A:问正n边形的一条边和x轴平行的时候有没有一条边和y轴重合,直接判断n是否是4的倍数

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#define rep(i,j,k) for(int i = j; i <= k; i++)
#define dow(i,j,k) for(int i = j; i >= k; i--)
#define ez(i,x) for(int i = h[x]; i; i = e[i].next)
#define fi first
#define se second
using namespace std; typedef long long ll;
typedef pair<int,int> pi; int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
if (n % == ) puts("YES");
else puts("NO");
}
}

B题:给一个01串每次可以从连续的“10”中删去0或1(不能同时删去),问可以得到的最小字典序字符串。

字符串中开头的0是去不掉的,末尾的1是去不掉的。中间是1开头的01串,可以发现这堆东西能变成一个"0"。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#define rep(i,j,k) for(int i = j; i <= k; i++)
#define dow(i,j,k) for(int i = j; i >= k; i--)
#define ez(i,x) for(int i = h[x]; i; i = e[i].next)
#define fi first
#define se second
using namespace std; typedef long long ll;
typedef pair<int,int> pi;
const int N = 1e5 + ; char s[N];
int top;
int n;
char a[N];
void solve() {
scanf("%d", &n);
memset(a, , sizeof (a));
memset(s, , sizeof (s));
top = ;
scanf("%s", a + );
int f = ;
rep(i,,n) {
if (!f && a[i] == '') {
putchar(a[i]);
continue;
}
if (a[i] == '') f = , s[++top] = a[i];
if (a[i] == '') top = , s[] = '';
}
rep(i,,top) putchar(s[i]);
puts("");
} int main() {
int t;
scanf("%d", &t);
while (t--) {
solve();
}
}

C题:给你n个数字,分给k个小伙伴,每个人分得w_i个数字,小伙伴的快乐值是他得到的数字中的最大值加最小值。求所有小伙伴快乐值的和最大是多少。

首先把小伙伴按分得数字个数从小到大排序,数字按从大到小排序。先把最大的k个按这样的顺序分给大家每人一个,然后剩下的数字从第一个小伙伴开始给,到这个小伙伴拿够,给下一个人。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#define rep(i,j,k) for(int i = j; i <= k; i++)
#define dow(i,j,k) for(int i = j; i >= k; i--)
#define ez(i,x) for(int i = h[x]; i; i = e[i].next)
#define fi first
#define se second
using namespace std; typedef long long ll;
typedef pair<int,int> pi;
const int N = 2e5 + ;
int w[N], a[N], n, k; void solve() {
scanf("%d %d", &n, &k);
ll ans = ;
rep(i,,n) scanf("%d", &a[i]);
rep(i,,k) scanf("%d", &w[i]);
sort(a + , a + n + );
sort(w + , w + k + );
reverse(a + , a + n + );
rep(i,,k) ans += a[i];
int cnt = k;
rep(i,,k) {
if (w[i] >= ) {
if (w[i] == ) ans += a[i];
else {
while (w[i] != ) {
cnt++;
w[i]--;
}
ans += a[cnt];
}
}
}
printf("%lld\n", ans);
}
int main() {
int t;
scanf("%d", &t);
while(t--) {
solve();
}
}

D:有一个叫RDB的有根树。一阶RDB只有根结点。i阶RDB是在i-1阶的RDB上发生一些变化:对于没有儿子的节点,长出一个儿子;有一个儿子的节点,再长两个儿子,其余节点不发生变化。钦定一个点和他的三个儿子叫做爪子。然后问你在n阶段RDB上最多能找到多少个不重叠的爪子。

问题在有三个儿子的结点什么时候会被选什么时候不会被选。当这个结点第一次有三个儿子的时候,选这个结点,一定不比选他的父亲那个结点差,这个时候必选这个结点。更高一阶他中间的儿子结点将有三个儿子,更高两阶他的左右两个儿子会有三个儿子,这时候显然不选这个结点。而更高3阶的时候就会选这个结点。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#define rep(i,j,k) for(int i = j; i <= k; i++)
#define dow(i,j,k) for(int i = j; i >= k; i--)
#define ez(i,x) for(int i = h[x]; i; i = e[i].next)
#define fi first
#define se second
using namespace std; typedef long long ll;
typedef pair<int,int> pi;
const int N = 2e6 + ;
const int mod = 1e9 + ;
ll f[N][]; void init(){
f[][] = ;
rep(i,,) {
f[i][] = f[i-][];
f[i][] = f[i-][];
f[i][] = (f[i-][] + f[i-][]) % mod;
//temp = f[2];
f[i][] = f[i-][];
f[i][] = (f[i-][] + * f[i-][]) % mod;
}
} void solve() {
int n;
scanf("%d", &n);
printf("%lld\n",f[n][] * % mod);
} int main() {
init();
int t;
scanf("%d", &t);
while (t--) {
solve();
}
}

