Codeforces Round #652 (Div. 2) 总结
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) 总结的更多相关文章
- Codeforces Round #652 (Div. 2) E. DeadLee(贪心)
题目链接:https://codeforces.com/contest/1369/problem/E 题意 Lee 有 $n$ 种不同种类的食物和 $m$ 个朋友,每种食物有 $w_i$ 个,每个朋友 ...
- Codeforces Round #652 (Div. 2) D. TediousLee(dp)
题目链接:https://codeforces.com/contest/1369/problem/D 题意 最初有一个结点,衍生规则如下: 如果结点 $u$ 没有子结点,添加 $1$ 个子结点 如果结 ...
- Codeforces Round #652 (Div. 2) C. RationalLee(贪心)
题目链接:https://codeforces.com/contest/1369/problem/C 题意 将 $n$ 个数分给 $k$ 个人,每个人分 $w_i$ 个数($\sum_{i = 1}^ ...
- Codeforces Round #652 (Div. 2) B. AccurateLee(字符串)
题目链接:https://codeforces.com/contest/1369/problem/B 题意 给出一个长 $n$ 的 二进制串,每次可以选择字符串中的一个 $10$,然后删除其中的一个字 ...
- Codeforces Round #652 (Div. 2) A. FashionabLee(几何)
题目链接:https://codeforces.com/contest/1369/problem/A 题意 判断正 $n$ 边形能否通过旋转使得一边与 $x$ 轴平行,一边与 $y$ 轴平行. 题解 ...
- Codeforces Round #652 (Div. 2) B. AccurateLee(思维)
题意: 给你一个01字符串,现在你可以删除其中的一些子序列,要求如下:当遇到1 0的俩个连续子字符串后,可以删除其中的一个字符,现在要求把他删到尽量最短并且字典序最小,输出最后的字符串 题解: 刚开始 ...
- Codeforces Round #652 (Div. 2) C. RationalLee 贪心
题意: t组输入,你有n个数,还有k个朋友,每一个朋友需要wi个数.意思就是你要给第i个朋友分配wi个数,输入保证w1+w2+...+wk=n 一个朋友的兴奋值是你分配给他的数中最大值加上最小值的和( ...
- Codeforces Round #652 (Div. 2)D. TediousLee 推导
题意: Rooted Dead Bush (RDB) of level 1是只有一个点,如下图 当(RDB) of level i变成(RDB) of level i+1的时候,每一个顶点要进行下面的 ...
- Codeforces Round #652 (Div. 2) E. DeadLee 贪心
题意: 派会上有n种食物,每种食物有wi份.有m个朋友,每一个朋友有两种他喜欢吃的食物xi,yi.你需要判断他的朋友是否都能吃到食物.如果都能吃到食物,那么要输出朋友来的顺序,不能的话输出" ...
随机推荐
- tomcat session漏洞反序列化详解
1. 条件1)攻击者可以控制服务器上的文件名/文件内容2)tomcat context配置了persistencemanager的fileSotre3) persistenceManager 配置了s ...
- 基于 abp vNext 和 .NET Core 开发博客项目 - 博客接口实战篇(二)
系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 ...
- java代码(13) ---Predicate详解
Predicate详解 遇到Predicate是自己在自定义Mybatis拦截器的时候,在拦截器中我们是通过反射机制获取对象的所有属性,在查看这些属性上是否有我们自定义的UUID注解 如果有该注解,那 ...
- ASP.NET Core 3.1 WebApi部署到腾讯云CentOS 7+Docker
一.准备 首先需要有一台CentOS服务器,安装最新版Docker,配置镜像加速等,安装方法网上很多,下面是一些相关指令: yum install -y yum-utils device-mapper ...
- TB6612FNG电机驱动模块
TB6612FNG电机驱动模块 模块原理图 模块的使用 TB6612是双驱动,也就是可以驱动两个电机 下面分别是控制两个电机的IO口 STBY口接单片机的IO口清零电机全部停止, 置1通过AIN1 A ...
- 关于cronExpression表达式
spring 定时任务设置,关于cronExpression表达式: 字段 允许值 允许的特殊字符 秒 0-59 , - * / 分 0-59 , - * / 小时 0-23 , - * / 日期 1 ...
- 【华为云技术分享】数据库开发:MySQL Seconds_Behind_Master简要分析
[摘要]对于mysql主备实例,seconds_behind_master是衡量master与slave之间延时的一个重要参数.通过在slave上执行"show slave status;& ...
- [转]记一次linux(被)入侵,服务器变矿机~
0x00 背景 周一早上刚到办公室,就听到同事说有一台服务器登陆不上了,我也没放在心上,继续边吃早点,边看币价是不是又跌了.不一会运维的同事也到了,气喘吁吁的说:我们有台服务器被阿里云冻结了,理由:对 ...
- Stylus 之 网教通直播间整修
暗色模式 效果 Mozilla 格式源代码 @-moz-document domain("fj.101.com") { * { transition: all .3s; } #wj ...
- 【Java入门】JDK安装和环境变量配置(Win7版)
系统环境:Windows7 x64 安装JDK和JRE版本:1.8.0_191 1.下载JDK安装包 Oracle官网下载网址:https://www.oracle.com/technetwork/j ...