Codeforces Round #760

A

解个三元一次方程

rep(i,1,7) cin>>a[i];
sort(a+1,a+8);
cout<<a[1]<<' '<<a[2]<<' '<<a[7]-a[1]-a[2]<<'\n';

B

尾首相同加后t[1],否则加上整个t,不足补a

                string s,t,res,d;
		cin>>n>>s;
		res+=s;
		rep(i,1,n-3)
		{
			cin>>t;
			
			if(t[0]==s[1])
				res +=t[1];
			else res+= t;
			s = t;
		}
		if(res.size()<n)res+='a';
		cout<<res<<endl;

C

对奇数列和偶书列取最小公因数,分别尝试是否能行,不行取0;

        cin>>n; int a1=0,b1=0;
        rep(i,1,n){
            cin>>c[i];
            if(i&1) a[a1++] = c[i];
            else b[b1++] = c[i];
        }
        ll ma = maxgysarray(a,a1);
        ll mb = maxgysarray(b,b1);
        //cout<<ma<<' '<<mb<<endl;
        int fa = 0,fb = 0;
        rep(i,1,n){
            if(i&1){
                if(c[i]%mb==0) fa = 1;
            }
            else if(c[i]%ma==0) fb = 1;
        }
        //cout<<fg<<fb<<endl;
        if(!fa) cout<<mb<<endl;
        else if(!fb) cout<<ma<<endl;
        else cout<<0<<endl;

D

排序后取最后2*k个,令i=n-k,j = n;从后往前res += i/j即可

        cin>>n>>k;
        rep(i,1,n) cin>>a[i];
        sort(a+1,a+n+1);
        int i = n-k,j = n;
        int res = 0;
        while(k--)
        {
            res+=a[i--]/a[j--];
        }
    
        for(;k<=i;k++) res+=a[k];
        cout<<res<<endl;

E

公式推导(高斯是不可能的):bi - bi-1 = Σ \Sigma Σai - n*ai

Σ \Sigma Σai *(n+1)*n/2 = Σ \Sigma Σbi

		cin>>n; ll sum = 0;
		
		rep(i,1,n) cin>>a[i],sum += a[i];
		
		bool ok  = 1;
		
		if(sum%((n+1)*n/2)) ok = 0;
		
		sum/=((n+1)*n/2);
		
		rep(i,1,n)
		{
			int j = i-1;
			if(!j) j = n;
			ll ca = sum - a[i]+a[j];
			if(ca%n) ok = 0;
			
			b[i] = ca/n;
			
			if(b[i]<=0) ok = 0;
                }
                if(ok)
		{
			cout<<"Yes\n";
			rep(i,1,n) cout<<b[i]<<' ';
			cout<<endl;
		}
		else cout<<"No\n";

F

新加入的可能结果二进制必然首尾是1,逆推dfs一下,有环剪下枝

ll reverse(ll x)
{
	int cnt = 0;
	for (; x; x /= 2)
		a[++cnt] = x & 1;
	ll y = 0;
	for(int i = 1;i<=cnt; i++)
		y = y*2 +a[i];
	return y;
}

bool dfs(ll x)
{
	if(!x) return 0;
	if(s.find(x)!=s.end()) return 0;
	if(x==x1||x== x2) return 1;
	s.insert(x);
	
	if(x&1)
	{
		if(reverse(x)!=x &&dfs(reverse(x)))
			return 1;
		int cnt = 0;
		for (; x; x /= 2)
		a[++cnt] = x & 1;
	
		if(cnt>1 && a[1] && a[2])
		{
			ll z = 0;
			rep(i,2,cnt) z = z*2 + a[i];
			if(dfs(z)) return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>x>>y;
	if(x==y)
	{
		puts("Yes"); return 0;
	}
	x1 = reverse(x*2+1);
	x2 = reverse(x*2);
	if(dfs(y)) puts("Yes");
	else puts("No");
    
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值