Codeforces Round #557 (Div. 1)
A.直接做。
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
int n,m,a[N],cnt[N],tot;
vector<int> pos[N];
ll ans; int main(){
scanf("%d%d",&m,&n);
rep(i,,n) scanf("%d",&a[i]),pos[a[i]].push_back(i);
rep(i,,m){
if (i>){
if (pos[i].empty()) ans++;
else{
int x=pos[i][];
if (pos[i-].empty() || pos[i-][pos[i-].size()-]<x) ans++;
}
}
if (pos[i].empty()) ans++;
if (i<m){
if (pos[i].empty()) ans++;
else{
int x=pos[i][];
if (pos[i+].empty() || pos[i+][pos[i+].size()-]<x) ans++;
}
}
}
cout<<ans<<endl;
return ;
}
B.显然转的角度是n的约数,枚举约数暴力判断是否合法即可。
#include<cstdio>
#include<algorithm>
#include<vector>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std; const int N=;
int n,m,x,y;
vector<int>E[N]; vector<int>work(vector<int>a,int b){
int sz=a.size(),p=;
rep(i,,sz-) if((a[i]+b)%n<(a[p]+b)%n)p=i;
vector<int>c(sz);
rep(i,p,sz-) c[i-p]=(a[i]+b)%n;
rep(i,,p-) c[i+sz-p]=(a[i]+b)%n;
return c;
} int main(){
scanf("%d%d",&n,&m);
rep(i,,m) scanf("%d%d",&x,&y),x--,y--,E[x].push_back(y),E[y].push_back(x);
rep(i,,n-) sort(E[i].begin(),E[i].end());
rep(k,,n-) if (n%k==){
int flag=;
rep(i,,n-) if (work(E[i],k)!=E[(i+k)%n]){ flag=; break; }
if (flag){ puts("Yes"); return ; }
}
puts("No");
return ;
}
C.数据范围明显欺诈,讲一下我的思路,不是严谨证明。尝试从最终局面倒推:
最后局面:有石子的堆数小于n/2。(必败)
倒数第二步:至少有一堆没有石子,这样就可以通过拿走n/2堆的全部石子来转移到最终局面。(必胜)
倒数第三步:所有堆都有石子,且至少有n/2+1个堆的石子个数为1。因为面临此局面的人一定不希望制造出一个没有石子的堆,只有迫不得已的情况下才会制造出,也就是所选堆中有至少一个堆只有一个石子。(必败)
倒数第四步:至少有一堆有且仅有一个石子,这样就可以通过让另外n/2堆都只剩一个石子来达到倒数第三步的局面。(必胜)
倒数第五步:至少有n/2+1个堆的式子个数为2,分析与倒数第三步类似。(必败)
根据上面的分析可以得出,当含有最小石子数的堆数超过半数时必败,否则必胜。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=,inf=1e9;
int n,mn=inf,tot,a[N]; int main(){
scanf("%d",&n);
rep(i,,n) scanf("%d",&a[i]),mn=min(mn,a[i]);
rep(i,,n) if (a[i]==mn) tot++;
if (tot<=n/) puts("Alice"); else puts("Bob");
return ;
}
D.显然b的位数就是|s|,枚举a的位数m。然后可以通过题目条件得到一些形如“a[i]与a[j]相同”“b[i]与b[j]相同”“a[i]与b[j]相同”“a[i]与b[j]不同”“a[i]为0/1”“b[i]为0/1”的约数。我的做法是,建立n+m+2个点分别表示b的每一位、a的每一位、0、1。对于“相同”约束连权值为0的边,“不同”约束连1边。若图中存在奇环或存在长度为偶数的0到1的路径时无解。否则对于一个连通块,确定其中一个值就可以确定所有值,而这个连通块的取值与连通块之外的点无关,于是答案就是2^(除0和1所在的连通块之外的连通块数)。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
#define For(i,x) for (int i=h[x],k; i; i=nxt[i])
typedef long long ll;
using namespace std; const int N=,M=N*,mod=;
bool flag;
char s[N];
int n,ans,cnt,h[N],vis[N],to[M],nxt[M],val[M]; void add(int u,int v,int w){
to[++cnt]=v; val[cnt]=w; nxt[cnt]=h[u]; h[u]=cnt;
to[++cnt]=u; val[cnt]=w; nxt[cnt]=h[v]; h[v]=cnt;
} void dfs(int x){
For(i,x) if (~vis[k=to[i]]){
if ((vis[x]^val[i])!=vis[k]){ flag=; return; }
}else vis[k]=vis[x]^val[i],dfs(k);
} int main(){
scanf("%s",s+); n=strlen(s+);
rep(m,,n-){
cnt=; int res=; flag=;
rep(i,,n+m+) h[i]=,vis[i]=-;
add(n,n+m+,); add(m+n,n+m+,);
rep(i,,n) add(i,n-i+,);
rep(i,,m) add(i+n,m-i++n,);
rep(i,,m){
if (s[n-i+]=='') add(i,i+n,);
if (s[n-i+]=='') add(i,i+n,);
}
rep(i,m+,n){
if (s[n-i+]=='') add(i,n+m+,);
if (s[n-i+]=='') add(i,n+m+,);
}
vis[n+m+]=; dfs(n+m+);
if (vis[n+m+]==) continue;
vis[n+m+]=; dfs(n+m+);
rep(i,,n+m) if (vis[i]==-) vis[i]=,res=*res%mod,dfs(i);
if (flag) continue;
ans=(ans+res)%mod;
}
printf("%d\n",ans);
return ;
}
Codeforces Round #557 (Div. 1)的更多相关文章
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #557 Div. 1 based on Forethought Future Cup - Final Round
A:开场就读错题.读对了之后也没啥好说的. #include<bits/stdc++.h> using namespace std; #define ll long long #defin ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
随机推荐
- Springboot配置文件获取系统环境变量的值
注意,这里说的是获取系统环境变量的值,譬如Windows里配置的JAVA_HOME之类的,可以直接在Springboot的配置文件中获取. 我们经常使用一些docker管理平台,如DaoCloud.r ...
- linux 中 scp 命令
scp命令用于Linux 之间复制文件和目录.如果想在windows 环境中使用需要安装 linux 命令环境,比如 cmder scp是 secure copy的缩写, scp是linux系统下基于 ...
- PHP如何防止注入及开发安全
1.PHP注入的基本原理 程序员的水平及经验也参差不齐,相当大一部分程序员在编写代码的时候,没有对 用户输入数据的合法性进行判断,使应用程序存在安全隐患.用户可以提交一段数据 库查询代码,根据程序返回 ...
- python获取公网ip的几种方式
python获取公网ip的几种方式 转 https://blog.csdn.net/conquerwave/article/details/77666226 from urllib2 import u ...
- 读取Excel,通过Testng完成数据驱动
背景 数据驱动是我们写自动化脚本非常常用的技术,而Testng中数据驱动常用的注解是 @DataProvider,但是这个方法必须返回一个Object[][].最近常有学生问起,如果通过外部文件作为数 ...
- git git push某一次的commit记录
$ git push <remote name> <commit hash>:<remote branch name> # Example:$ git push o ...
- Python3入门(十三)——常用内置模块之时间日期模块datatime
1.日期时间模块——datatime //其他模块例如time.calender等模块暂不展开 (1)获取当前时间:datatime.now(): from datetime import datet ...
- 【JS】jquery展示JSON插件JSONView
JSONView介绍 jQuery插件,用于显示漂亮的JSON. 官网地址:https://plugins.jquery.com/jsonview/ git地址:https://github.com/ ...
- if判断用法
- Laya的资源加载
白鹭中的资源加载,可以单个去加载.但是更多是通过资源组加载的. 比如进入登录界面,则加载登录资源组的资源.销毁登录界面,则卸载登录模资源. //加载登录模块资源组 RES.loadGroup(&quo ...