Codeforces Round #615 (Div. 3) 解题报告

Codeforces Round #615 (Div. 3)

【A.Collecting Coins】

【题目大意】
三个人手上分别有a,b,c元钱,你有n元钱,问你能否把你的前分给三个人使得他们手上的钱数目相等

【解题思路】
(a + b + c + n) % 3 == 0
(a + b + c + n) / 3 >= a && >= b && >= c

【AC代码】

#include <bits/stdc++.h>
using namespace std;
inline int read() {
	register int x = 0, w = 0; register char ch = 0;
	while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return w ? -x : x;
}
int main() {
	register int t = read();
	while (t--) {
		register int a = read(), b = read(), c = read(), n = read();
		int m = a + b + c + n;
		if (m % 3) puts("NO");
		else {
			int x = m / 3 - a;
			int y = m / 3 - b;
			int z = m / 3 - c;
			if (x >= 0 && y >= 0 && z >= 0) puts("YES");
			else puts("NO");
		}
	}
	return 0;
}

【B.Collecting Packages】

【题目大意】
给出n个物品的的坐标,你从(0, 0)出发,只能向右走或向上走,问你能否把所有的物品都拿到手,如果能打印YES和最短路径,否则打印NO

【解题思路】
将坐标根据x和y升序排序,遍历一遍,如果发现有不符合x,y升序的坐标就表明不能全部拿走

【AC代码】

#include <bits/stdc++.h>
#define N 1010
#define max(a, b) ((a) > (b) ? (a) :(b))
#define min(a, b) ((a) < (b) ? (a) :(b))
#define _Rep(i, n) for(register int i = 1; i < (n); ++i)
#define Rep(i, n) for(register int i = 1; i <= (n); ++i)
#define _rep(i, n) for(register int i = 0; i < (n); ++i)
#define rep(i, n) for(register int i = 0; i <= (n); ++i)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 4e5 + 10;
const int maxm = 4e6 + 10;
const ll INF = 0x3f3f3f3f;
inline int read() {
	register int x = 0, w = 0; register char ch = 0;
	while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return w ? -x : x;
}
inline void write(register int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
struct Node {
	int x, y;
	bool operator < (const Node& b) {
		if (x == b.x) return y < b.y;
		return x < b.x;
	}
}a[N];
int main() {
	register int t = read();
	while (t--) {
		register int n = read();
		Rep(i, n) {
			a[i].x = read();
			a[i].y = read();
		}
		sort(a + 1, a + n + 1);
		register string s = "";
		register bool flag = false;
		register int i = 0;
		for (; i < n; ++i) {
			if (a[i].x <= a[i + 1].x && a[i].y <= a[i + 1].y) {
				for (register int j = a[i].x; j < a[i + 1].x; ++j) {
					s += 'R';
				}
				for (register int j = a[i].y; j < a[i + 1].y; ++j) {
					s += 'U';
				}
			}
			else {
				flag = true;
				break;
			}
		}
		if (flag) puts("NO");
		else {
			puts("YES");
			cout << s << endl;
		}
	}
	return 0;
}

【C.Product of Three Numbers】

【题目大意】
找到a, b, c
1.a ≠ b ≠ c
2.a, b, c >= 2
3.a * b * c = n

【解题思路】
不妨设 a < b < c
a, b, c <= sqrt(n)
b, c <= sqrt(n / a)

【AC代码】

#include <bits/stdc++.h>
#define N 1010
#define max(a, b) ((a) > (b) ? (a) :(b))
#define min(a, b) ((a) < (b) ? (a) :(b))
#define _Rep(i, n) for(register int i = 1; i < (n); ++i)
#define Rep(i, n) for(register int i = 1; i <= (n); ++i)
#define _rep(i, n) for(register int i = 0; i < (n); ++i)
#define rep(i, n) for(register int i = 0; i <= (n); ++i)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 4e5 + 10;
const int maxm = 4e6 + 10;
const ll INF = 0x3f3f3f3f;
inline int read() {
	register int x = 0, w = 0; register char ch = 0;
	while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return w ? -x : x;
}
inline void write(register int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
int main() {
	register int t = read();
	while (t--) {
		register int n = read();
		register int k = sqrt(n);
		register bool flag = false;
		for (register int i = 2; i <= k; ++i) {
			if (n % i == 0) {
				register int temp = n / i;
				register int kk = sqrt(temp);
				for (register int j = i + 1; j <= kk; ++j) {
					if (temp % j == 0) {
						if (j == temp / j) continue;
						puts("YES");
						printf("%d %d %d\n", i, j, temp / j);
						flag = true;
						break;
					}
				}
			}
			if (flag) break;
		}
		if (!flag) puts("NO");
	}
	return 0;
}
发布了40 篇原创文章 · 获赞 2 · 访问量 3230

猜你喜欢

转载自blog.csdn.net/weixin_44211980/article/details/104073773