# AtCoder Grand Contest 014

#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,ans;
int main()
{
scanf("%d%d%d",&a,&b,&c);
if(a%2==0&&a==b&&b==c){puts("-1");return 0;}
while(a%2==0&&b%2==0&&c%2==0)
{
int aa=a>>1,bb=b>>1,cc=c>>1;
a=bb+cc;b=aa+cc;c=aa+bb;++ans;
}
printf("%d\n",ans);
return 0;
}


## B - Unplanned Queries

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define MAX 100100
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
int n,m,f[MAX],a[MAX];
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
vector<int> E[MAX];
void dfs(int u,int ff){for(int v:E[u])if(v!=ff)dfs(v,u),a[u]^=a[v];}
int main()
{
for(int i=1;i<=n;++i)f[i]=i;
for(int i=1;i<=m;++i)
{
if(getf(u)!=getf(v))
E[u].push_back(v),E[v].push_back(u),f[getf(u)]=getf(v);
a[u]^=1;a[v]^=1;
}
for(int i=1;i<=n;++i)
if(getf(i)!=getf(1))E[1].push_back(i),E[i].push_back(1),f[getf(i)]=getf(1);	dfs(1,0);
for(int i=1;i<=n;++i)if(a[i]){puts("NO");return 0;}
puts("YES");
return 0;
}


## C - Closed Rooms

#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
#define MAX 808
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
int ans,n,m,K,sx,sy;
char g[MAX][MAX];
int Calc(int x,int y){return min(min(x-1,n-x),min(y-1,m-y));}
int dis[MAX][MAX];
int d[4][2]={1,0,0,1,-1,0,0,-1};
void BFS(int sx,int sy)
{
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)dis[i][j]=1e9;
dis[sx][sy]=0;ans=1e9;
queue<int> Qx,Qy;Qx.push(sx),Qy.push(sy);
while(!Qx.empty())
{
int x=Qx.front(),y=Qy.front();Qx.pop();Qy.pop();
ans=min(ans,(Calc(x,y)+K-1)/K);
if(dis[x][y]>=K)continue;
for(int i=0;i<4;++i)
{
int xx=x+d[i][0],yy=y+d[i][1];
if(xx<1||xx>n||yy<1||yy>m)continue;
if(g[xx][yy]=='#')continue;
if(dis[xx][yy]<=dis[x][y]+1)continue;
dis[xx][yy]=dis[x][y]+1;
Qx.push(xx);Qy.push(yy);
}
}
}
int main()
{
for(int i=1;i<=n;++i)scanf("%s",g[i]+1);
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
if(g[i][j]=='S')sx=i,sy=j;
BFS(sx,sy);
printf("%d\n",ans+1);
return 0;
}


## D - Black and White Tree

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define MAX 100100
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
int n;
vector<int> E[MAX];
bool dfs(int u,int ff)
{
int cnt=0;
for(int v:E[u])
{
if(v==ff)continue;
if(dfs(v,u))++cnt;
}
if(cnt>=2){puts("First");exit(0);}
return cnt^1;
}
int main()
{
for(int i=1;i<n;++i)
{
E[u].push_back(v);
E[v].push_back(u);
}
if(dfs(1,0))puts("First");
else puts("Second");
return 0;
}


## E - Blue and Red Tree

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define MAX 100100
#define pi pair<int,int>
#define mp make_pair
#define fr first
#define sd second
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
int n,f[MAX];
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
queue<pi> Q;
map<pi,int> M;
set<int> E[MAX];
pi get(int x,int y){if(x>y)swap(x,y);return mp(x,y);}
{
E[x].insert(y);E[y].insert(x);
pi u=get(x,y);
if(++M[u]==2)Q.push(u);
}
int main()
{
for(int i=1;i<=n;++i)f[i]=i;
for(int i=1,x,y;i<n;++i)
{
do
{
if(Q.empty()){puts("NO");return 0;}
x=Q.front().fr,y=Q.front().sd;Q.pop();
x=getf(x);y=getf(y);
}while(x==y);
if(E[x].size()>E[y].size())swap(x,y);
f[x]=y;M.erase(get(x,y));E[y].erase(x);
for(auto v:E[x])
{
int fv=getf(v);
if(fv==y)continue;
M.erase(get(x,fv));
E[fv].erase(x);
}
}
puts("YES");
return 0;
}


## F - Strange Sorting

#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 200200
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
int n,a[MAX],b[MAX],T[MAX],f[MAX];
int main()
{
for(int i=n-1;i;--i)
if(!T[i+1])
{
if(b[i]>b[i+1])T[i]=1,f[i]=i+1;
else T[i]=0;
}
else
{
if((b[f[i+1]]<b[i])+(b[i]<b[i+1])+(b[i+1]<b[f[i+1]])==2)T[i]=T[i+1],f[i]=f[i+1];
else T[i]=T[i+1]+1,f[i]=i+1;
}
printf("%d\n",T[1]);
return 0;
}

posted @ 2019-05-04 09:51  小蒟蒻yyb  阅读(...)  评论(...编辑  收藏