【队伍训练3】Codeforces Round #661 (Div. 3)

A
签到

#include<bits/stdc++.h>

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int a[105];
int main(){
	ios
    int n,t;
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++){
           cin>>a[i];
        }
        sort(a+1,a+n+1);
        bool flag=1;
        for(int i=1;i<n;i++){
           if(a[i+1]-a[i]>1){
             flag=0;
             break;
           }
        }
        if(flag){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

B

#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define rint register int
using namespace std;
const int INF=2e9+5,N=56;
int T,n;
int a[N],b[N];
int mina,minb;
LL ans;
int main()
{
//	freopen("1.in","r",stdin);
	int i;
	scanf("%d",&T);
	while(T--) {
		mina=minb=INF; ans=0;
		scanf("%d",&n);
		for(i=1;i<=n;i++) 
			scanf("%d",&a[i]),mina=min(a[i],mina);
		for(i=1;i<=n;i++)
			scanf("%d",&b[i]),minb=min(b[i],minb);
		for(i=1;i<=n;i++) 
			ans+=(LL)max(b[i]-minb,a[i]-mina);
		printf("%lld\n",ans);
	}
	return 0;
}

C

#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define rint register int
using namespace std;
const int N=256,INF=1e9;
int T,n;
int w[N],cnt[N];
int main()
{
//	freopen("1.in","r",stdin);
	int i,j;
	int x;
	scanf("%d",&T);
	int res,ans;
	while(T--) {
		ans=-INF;
		scanf("%d",&n);
		for(i=1;i<=n;i++)
			scanf("%d",&w[i]);
		for(i=2;i<=(n<<1);i++) {
			memset(cnt,0,sizeof cnt);
			res=0;
			for(j=1;j<=n;j++) 
				cnt[w[j]]++;
			for(j=1;i-j>=1;j++) {
				if(cnt[j]==0) continue;
				if(i-j==j) {
					res+=cnt[j]/2;
					cnt[j]=cnt[j]%2;
				}
				else {
					x=min(cnt[j],cnt[i-j]);
					res+=x;
					cnt[j]-=x; cnt[i-j]-=x;
				}	
			}
			ans=max(ans,res);
		}
		printf("%d\n",ans);
	}
	return 0;
}

D

#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define rint register int
using namespace std;
const int N=2e5+5;
int a[N];
char c[N];
int T,n;
struct DSU
{
	int par[N];
	int Find(int x)	
	{
		if(x==par[x]) return x;
		else return par[x]=Find(par[x]);
	}
	inline void reset(int n)
	{
		for(int i=1;i<=n+4;i++) 
			par[i]=i;
		return;
	}
}b0,b1;
int d[N];
void draw(int now,int col)
{
	if(now>n) return;
	d[now]=col;
	if(a[now]==0) {
		b0.par[now]=b0.Find(now+1);
		draw(b1.Find(now),col);
	} 
	else {
		b1.par[now]=b1.Find(now+1);
		draw(b0.Find(now),col);
	}
	return;
}
int main()
{
//	freopen("1.in","r",stdin);
	int i;
	int ans;
	scanf("%d",&T);
	while(T--) {
		ans=0;
		scanf("%d",&n);
		fill(d,d+n+2,0);
		scanf("%s",c+1);
		for(i=1;i<=n;i++) 	
			a[i]=c[i]-'0';
		b0.reset(n); b1.reset(n);
		for(i=n;i>=1;i--) {
			if(a[i]==1) b1.par[i]=i,b0.par[i]=b0.par[i+1];
			else b1.par[i]=b1.par[i+1],b0.par[i]=i;
		}
		for(i=1;i<=n;i++) {
			if(d[i]>0) continue;
			d[i]=++ans;
			draw(i,ans);
		}
		printf("%d\n",ans);
		for(i=1;i<=n;i++) 
			printf("%d ",d[i]);
		printf("\n");
	}
	return 0;
}

E1

#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define rint register int
using namespace std;
const int N=2e5+5;
int one[N];
int ver[N],Next[N],idx;
LL edge[N];
inline void AddEdge(int a,int b,LL c)
{
	Next[++idx]=one[a];
	one[a]=idx;
	ver[idx]=b;
	edge[idx]=c;
	return;
}
//==================================
LL sum[N];
int T,n;
LL S;
LL ss,ans;
priority_queue< pair<LL,int> > q;
void dfs(int x,int fa)
{
	sum[x]=0;
	int i;
	for(i=one[x];i>0;i=Next[i]) {
		if(ver[i]!=fa) 
			dfs(ver[i],x),sum[x]+=sum[ver[i]];
	}
	for(i=one[x];i>0;i=Next[i]) {
		if(ver[i]==fa) continue;
		q.push(make_pair(sum[ver[i]]*(edge[i]-edge[i]/2),i));
		ss+=sum[ver[i]]*edge[i];
	}
	if(ver[one[x]]==fa&&Next[one[x]]==0) 
		sum[x]=1;
	return;
}
int main()
{
//	freopen("1.in","r",stdin);
	int i;
	int x,y;
	LL z;
	scanf("%d",&T);
	while(T--) {
		while(q.size()) q.pop();
		ss=0; ans=0;
		scanf("%d%lld",&n,&S);
		idx=0;
		fill(one,one+n+2,0);
		fill(ver,ver+2*n+2,0);
		fill(Next,Next+2*n+2,0);
		fill(edge,edge+2*n+2,0);
		for(i=1;i<=n-1;i++) {
			scanf("%d%d%lld",&x,&y,&z);
			AddEdge(x,y,z);
			AddEdge(y,x,z);
		}
		dfs(1,0);
		while(ss>S) {
			x=q.top().second; z=q.top().first;
			q.pop(); ans++;
			ss-=z;
			edge[x]=edge[x]/2;
			q.push(make_pair(sum[ver[x]]*(edge[x]-edge[x]/2),x));
		}
		printf("%lld\n",ans);
	}
	return 0;
}

©️2020 CSDN 皮肤主题: 黑客帝国 设计师:上身试试 返回首页