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)的更多相关文章

  1. Codeforces Round #534 (Div. 2) D. Game with modulo(取余性质+二分)

    D. Game with modulo 题目链接:https://codeforces.com/contest/1104/problem/D 题意: 这题是一个交互题,首先一开始会有一个数a,你最终的 ...

  2. CF1103D Codeforces Round #534 (Div. 1) Professional layer 状压 DP

    题目传送门 https://codeforces.com/contest/1103/problem/D 题解 失去信仰的低水平选手的看题解的心路历程. 一开始看题目以为是选出一些数,每个数可以除掉一个 ...

  3. CF1103C Johnny Solving (Codeforces Round #534 (Div. 1)) 思维+构造

    题目传送门 https://codeforces.com/contest/1103/problem/C 题解 这个题还算一个有难度的不错的题目吧. 题目给出了两种回答方式: 找出一条长度 \(\geq ...

  4. Codeforces Round #534 (Div. 1)

    A 构造题 有一个44的方格 每次放入一个横向12或竖向2*1的方格 满了一行或一列就会消掉 求方案 不放最后一行 这样竖行就不会消 然后竖着的放前两行 横着的放第三行 循环放就可以啦 #includ ...

  5. 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 ...

  6. Codeforces Round #534 (Div. 2) Solution

    A. Splitting into digits Solved. #include <bits/stdc++.h> using namespace std; int n; void sol ...

  7. [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 ...

  8. 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 ...

  9. Codeforces Round #534 (Div. 2) D. Game with modulo 交互题

    先二分一个区间,再在区间里面二分即可: 可以仔细想想,想明白很有意思的: #include<iostream> #include<cstdio> #include<alg ...

随机推荐

  1. 软件-分布式:Kylin (apache开源分布式分析引擎软件)

    ylbtech-软件-分布式:Kylin (apache开源分布式分析引擎软件) Apache Kylin™是一个开源的分布式分析引擎,提供Hadoop之上的SQL查询接口及多维分析(OLAP)能力以 ...

  2. GIS(地理信息系统)

    ylbtech-杂项:GIS(地理信息系统) 地理信息系统(Geographic Information System或 Geo-Information system,GIS)有时又称为“地学信息系统 ...

  3. Docker集群管理(一)—— 基础docker+swarm+shipyard

    目的 学习docker的集群管理,摸索出高可用的docker微服务架构方案.本篇文章只初步的了解下swarm(docker新版已集成了swarm)的使用,了解docker的发现服务的基础方法(dock ...

  4. mysql sleep连接过多解决办法

    睡眠连接过多,会对mysql服务器造成什么影响? 严重消耗mysql服务器资源(主要是cpu, 内存),并可能导致mysql崩溃. 造成睡眠连接过多的原因? 1. 使用了太多持久连接(个人觉得,在高并 ...

  5. position属性详解

    内容: 1.position属性介绍 2.position属性分类 3.relative相对定位 4.absolute绝对定位 5.relative和absolute联合使用进行定位 6.fixed固 ...

  6. uva-10054-欧拉回路

    题意:一个项链上面的每一个珠子有俩种颜色,前面一个珠子后面的颜色和后面珠子的前面颜色一样,有一天它断了, 一个人去搜集,问,搜集到的珠子能不能再次串成项链 原以为是链表,原来链表这组数据过不了. 71 ...

  7. Java调用Bat

    import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.Input ...

  8. canvas学习笔记、小函数整理

    http://bbs.csdn.net/topics/391493648 canvas实例分享 2016-3-16 http://bbs.csdn.net/topics/390582151 html5 ...

  9. zabbix监控windows系统CPU使用率

    参考网站:https://blog.csdn.net/reblue520/article/details/76287113 Zabbix 自带的模块没有 CPU 使用率(百分比)这个监控项,我们可以通 ...

  10. 58. :CREATE UNIQUE INDEX 终止,因为发现对象名称 'dbo.tSysParam' 和索引名称 'PK_tSysParam' 有重复的键

    更改实体对应表结构失败[修改实体对象表结构失败[修改表[tSysParam]的主键信息失败:CREATE UNIQUE INDEX 终止,因为发现对象名称 'dbo.tSysParam' 和索引名称 ...