# A - Pizza, Pizza, Pizza!!!

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 1e5+10;

int main()
{
long long n;
while(scanf("%I64d",&n)!=EOF)
{
n++;
if(n==1LL)
{
n=0LL;
}
if(n%2LL==0LL)
{
n /= 2LL;
}
printf("%I64d\n",n);
}
return 0;
}


# B - Treasure Hunt

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 1e5+10;

int ku[52],sh[52],ka[52];

int main()
{
int n;
ios::sync_with_stdio(false);
//freopen("in.txt","r",stdin);
while(cin >> n)
{
memset(ku,0,sizeof ku);
memset(sh,0,sizeof sh);
memset(ka,0,sizeof ka);
string Kuro,Shiro,Katie;
cin >> Kuro >> Shiro >> Katie;
int len = Kuro.size();
for(int i=0;i<len;i++)
{
int pos = Kuro[i];
if(pos>='a'&&pos <= 'z')
{
ku[pos-'a']++;
}
else
{
ku[pos-'A'+26]++;
}
pos = Shiro[i];
if(pos>='a'&&pos <= 'z')
{
sh[pos-'a']++;
}
else
{
sh[pos-'A'+26]++;
}
pos = Katie[i];
if(pos>='a'&&pos <= 'z')
{
ka[pos-'a']++;
}
else
{
ka[pos-'A'+26]++;
}
}
int kulen=0,shlen=0,kalen=0;
for(int i=0;i<52;i++)
{
if(ku[i]>kulen)
{
kulen = ku[i];
}
if(sh[i]>shlen)
{
shlen = sh[i];
}
if(ka[i]>kalen)
{
kalen = ka[i];
}
}
//cout << kulen << "*" << shlen << "*" << kalen << "*" << len << "*" << n << endl;
//int lef;
//cout << kulen << "**" << endl;
if(kulen == len&&n==1)
{
kulen--;
}
else
{
kulen += n;
if(kulen >len)
{
kulen = len;
/*lef = len - kulen;
if(lef%2>0)
{
kulen--;
}*/
}
}
if(shlen == len&&n==1)
{
shlen--;
}
else
{
shlen += n;
if(shlen >len)
{
shlen = len;
/*lef = len - shlen;
if(lef%2>0)
{
shlen--;
}*/
}
}
if(kalen == len&&n==1)
{
kalen--;
}
else
{
kalen += n;
if(kalen >len)
{
kalen = len;
/*lef = len - kalen;
if(lef%2>0)
{
kalen--;
}*/
}
}
if(kulen>shlen&&kulen>kalen)
{
cout << "Kuro\n";
}
else if(shlen>kulen&&shlen>kalen)
{
cout << "Shiro\n";
}
else if(kalen>kulen&&kalen>shlen)
{
cout << "Katie\n";
}
else
{
cout << "Draw\n";
}
//cout << kulen << "*" << shlen << "*" << kalen << endl << endl;
}
return 0;
}


# C - Kuro and Walking Route

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 3e5+10;

vector <int> ne[maxn];
bool vis[maxn];
int nep[maxn];

void dfs(int p,int q)
{
int len = ne[p].size();
vis[p] = true;
for(int i=0;i<len;i++)
{
int nowpos = ne[p][i];
if(vis[nowpos])
{
continue;
}
nep[nowpos] = p;
if(nowpos == q)
{
return ;
}
dfs(nowpos,q);
}
return ;
}

void dfsnum(int k,long long &num)
{
vis[k] = true;
int len = ne[k].size();
for(int i=0;i<len;i++)
{
int nowpos = ne[k][i];
if(vis[nowpos])
{
continue;
}
num++;
dfsnum(nowpos,num);
}
return ;
}

int main()
{
int n,x,y;
//freopen("in.txt","r",stdin);
while(scanf("%d%d%d",&n,&x,&y)!=EOF)
{
for(int i=1;i<=n;i++)
{
ne[i].clear();
}
memset(vis,false,sizeof vis);
//memset(len,0,sizeof len);
memset(nep,-1,sizeof nep);
for(int i=1;i<n;i++)
{
int p,q;
scanf("%d%d",&p,&q);
ne[p].push_back(q);
ne[q].push_back(p);
}
if(n==1)
{
printf("0\n");
}
else
{
dfs(x,y);
int nepy = nep[y];
int nepx;
for(nepx=y;nep[nepx]!=x;nepx=nep[nepx]);
long long re = (long long)(n) * (long long)(n-1);
long long xnum = 1;
long long ynum = 1;
int xlen = ne[x].size();
int ylen = ne[y].size();
memset(vis,false,sizeof vis);
for(int i=0;i<xlen;i++)
{
int nowpos = ne[x][i];
if(nowpos == y || nowpos == nepx)
{
continue;
}
xnum++;
vis[x] = true;
dfsnum(nowpos,xnum);
}
for(int i=0;i<ylen;i++)
{
int nowpos = ne[y][i];
if(nowpos == x || nowpos == nepy)
{
continue;
}
ynum++;
vis[y] = true;
dfsnum(nowpos,ynum);
}
re -= xnum * ynum;
printf("%I64d\n",re);
//cout << xnum << "*" << ynum << endl;
}
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120