Codeforces Round #482 (Div. 2)

大城市里の小女人 提交于 2020-05-02 15:08:53

标签: 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

留坑

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!