标签: codeforces
题目链接
http://codeforces.com/contest/979
A.Pizza, Pizza, Pizza!!!
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn=100050;
const int MOD=1e9+7;
int main(int argc, char const *argv[])
{
ll x;
cin>>x;
x++;
if(x==1) printf("0\n");
else if(x&1) printf("%lld\n", x);
else printf("%lld\n", x/2);
return 0;
}
B.Treasure Hunt
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=100050;
const int MOD=1e9+7;
int b[300];
int solve(string &s,int n){
if(n>s.size()) return s.size();
memset(b,0,sizeof b);
for (int i = 0; i < s.size(); ++i)
{
b[s[i]]++;
}
int m=s.size();
int ans=0;
int cnt=0;
for (int i = 0; i < 300; ++i)
{
if(b[i]) cnt++;
if(n<=m-b[i]){
ans=max(ans,n+b[i]);
}
else{
if(n==1&&m==b[i]) ans=max(ans,m-1);
else ans=max(ans,m);
}
}
return ans;
}
int main(int argc, char const *argv[])
{
int n;
string a,b,c;
cin>>n>>a>>b>>c;
int x=solve(a,n);
int y=solve(b,n);
int z=solve(c,n);
int M=max(x,max(y,z));
int C=0;
if(M==x) C++;
if(M==y) C++;
if(M==z) C++;
if(C>=2) printf("Draw\n");
else if(M==x) printf("Kuro\n");
else if(M==y) printf("Shiro\n");
else if(M==z) printf("Katie\n");
return 0;
}
C.Kuro and Walking Route
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=300050;
const int MOD=1e9+7;
typedef long long ll;
std::vector<int> v[maxn];
int sz[maxn];
void dfs(int x,int fa){
sz[x]=1;
for(auto y:v[x]){
if(y!=fa){
dfs(y,x);
sz[x]+=sz[y];
}
}
}
int main(int argc, char const *argv[])
{
int n,x,y;
scanf("%d%d%d", &n,&x,&y);
for (int i = 0; i < n-1; ++i)
{
int u,w;
scanf("%d%d", &u,&w);
v[u].push_back(w);
v[w].push_back(u);
}
dfs(x,x);
ll s1=sz[y];
dfs(y,y);
ll s2=sz[x];
printf("%lld\n", (ll)n*(n-1)-s1*s2);
return 0;
}
D.Kuro and GCD and XOR and SUM
留坑
E.Kuro and Topological Parity
留坑
来源:oschina
链接:https://my.oschina.net/u/4265407/blog/3973143