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;
}

猜你喜欢

转载自blog.csdn.net/qq_41722217/article/details/89397808