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. css display table使用小例子实验

    display的下面: table: 此元素会作为块级表格来显示(类似 <table>),表格前后带有换行符. table-row 此元素会作为一个表格行显示(类似 <tr>) ...

  2. Win7_64位 CHM打不开

    (2)在命令行运行regsvr32 itss.dll (3)在命令行运行regsvr32 hhctrl.ocx (4)开始--运行--输入“regedit”,打开注册表,找到以下分支: HKEY_LO ...

  3. zclip复制到剪切板插件有个bug

    今天发现zclip复制到剪切板插件有个bug,就是在遨游和360浏览器的兼容模式下,点击复制没响应,后来我看了页面代码,发现在这两个浏览器的兼容模式下,生成的是<object>,其他浏览器 ...

  4. 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

  5. 浅析HttpCient

    HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.虽然在 JDK 的 java.net 包中已经提供了 ...

  6. pandas的map函数与apply函数的区别

    import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(4,3),columns=list("ABC ...

  7. 解决WPF两个图片控件显示相同图片因线程占用,其中一个显示不全的问题

    在做项目的过程中遇到这样一个问题,下面提出一种解决方法,主要思想是图片的Copy,如还有其他方法,欢迎交流. 在前端图片控件绑定显示时,使用转换器进行转义绑定   (1)转换器: public cla ...

  8. Valve新员工手册中文版

  9. openVswitch(OVS)源代码分析之工作流程(数据包处理)

    上篇分析到数据包的收发,这篇开始着手分析数据包的处理问题.在openVswitch中数据包的处理是其核心技术,该技术分为三部分来实现:第一.根据skb数据包提取相关信息封装成key值:第二.根据提取到 ...

  10. 求m-n之间数字的和

    unction sum(m,n){         var sum = 0;         if(m>n){                 for(var i=n; i<=m; i++ ...