E:你有一些朋友,每个人有两道爱吃的菜x_i, y_i。然后每道菜有w_i份。当一个朋友来的时候会吃ta喜欢的菜,如果有两道就吃两道,有一道就吃一道,如果没有就会吃了你。请问你应该怎么安排朋友吃菜的顺序,来让大家都吃到至少一道自己喜欢吃的菜,或者无论怎么安排都会有人吃不到。

设喜欢吃某道菜的人数为s_i,如果所有的s_i 都小于 w_i那么就无解,显然最后一个人的菜一定都被别人吃光了。对于wi >= si的菜,这些人多会吃都有关系。所以我们放在后面,这样他们就会吃的少一点。然后按照这种方法一直做就好了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#define rep(i,j,k) for(int i = j; i <= k; i++)
#define dow(i,j,k) for(int i = j; i >= k; i--)
#define ez(i,x) for(int i = h[x]; i; i = e[i].next)
#define fi first
#define se second
using namespace std; typedef long long ll;
typedef pair<int,int> pi;
const int N = 2e5 + ;
const int mod = 1e9 + ; int n, m;
vector<int> d[N];
int s[N], w[N], a[N], b[N], vis[N];
int ans[N], cnt = ;
int main() {
scanf("%d%d", &n, &m);
rep(i,,n) scanf("%d", &w[i]);
rep(i,,m) {
scanf("%d %d", &a[i], &b[i]);
s[a[i]]++;
s[b[i]]++;
d[a[i]].push_back(i);
d[b[i]].push_back(i);
}
queue<int> q;
rep(i,,n) if (s[i] <= w[i]) q.push(i);
while (!q.empty()) {
int j = q.front(); q.pop();
int _ = (int)d[j].size();
rep(i,,_-) {
if (!vis[d[j][i]]) {
int u = a[d[j][i]], v = b[d[j][i]];
if (u == j) swap(u, v);
s[u]--;
if (s[u] == w[u]) q.push(u);
vis[d[j][i]] = ;
ans[++cnt] = d[j][i];
}
}
}
if (cnt < m) {
puts("DEAD");
return ;
}
puts("ALIVE");
reverse(ans + , ans + cnt + );
rep(i,,cnt) printf("%d ", ans[i]); puts("");
}

f题:有一个游戏,有两个数s,e每次可以把s变成s + 1或者是s * 2,当s大于e时,就输了。有n轮游戏,每轮游戏输的人先手开始下一轮游戏。在最后一轮赢了的人,赢得了游戏。在最后一轮输的人,输掉了游戏。

问先手能否必胜,同时先手能否一定失败。

定义一下win(s,e)和lose(s,e)表示先手是否能一定赢和一定输。

e是奇数的时候s奇数必败s是偶数必胜。(可以自己写一写看一下)。e是偶数的时候,s大于e/2,s是奇数必胜,偶数必败。s大于e/4的时候,无论s是什么都能必胜。否则就是win(s, e/4)

对于先手强制输的情况,如果s * 2 > e一定可以输,否则等价于win(s, e / 2)

