Codeforces Round #534 (Div. 2)
B. Game with string
题意:
给出一个字符串s只包括小写字母。当轮到一个玩家的时候,他可以选择两个连续且相等的字母并且删除它。当一个玩家没得删的时候他就输了。
题解:
乍一看有点懵,像dp,但是观察一下就发现输赢和顺序无关,只跟能组成相同的对数量有关,这个数量是一定的。那么我们用栈扫一遍就好了。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <stack> using namespace std;
const int maxn=1e5+;
char s[maxn];
int n;
stack<char>S;
int ans;
int main(){
scanf("%s",s);
n=strlen(s);
for(int i=;i<n;i++){
if(!S.empty()&&S.top()==s[i]){
S.pop();
ans++;
}else{
S.push(s[i]);
}
}
if(ans%){
printf("Yes\n");
}else{
printf("No\n");
}
return ;
}
C. Grid game
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std;
const int maxn=+;
char s[maxn];
int n;
int main(){
scanf("%s",s);
n=strlen(s);
int a=,b=;
for(int i=;i<n;i++){
if(s[i]==''){
a=a%+;
printf("3 %d\n",a);
}else{
b=b%+;
printf("1 %d\n",b*-);
}
}
return ;
}
D. Game with modulo
题意:交互题。
V和P要玩一个游戏,P有一些正整数a,V要用下面的问题来猜这个数字a。他可以问(x,y),P会回答他:
1.'x',如果x mod a >= y mod a
2.'y',如果 x mod a < y mod a
V需要在60次问题内猜到数字a。保证a<=1e9.
题解:
首先询问0,1。如果返回x,那么a一定是1.如果返回y那么去询问1 2如果返回y再询问2 4然后4 8,8 16。直到返回x,则证明a一定在x和y之间。然后二分[x,y]这个区间。
这种办法我也没想到,看了答案后可以推一下发现可以很容易推出y=2*x.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std;
const int Max=1e9; string com; int main(){
while(cin>>com){
if(com=="end")break;
if(com=="mistake")break;
if(com=="start"){
char c;
printf("? 0 1\n");
fflush(stdout);
scanf(" %c",&c);
if(c=='x'){
printf("! 1\n");
fflush(stdout);
continue;
}else{
int x=,y=;
printf("? %d %d\n",x,y);
fflush(stdout);
while(scanf(" %c",&c)){
if(c=='x'){
break;
}
x=y,y=*y;
printf("? %d %d\n",x,y);
fflush(stdout);
}
int l=x,r=y;
int ans=;
for(int j=;j<=;j++){
int mid=l+(r-l)/;
printf("? %d %d\n",mid,r);
fflush(stdout);
scanf(" %c",&c);
if(c=='x'){
l=mid;
}else{
r=mid;
}
}
printf("! %d\n",max(l,r));
fflush(stdout);
}
}
}
// fflush(stdout);
return ;
}
E. Johnny Solving
题意:
给出一张连通图,不存在自环和重边,有n个结点和m条边,每个点的度数至少为3,给出一个参数k,若存在长度大于等于n/k的路径,则输出PATH并将路径输出,若存在k个满足周长不被3整除的环,且每一个环都存在一个只属于只属于这个环的点则输出CYCLES,并将k个环输出。
题解:下面是翻译自官方题解。。
从1结点开始建dfs树,然后确定这颗生成树的深度为depth。如果深度最少为n/k,那么我们就可以打印从根结点到最深结点的路径。否则的话,在dfs树中至少存在k+1个叶子结点。(想一想为什么,其实比较显然,也很好证明)。现在考虑dfs树中的一个叶子结点v,这个叶子结点至少有两条反向边,我们定义这两条反向边连向的祖先为x和y。显然我们有三个环,x到v,y到v,和x到y加上v。他们的长度分别是d(v,x)+1,d(v,y)+1,和d(x,y)+2.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector> using namespace std;
const int maxn=25e4+;
const int maxm=5e5+;
int head[maxn],Next[*maxm],to[*maxm];
int n,m,sz,k,goal,cir;
vector<int>path;
void init(){
sz=;
memset(head,-,sizeof(head));
}
void add_edge(int a,int b){
++sz;
to[sz]=b;Next[sz]=head[a];head[a]=sz;
}
int vis[maxn];
bool find_path(int u,int fa){
vis[u]=;
path.push_back(u);
if(path.size()>goal)
return true;
for(int i=head[u];i!=-;i=Next[i]){
int v=to[i];
if(vis[v])continue;
if(find_path(v,u))
return true;
}
path.pop_back();
return false;
}
int depth[maxn];
void dfs(int u,int fa){
vis[u]=;
depth[u]=path.size();
path.push_back(u);
int flag=;
for(int i=head[u];i!=-;i=Next[i]){
int v=to[i];
if(!vis[v]){flag=;break;}
}
if(flag){
for(int i=head[u];i!=-;i=Next[i]){
int v=to[i];
if(!vis[v])
dfs(v,u);
}
}else{
if(cir){
cir--;
int fax=-,fay=-;
for(int i=head[u];i!=-;i=Next[i]){
int v=to[i];
if(v==fa)continue;
if(fax==-)fax=v;
else if(fay==-){fay=v;break;}
}
if(depth[fax]<depth[fay])swap(fax,fay);
int ori=-;
if((depth[u]-depth[fax]+)%)ori=fax;
if((depth[u]-depth[fay]+)%)ori=fay;
if(ori==-){
printf("%d\n",depth[fax]-depth[fay]+);
printf("%d ",u);
for(int i=depth[fax];i>=depth[fay];i--){
printf("%d ",path[i]);
}
printf("\n");
}else{
printf("%d\n",depth[u]-depth[ori]+);
for(int i=depth[u];i>=depth[ori];i--){
printf("%d ",path[i]);
}
printf("\n");
}
}
}
path.pop_back();
} int main(){
scanf("%d%d%d",&n,&m,&k);
goal=n/k;
if(n%k)goal++;
init();
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
add_edge(u,v);
add_edge(v,u);
}
if(find_path(,)){
printf("PATH\n");
printf("%d\n",path.size());
for(int i=;i<path.size();i++){
printf("%d ",path[i]);
}
}else{
cir=k;
memset(vis,,sizeof(vis));
path.clear();
printf("CYCLES\n");
dfs(,);
}
return ;
}
Codeforces Round #534 (Div. 2)的更多相关文章
- Codeforces Round #534 (Div. 2) D. Game with modulo(取余性质+二分)
D. Game with modulo 题目链接:https://codeforces.com/contest/1104/problem/D 题意: 这题是一个交互题,首先一开始会有一个数a,你最终的 ...
- CF1103D Codeforces Round #534 (Div. 1) Professional layer 状压 DP
题目传送门 https://codeforces.com/contest/1103/problem/D 题解 失去信仰的低水平选手的看题解的心路历程. 一开始看题目以为是选出一些数,每个数可以除掉一个 ...
- CF1103C Johnny Solving (Codeforces Round #534 (Div. 1)) 思维+构造
题目传送门 https://codeforces.com/contest/1103/problem/C 题解 这个题还算一个有难度的不错的题目吧. 题目给出了两种回答方式: 找出一条长度 \(\geq ...
- Codeforces Round #534 (Div. 1)
A 构造题 有一个44的方格 每次放入一个横向12或竖向2*1的方格 满了一行或一列就会消掉 求方案 不放最后一行 这样竖行就不会消 然后竖着的放前两行 横着的放第三行 循环放就可以啦 #includ ...
- Codeforces Round #534 (Div. 2)D. Game with modulo-1104-D(交互+二分+构造)
D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #534 (Div. 2) Solution
A. Splitting into digits Solved. #include <bits/stdc++.h> using namespace std; int n; void sol ...
- [ACM]Codeforces Round #534 (Div. 2)
A. Splitting into digits Vasya has his favourite number n. He wants to split it to some non-zero dig ...
- Codeforces 1104 D. Game with modulo-交互题-二分-woshizhizhang(Codeforces Round #534 (Div. 2))
D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #534 (Div. 2) D. Game with modulo 交互题
先二分一个区间,再在区间里面二分即可: 可以仔细想想,想明白很有意思的: #include<iostream> #include<cstdio> #include<alg ...
随机推荐
- ApplicationEvent事件机制源码分析
<spring扩展点之三:Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法,在spring启动后做些事情> <服务网关zu ...
- 1062 Talent and Virtue (25 分)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
- javascript创建对象之工厂模式(一)
工厂模式在软件工程里面是一种比较常见的设计模式了.这种模式抽象了创建具体对象的过程. 上代码: function createHuman(name,sex) { var obj = new Objec ...
- javascript的防篡改对象之preventExtensions()方法
js在默认情况下,所有的对象都是可扩展的.这也是让很多开发人员头特疼的问题.因为在同一环境中,一不小心就会发生修改了不必要的对象,而自己却不知道. 在ECMAScript5可以解决这种问题了. pre ...
- 输出tuple和chrono的使用小例子
// move example #include <iostream> // std::cout #include<tuple> #include<ratio> # ...
- ubuntu 18.04下svn的安装与基本命令
一.安装: apt-get install subversion 二.基本命令 1.将文件checkout到本地目录 svn checkout path(path是服务器 上的目录)例如:svn ch ...
- python3中的mysql数据库操作
软硬件环境 OS X EI Capitan Python 3.5.1 mysql 5.6 前言 在开发中经常涉及到数据库的使用,而python对于数据库也有多种解决方法.本文以python3中的mys ...
- 折腾了好久,thinkphp5打开提示加载failed to open stream: No such file or directory in think start.php
GIT上下载的THINKPHP5记得先 composer update 我就是没update ,折腾了1个小时,才想起来这个事 thinkphp5默认首页打开空白 打开报错提示 提示thinkphp ...
- elt区间分布
select DATE_FORMAT(CURDATE(),'%Y%m%d') DateId,elt(interval(curnum,0, 10000,20000,30000,40000,50000, ...
- spring中 的MD5 加密
//对密码进行加密(不需要使用其他Md5工具 .spring中有 在digestUtils) String password = DigestUtils.md5DigestAsHex( ...