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. 9-16Jenkins-1第一个任务

    jenkins安装搭建 #mac安装jenkins brew install jenkins #或下载war包 java -jar jenkins.war 第一个jenkins任务 创建一个自由风格的 ...

  2. 6-3-1appium iOS

    环境准备 brew install carthage npm i -g ios-deploy brew install libimobiledevice --HEAD brew install ide ...

  3. skopt超参数优化实例

    import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import load_boston from skl ...

  4. JS获取url传参

    function GetRequest() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new O ...

  5. 第3章 文件I/O(3)_内核数据结构、原子操作

    3. 文件I/O的内核数据结构 (1) 内核数据结构表 数据结构 主要成员 文件描述符表 ①文件描述符标志 ②文件表项指针 文件表项 ①文件状态标志(读.写.追加.同步和非阻塞等状态标志) ②当前文件 ...

  6. 用Dockerfile生成docker image

    在docker的官方php镜像中,有独立的php和apache版本的,这里尝试用php-fpm7.2.1(alpine3.7)作为基础镜像,在把nginx1.13.8加进去. 第一步:拉取php镜像: ...

  7. 对象DIY

    1.在java开发中,好代码都是组织的比较好,模拟现实很好,而不是步骤指令 2.对象组织+继承(归类

  8. blktrace 深度了解linux系统的IO运作

    http://blog.yufeng.info/archives/751 我们在Linux上总是要保存数据的,数据要么保存在文件系统里(如ext3),要么就在裸设备里面.我们在使用这些数据的时候都是通 ...

  9. 2018-2019-2 《网络对抗技术》Exp1 PC平台逆向破解 Week3 20165233

    Exp1 PC平台逆向破解 实验内容 一.基础知识点 NOP, JNE, JE, JMP, CMP汇编指令的机器码 NOP指令即"空指令",执行到NOP指令时,CPU什么也不做,机 ...

  10. 简单学习Git

    Git是什么? Git是目前世界上最先进的分布式版本控制系统(没有之一). Git有什么特点?简单来说就是:高端大气上档次! Git的发展历史 很多人都知道,Linus在1991年创建了开源的Linu ...