然后对于游戏的输赢就是,就是从最后局开始递归,如果这局能先手必胜(败),上一局就必须要输,否则上一局就必须要赢。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#define rep(i,j,k) for(int i = j; i <= k; i++)
#define dow(i,j,k) for(int i = j; i >= k; i--)
#define ez(i,x) for(int i = h[x]; i; i = e[i].next)
#define fi first
#define se second
using namespace std; typedef long long ll;
typedef pair<int,int> pi; const int N = 1e5 + ;
ll e[N], s[N];
bool w[N], l[N];
int n; bool Win(ll s, ll e) {
if ((e & )) {
if (s & ) return ;
return ;
}
if (s > e) return ;
if (s * > e) return (bool)(s & );
if (s * > e) return ;
return Win(s, e / );
} bool Lose(ll s, ll e) {
if (s * > e) return ;
return Win(s, e / );
} int getWin(int);
int getLose(int); int getWin(int x) {
if (x == ) return (int)w[];
return w[x]? getLose(x - ) : getWin(x - );
} int getLose(int x) {
if (x == ) return (int)l[];
return l[x]? getLose(x - ) : getWin(x - );
}
int main() {
//ios::sync_with_stdio(0);
scanf("%d", &n);
rep(i,,n) {
scanf("%lld %lld", &s[i], &e[i]);
w[i] = Win(s[i], e[i]);
l[i] = Lose(s[i], e[i]);
// cout << w[i] << " " << l[i] << endl;
}
printf("%d %d\n",getWin(n), getLose(n));

Codeforces Round #652 (Div. 2) 总结的更多相关文章

  1. Codeforces Round #652 (Div. 2) E. DeadLee(贪心)

    题目链接:https://codeforces.com/contest/1369/problem/E 题意 Lee 有 $n$ 种不同种类的食物和 $m$ 个朋友,每种食物有 $w_i$ 个,每个朋友 ...

  2. Codeforces Round #652 (Div. 2) D. TediousLee(dp)

    题目链接:https://codeforces.com/contest/1369/problem/D 题意 最初有一个结点,衍生规则如下: 如果结点 $u$ 没有子结点,添加 $1$ 个子结点 如果结 ...

  3. Codeforces Round #652 (Div. 2) C. RationalLee(贪心)

    题目链接:https://codeforces.com/contest/1369/problem/C 题意 将 $n$ 个数分给 $k$ 个人,每个人分 $w_i$ 个数($\sum_{i = 1}^ ...

  4. Codeforces Round #652 (Div. 2) B. AccurateLee(字符串)

    题目链接:https://codeforces.com/contest/1369/problem/B 题意 给出一个长 $n$ 的 二进制串,每次可以选择字符串中的一个 $10$,然后删除其中的一个字 ...

  5. Codeforces Round #652 (Div. 2) A. FashionabLee(几何)

    题目链接:https://codeforces.com/contest/1369/problem/A 题意 判断正 $n$ 边形能否通过旋转使得一边与 $x$ 轴平行,一边与 $y$ 轴平行. 题解 ...

  6. Codeforces Round #652 (Div. 2) B. AccurateLee(思维)

    题意: 给你一个01字符串,现在你可以删除其中的一些子序列,要求如下:当遇到1 0的俩个连续子字符串后,可以删除其中的一个字符,现在要求把他删到尽量最短并且字典序最小,输出最后的字符串 题解: 刚开始 ...

  7. Codeforces Round #652 (Div. 2) C. RationalLee 贪心

    题意: t组输入,你有n个数,还有k个朋友,每一个朋友需要wi个数.意思就是你要给第i个朋友分配wi个数,输入保证w1+w2+...+wk=n 一个朋友的兴奋值是你分配给他的数中最大值加上最小值的和( ...

  8. Codeforces Round #652 (Div. 2)D. TediousLee 推导

    题意: Rooted Dead Bush (RDB) of level 1是只有一个点,如下图 当(RDB) of level i变成(RDB) of level i+1的时候,每一个顶点要进行下面的 ...

  9. Codeforces Round #652 (Div. 2) E. DeadLee 贪心

    题意: 派会上有n种食物,每种食物有wi份.有m个朋友,每一个朋友有两种他喜欢吃的食物xi,yi.你需要判断他的朋友是否都能吃到食物.如果都能吃到食物,那么要输出朋友来的顺序,不能的话输出" ...

随机推荐

  1. PowerPC-Link Command File解析

    https://mp.weixin.qq.com/s/CATWma2mv5IPYGtKZLuGDA   以Code Warrior 11生成的flash版本(FLASH.lcf)为例   一. 参考资 ...

  2. jchdl-GSL-实例 - 使用Intellij IDEA创建Mux

    https://mp.weixin.qq.com/s/yP9xKeg0iHJChuMPzxdJtA https://github.com/wjcdx/jchdl/blob/master/src/org ...

  3. Jmeter 样例 之 JDBC请求-操作MySql数据库

    准备: 1.MySql的驱动jar包:mysql-connector-java-5.1.28.jar, 2.jmeter安装目录中修改编码格式:\bin\jmeter.properties   :sa ...

  4. Linux (四) 基础命令 下

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 一.查看文件内容 1.命令  cat 对应单词:concatenate 作用:查看文件内容 常用参数: ...

  5. Java实现蓝桥杯-算法提高 P1003

    算法提高 P1003 时间限制:1.0s 内存限制:256.0MB 作为一名网络警察,你的任务是监视电子邮件,看其中是否有一些敏感的关键词.不过,有些狡猾的犯罪嫌疑人会改变某些单词的字母顺序,以逃避检 ...

  6. Java实现蓝桥杯 算法训练 ALGO-15 旅行家的预算

    问题描述 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D1.汽车油箱的容量C(以升为单位).每升汽油能行驶的距离D2.出发点每升汽油价格P和沿 ...

  7. Java实现 LeetCode 416 分割等和子集

    416. 分割等和子集 给定一个只包含正整数的非空数组.是否可以将这个数组分割成两个子集,使得两个子集的元素和相等. 注意: 每个数组中的元素不会超过 100 数组的大小不会超过 200 示例 1: ...

  8. Java实现 蓝桥杯VIP 算法训练 传球游戏

    [问题描述] 上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏. 游戏规则是这样的:n个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每 ...

  9. Linux vi使用技巧

    导入命令执行结果:r !命令,例如:导入已经存在的文件内容到当前文件 导入命令执行的结果到当前文件 定义快捷键,map 快捷键 触发命令,例如:map ^P I#<ESC>(使用CRTL+ ...

  10. Spring事务的传播属性

    前言 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为.事务传播行为是Spring框架独有的事务增强特性,他不属于的事务实际提供方数据库行为.这是Spring ...