2020年 CSP-J + CSP-S 总结
文章目录
普及组
T1 优秀的拆分(power)
T 1 T1 T1 还是一如既往的简单
#include <cstdio>
int N;
int ans[50], cnt;
int main() {
freopen("power.in", "r", stdin);
freopen("power.out", "w", stdout);
scanf("%d", &N);
if (N & 1) {
printf("-1\n"); return 0; }
for (int i = 30; i >= 1 && N; i--) {
int now = 1 << i;
if (now <= N) {
ans[++cnt] = now;
N -= now;
}
}
for (int i = 1; i < cnt; i++)
printf("%d ", ans[i]);
if (cnt) printf("%d\n", ans[cnt]);
return 0;
}
T2 直播获奖(live)
T 2 T2 T2 考试的时候先打了一个插入排序,但是考虑到时间复杂度太高 O ( n 2 ) O(n^2) O(n2),于是推了一些神奇的优化,就 A C AC AC 了
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1e5;
int N, W;
struct People {
int G, Pos;
}P[MAXN + 5];
int ans[MAXN + 5], Match[MAXN + 5];
bool vis[MAXN + 5];
int Max(int a, int b) {
return a > b ? a : b; }
int Min(int a, int b) {
return a < b ? a : b; }
void Read(int &n) {
n = 0;
bool f = 1;
char C = getchar();
while (C < '0' || C > '9') {
if (C == '-') f ^= 1;
C = getchar();
}
while ('0' <= C && C <= '9') {
n = (n << 3) + (n << 1) + (C ^ 48);
C = getchar();
}
if (!f) n = -n;
}
bool cmp(People a, People b) {
return a.G > b.G; }
int main() {
freopen("live.in", "r", stdin);
freopen("live.out", "w", stdout);
Read(N); Read(W);
for (int i