Codeforces Round #553 (Div. 2)

A. Maxim and Biology

题目:http://codeforces.com/contest/1151/problem/A

  暴力

B. Dima and a Bad XOR

题目:http://codeforces.com/contest/1151/problem/B

所选数异或不等于零即可 按题意模拟     

理解错题意 gg

#include<iostream>
#define N 1010
using namespace std;
int n,m;
int a[N][N],c[N];
void pr(){
	cout<<"TAK"<<endl;
	for(int i=1;i<=n;i++)
	cout<<c[i]<<" ";
	 
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		sum^=a[i][1];
		c[i]=1;
	}
	if(sum) pr();
	else{
      for(int i=1;i<=n;i++){
		for(int j=2;j<=m;j++){
			if(a[i][j]!=a[i][1]){
				c[i]=j;
				pr();
				return 0;
			}
		}
	  }
	  cout<<"NIE"<<endl;
     }
	return 0;
}

C. Problem for Nazar

题目:http://codeforces.com/contest/1151/problem/C

a[]={1,3,5,7,9,11,...2n-1};

b[]={2,4,6,8,10,12,14,...2n};

将a[],b[],以1,2,4,8,..的个数合并

1 / 2 4 / 3 5 7 9 / 6 8 10  12 14 16 18 20 / 11..

找区间l,r的和   

解:找出n位置前出现的a[]的个数 b[]的个数  等差数列求和

#include<iostream>
#define ll long long
using namespace std;
const ll M = 1000000007;
ll slove(ll  up){
    ll x=0,f=0,nx=1,a=0,b=0;
    while(x<up){
    	if(!f) a+=min(up-x,nx);
    	else b+=min(up-x,nx);
    	f=1-f;
    	x+=nx;
    	nx*=2;
	}
	a%=M;b%=M;
	return  (a*a)%M+((1+b)*b)%M;
}
int main(){
	ll l,r;
	cin>>l>>r;
	cout<<((slove(r)-slove(l-1))%M+M)%M<<endl;
	return 0;
}

D. Stas and the Queue at the Buffet

题目:http://codeforces.com/contest/1151/problem/D

考虑左右数对乘积影响的权值     按照a-b的结果从大到小排序

#include<iostream>
#include<algorithm>
#define ll long long
#define N 100010
#define P pair<ll,ll>
using namespace std;
int n;
P a[N],b[N];
bool cmp1(P x,P y){
	return x.first-x.second>y.first-y.second;
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		ll x,y;
		cin>>x>>y;
		a[i]=P(x,y);
		b[i]=a[i];
	}
	sort(a+1,a+1+n,cmp1);
	ll sum1=0;
	for(int i=1;i<=n;i++){
		sum1+=a[i].first*(i-1)+a[i].second*(n-i);
	}
	cout<<sum1<<endl;
	return 0;
}

E. Number of Components

题目:http://codeforces.com/contest/1151/problem/E

还是看不懂:https://blog.csdn.net/qq_41829060/article/details/89397907

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值