【CF补题】Codeforces Round #790 (Div. 4)C++代码

懒得写题解,但欢迎提问。

注意:Div. 4,Div. 4,Div. 4,暴力,暴力,暴力!能过,能过,能过!

A.

#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		int a = 0;
		int b = 0;
		char c;
		for (int i = 1; i <= 3; i++)
		{
			cin >> c;
			a += c - '0';
		}
		for (int i = 1; i <= 3; i++)
		{
			cin >> c;
			b += c - '0';
		}
		if (a == b)cout << "YES" << '\n';
		else cout << "NO" << '\n';
	}
	return 0;
}

B

#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		long long sum = 0;
		int minn = 1e8;
		int x;
		cin >> n;
		for (int i = 1; i <= n; i++)
		{
			cin >> x;
			sum += x;
			minn = min(minn, x);
		}
		cout << sum - minn * n<<'\n';
	}
	return 0;
}

C

#include<bits/stdc++.h>
using namespace std;
int n,m;
char c[60][10];
int cha[60];
long long sum[60];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		sum[0] = 0;
		long long ans = 1e9 + 7;
		cin >> n >> m;
		for (int i = 1; i <= n; i++)
		{
			//cha[i] = 0;
			for (int j = 1; j <= m; j++)
			{
				cin >> c[i][j];
				if (i != 1)
				{
				//	cha[i] += c[i][j] - c[i - 1][j];
				}
			}
			//sum[i] = sum[i - 1] + cha[i];
		}
		long long summ;
		for(int i=1;i<n;i++)
			for (int j = i + 1; j <= n; j++)
			{
				summ = 0;
				for (int k = 1; k <= m; k++)
				{
					summ += abs(c[i][k] - c[j][k]);
				}
				ans = min(ans, summ);
			}
		cout << ans << '\n';
	}
	return 0;
}


D

#include<bits/stdc++.h>
using namespace std;
int n, m;
int c[300][300];
int cha[60];
long long suma[1010], sumb[1010];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		long long ans = 0;
		cin >> n >> m;
		memset(suma, 0, sizeof(suma));
		memset(sumb, 0, sizeof(sumb));
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
			{
				cin >> c[i][j];
				suma[i - j + n + m] += c[i][j];
				sumb[i + j] += c[i][j];
			}
		int nm = max(n, m);
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				ans = max(ans, suma[i - j + n + m] + sumb[i + j] - c[i][j]);
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

E

#include<bits/stdc++.h>
using namespace std;
int n, m;
long long c[500005];
long long suma[500005];
int test(int low, int high, long long key)
{
	long long mid = 0;
	while (high > low)
	{
		mid = (high + low) / 2;
		if (suma[mid] >= key)
		{
			high = mid;
		}
		else
		{
			low = mid + 1;
		}
	}
	return high;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		long long ans = 0;
		cin >> n >> m;
		memset(suma, 0, sizeof(suma));
		for (int i = 1; i <= n; i++)
		{
			cin >> c[i];
		}
		sort(c + 1, c + 1 + n);
		suma[0] = 0;
		for (int i = 1; i <= n; i++)
		{
			suma[i] = suma[i - 1] + c[n - i + 1];
			//cout << suma[i] << endl;
		}
		long long q;
		while (m--)
		{
			cin >> q;
			if (q == 0)cout << 0 << '\n'; else
			{
				int ans = test(1, n, q);
				if (suma[ans] >= q)
					cout << ans << '\n'; else cout << -1 << '\n';
			}
		}
	}
	return 0;
}

F

#include<bits/stdc++.h>
using namespace std;
int n, m;
int c[500005], a[500005];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int q;
	cin >> q;
	map<int,int>t;
	while (q--)
	{
		int k = 0;
		int x;
		cin >> n >> m;
		for (int i = 1; i <= n; i++)
		{
			cin >> x;
			t[x]++;
			if (t[x] == m) a[++k] = x;
		}
		sort(a + 1, a + 1 + k);
		/*for (int i = 1; i <= k; i++)
		{
			cout << a[i] << endl;
		}*/

		
		if (k == 0) {
			cout << -1 << '\n';
			t.clear();
			continue;
		}

		int cnt = 1;
		int ans = 1, anl = a[1], anr = a[1];
		int cnl = a[1], cnr = 0;

		for (int i = 2; i <= k; i++)
		{
			if (a[i] - a[i - 1] == 1)
			{
				cnt++;
				if (cnt > ans)
				{
					ans = cnt;
					anl = cnl;
					anr = a[i];
				}
			}
			else
			{
				cnt = 1;
				cnl = a[i];
			}
		}

		if (ans > 0)cout << anl << " " << anr<<'\n';
		t.clear();
	}
	return 0;
}

G

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值