Daily Practice 10th:Educational Codeforces Round 115 (Rated for Div. 2)

昨天懒了,,,我错了我错了我错了qwq

VP*10;

rating:800--1000--1200--1700

A. Computer Game

在一个2*n的地图中,从(1,1)到(2,n),通过八个方向的移动,是否可以到达。

思路: 判断每一列是否都有空格即可。

AC Code:

#include <bits/stdc++.h>
#pragma GCC optimize(2)

template <typename T>
inline void read(T &x) {
	x = 0;
	int f = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0', ch = getchar();
	}
	x *= f;
}

template <typename T>
void write(T x) {
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}

#define INF 0x3f3f3f3f
typedef long long ll;
const double PI = acos(-1);
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int t, n;
std::string s1, s2;

int main() {
//	freopen("test.in","r",stdin);
//  freopen("output.in", "w", stdout);
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin >> t;
	while (t--) {
		std::cin >> n;
		std::cin >> s1 >> s2;
		bool flag = true;
		if(s1[0]!='0'||s2[n-1]!='0'){
		    std::cout<<"NO"<<'\n';
		    continue;
        }
		for (int i = 0; i < n; i++) {
			if (s1[i] != '0' && s2[i] != '0') {
				flag = false;
				break;
			}
		}
		std::cout << (flag ? "YES" : "NO") << '\n';
	}
	return 0;
}

B. Groups

五天,给出n个学生在这五天里的空闲时间,把这两个学生平均分成两组,在不同的时间上课,判断能否分成这样两个满足条件的组。

思路:枚举任意两天,在第一天有空第二天没有空的计为aa,我们可以把这些人都放在第一天;第二天有空第一天没有空的计为bb,我们可以把这些人放在第二天;两天都有空的计为cc,这些人任意放置即可;两天都没有空的计为dd。那么满足条件的是:dd=0,a+c>=n/2&&b+c>=n/2。

AC Code:

#include <bits/stdc++.h>
#pragma GCC optimize(2)

template <typename T>
inline void read(T &x) {
	x = 0;
	int f = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0', ch = getchar();
	}
	x *= f;
}

template <typename T>
void write(T x) {
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}

#define INF 0x3f3f3f3f
typedef long long ll;
const double PI = acos(-1);
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 1e4 + 5;
int t, n, a[N][7];

int main() {
//	freopen("test.in","r",stdin);
//  freopen("output.in", "w", stdout);
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin >> t;
	while (t--) {
		std::cin >> n;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= 5; j++) {
				std::cin >> a[i][j];
			}
		}
		bool flag = false;
		for (int i = 1; i <= 5; i++) {
			for (int j = i + 1; j <= 5; j++) {
				int aa = 0, bb = 0, cc = 0, dd = 0;
				for (int k = 1; k <= n; k++) {
					if (a[k][i] && !a[k][j])
						aa++;
					if (!a[k][i] && a[k][j])
						bb++;
					if (a[k][i] && a[k][j])
						cc++;
					if (!a[k][i] && !a[k][j])
						dd++;
				}
				if (dd != 0)
					continue;
				if (aa + cc >= n / 2 && bb + cc >= n / 2) {
					flag = true;
					break;
				}
			}
			if (flag)
				break;
		}
		std::cout << (flag ? "YES" : "NO") << '\n';
	}
	return 0;
}

C. Delete Two Elements

给出一个序列,是否可以删除两个数,使得删除后的数组平均数不变。

思路: 将数组排序,从头开始遍历,寻找满足可以作为一组删去数的位置,用二分查找即可;加入答案ans中,记得最后将ans除以2,因为每个数都被计算了两遍,记得找到的这一组数两两不能相等。

AC Code:

#include <bits/stdc++.h>
#pragma GCC optimize(2)

template <typename T>
inline void read(T &x) {
	x = 0;
	int f = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0', ch = getchar();
	}
	x *= f;
}

template <typename T>
void write(T x) {
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}

#define INF 0x3f3f3f3f
typedef long long ll;
const double PI = acos(-1);
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int t, n, a[N];

int main() {
//	freopen("test.in","r",stdin);
//  freopen("output.in", "w", stdout);
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin >> t;
	while (t--) {
		std::cin >> n;
		ll sum = 0;
		for (int i = 1; i <= n; i++) {
			std::cin >> a[i];
			sum += a[i];
		}
		double k = sum * 1.0 * (n - 2) / n;
		std::sort(a + 1, a + 1 + n);
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			ans += std::upper_bound(a + 1, a + 1 + n, sum - k - a[i]) - std::lower_bound(a + 1, a + 1 + n, sum - k - a[i]);
			if (sum - k - a[i] == a[i])
				ans--;
		}
		std::cout << ans / 2 << '\n';
	}
	return 0;
}

D. Training Session

给出两两不同的二元组(a,b),选择三个二元组,至少满足以下一个条件:1、三个二元组的a都不同;2、三个二元组的b都不同。问可以选多少组满足条件的这样三个二元组。

思路:正着选不太容易,我们可以考虑反向考虑,考虑两个条件都不满足的:那么对于每个b=x的 二元组,我们可以从中选两个,对于第一个b=x的二元组,再选择一个a与这个二元组a相等的二元组。具体实现,假设b=x有k组,选择一个作为a的基础值那另一个选择有k-1种,再从cnt[a]中任选一个,那就有cnt[a]-1种选择,最后用n*(n-1)*(n-2)/6减去这些方案数即可。

AC Code:

#include <bits/stdc++.h>
#pragma GCC optimize(2)

template <typename T>
inline void read(T &x) {
	x = 0;
	int f = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0', ch = getchar();
	}
	x *= f;
}

template <typename T>
void write(T x) {
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}

#define INF 0x3f3f3f3f
typedef long long ll;
const double PI = acos(-1);
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
ll t, n, a[N], b[N];

int main() {
//	freopen("test.in","r",stdin);
//  freopen("output.in", "w", stdout);
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin >> t;
	while (t--) {
		std::cin >> n;
		std::map<int, ll>m1, m2;
		std::map<int, std::vector<int>>m3;
		for (int i = 1; i <= n; i++) {
			std::cin >> a[i] >> b[i];
			m1[a[i]]++;
			m2[b[i]]++;
			m3[b[i]].push_back(a[i]);
		}
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			ll tmp = 0;
			for (auto u : m3[i])
				tmp += m1[u] - 1;
			ans += (m2[i] - 1) * tmp;
		}
		std::cout << n*(n - 1)*(n - 2) / 6 - ans << '\n';
	}
	return 0;
}

若有错误请指教,谢谢!

orzorz

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值