寒假集训做题分享(4)

今天是习题课,讲了几道\(cf\) \(div2\)\(B\) 题,挖去,全是思维题,少有的是直接模拟,用到算法不多,基本是贪心。pqy讲的太快了,看两眼就有思路了,我还读题理解题意呢,他结论出来了,这我还做牛魔题啊。。。

然后呢今天又做了几道上周学的计算几何,十分考验我的数学水平,但感觉最近做题频率比较高,消化不是很好,打算今天在学习学习上周讲的知识点,上周太难了。。。

题目列表:

1. Milena and Admirer

2. AB Flipping

3. P7934 [COCI2007-2008#5] JABUKE

4. Collecting Game

5. P1183 多边形的面积

6. P1257 平面上的最接近点对

7. Eat the Chip

8. P1496 火烧赤壁

1.

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e6 + 100;
const int M = 1010;
int maxx = -1e18;
int minn = 1e18;
int cnt, sum;
int a[N];
signed main() {
	int t;
	cin >> t;
	while (t--) {
		int n, i;
		cin >> n;
		for (i = 1; i <= n; i++)
			cin >> a[i];
		int ans = 0;
		minn = 1e18;
		for (i = n; i >= 1; i--) {
			if (a[i] <= minn) {
				minn = min(minn, a[i]);
			} else {
				int t = (a[i] + minn - 1) / minn;
				ans += t - 1;
				minn = min(minn, a[i] / t);
			}
		}
		cout << ans << endl;
	}
}

2.

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e6 + 100;
const int M = 1010;
int maxx = -1e18;
int minn = 1e18;
int cnt, sum;
bool v[N];
char s[N];
signed main() {
	int t;
	cin >> t;
	while (t--) {
		int n, i;
		cin >> n;
		scanf("%s", s + 1);
		int ans = 0;
		for (i = 1; i <= n; i++)
			v[i] = 0;
		for (i = n; i >= 1; i--) {
			if (s[i] == 'A') {
				int now = i;
				while (!v[now] && s[now] == 'A' && s[now + 1] == 'B') {
					v[now] = 1;
					swap(s[now], s[now + 1]);
					now++;
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

3.

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e6 + 100;
const int M = 1010;
int maxx = -1e18;
int minn = 1e18;
int cnt, sum;

signed main() {
	double x1, x2, x3, y1, y2, y3;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
	int n, i;
	cin >> n;
	double S = abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2;
	for (i = 1; i <= n; i++) {
		double x, y;
		cin >> x >> y;
		double S1 = abs(x * (y2 - y3) + x2 * (y3 - y) + x3 * (y - y2)) / 2;
		double S2 = abs(x1 * (y - y3) + x * (y3 - y1) + x3 * (y1 - y)) / 2;
		double S3 = abs(x1 * (y2 - y) + x2 * (y - y1) + x * (y1 - y2)) / 2;
		if (S1 + S2 + S3 <=S)
			cnt++;
	}
	printf("%.1lf\n%lld", S, cnt);
}

4.

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e6 + 100;
const int M = 1010;
int maxx = -1e18;
int minn = 1e18;
int cnt, sum;
pair<int, int>a[N];
int q[N], ans[N];
signed main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		int i;
		for (i = 1; i <= n; i++) {
			scanf("%lld", &a[i].first);
			a[i].second = i;
		}
		sort(a + 1, a + 1 + n);
		for (i = 1; i <= n; i++) {
			q[i] = q[i - 1] + a[i].first;
		}
		int r = 2;
		for (i = 1; i <= n; i++) {
			r = max(r, i + 1);
			while (r <= n && q[r - 1] >= a[r].first) {
				r++;
			}
			ans[a[i].second] = r - 2;
		}
		for (i = 1; i <= n; i++)
			cout << ans[i] << " ";
		cout << endl;
	}
	return 0;

}

5.

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e6 + 100;
const int M = 1010;
int cnt, sum;
int x[N], y[N];
signed main() {
	int n;
	cin >> n;
	int i;
	for (i = 1; i <= n; i++) {
		scanf("%lld %lld", &x[i], &y[i]);
	}
	x[n + 1] = x[1];
	y[n + 1] = y[1];
	for (i = 1; i <= n; i++) {
		sum += (x[i] * y[i + 1] - x[i + 1] * y[i]);
	}
	cout << abs(sum / 2) << endl;
}
/*
--------
|      |
|    ---
|    |
|    |
------
*/

6.

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e7 + 10;
const int M = 1010;
double maxx = -1e18;
double minn = 1e18;
int cnt;
//int a[M][M];
//bool p[M][M];
int x[N],y[N];
signed main() {
	int n;
	cin>>n;
	int i,j;
	for(i=1;i<=n;i++)
	{
		cin>>x[i]>>y[i];
		for(j=i-1;j>=1;j--)
		{
			int aa=(x[i]-x[j])*(x[i]-x[j]);
			int bb=(y[i]-y[j])*(y[i]-y[j]);
			minn=min(sqrt(aa+bb),minn);
		}
	}
	printf("%.4lf",minn);
}

7.

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main() {
	int t;
	cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		int ha, hb, la, lb;
		cin >> ha >> la >> hb >> lb;
		int ans = hb - ha;
		if (ans <= 0) {
			cout << "Draw" << endl;
			continue;
		}
		int trun = ans / 2;
		if (ans % 2 == 1) {
			if (lb > la) {
				la = min(la + trun + 1, m);
				lb = min(lb + trun, m);
				if (la >= lb)
					cout << "Alice" << endl;
				else
					cout << "Draw" << endl;
			} else {
				int nnn = 1;
				la = max(la - trun - 1, nnn);
				lb = max(lb - trun, nnn);
				if (la <= lb)
					cout << "Alice" << endl;
				else
					cout << "Draw" << endl;
			}
		} else {
			if (la > lb) {
				la = min(la + trun, m);
				lb = min(lb + trun, m);
				if (la <= lb)
					cout << "Bob" << endl;
				else
					cout << "Draw" << endl;
			} else {
				int nnn = 1;
				la = max(la - trun, nnn);
				lb = max(lb - trun, nnn);
				if (la >= lb)
					cout << "Bob" << endl;
				else
					cout << "Draw" << endl;
			}
		}
	}
}

8.

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
double pi = acos(-1);
const int N = 1e6 + 100;
const int M = 1010;
int cnt, sum;
//int a[N];
int x[N], y[N];
vector<pair<int, int>>a;
signed main() {
	int n;
	cin >> n;
	int i;
	for (i = 1; i <= n; i++) {
		cin >> x[i] >> y[i];
	}
	sort(x + 1, x + 1 + n);
	sort(y + 1, y + 1 + n);
	for (i = 1; i <= n; i++) {
		sum += y[i] - x[i];
		if (i != n) {
			if (y[i] > x[i + 1])
				sum -= y[i] - x[i + 1];
		}
	}
	cout << sum << endl;
	return 0;
}
posted @ 2024-07-05 17:38  ZhangDT  阅读(0)  评论(0编辑  收藏  举报