码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #270 A B C

时间:2019-07-13 12:06:03      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:force   i+1   else   pre   int   rcm   make   pac   test   

ADesign Tutorial: Learn from Math

素数筛

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int a[N]={0};
int main(){
	int n;
	cin >> n;
	a[1] = 1;
	for(int i = 2; i*i <= n; i++){
		if(a[i] == 0){
			for(int j = i*i; j <= n; j += i){
				a[j] = 1;
			}
		}
	}
	
	for(int i = 2; i <= n; i++){
		if(a[i] && a[n-i]){
			cout << i << " " << n - i <<"\n";
			return 0;
		}
	}
	return 0;
}

  BDesign Tutorial: Learn from Life

贪心,从大到小,一次取k个,统计每次的楼层最高

#include<bits/stdc++.h>
using namespace std;
const int N = 2e3;

int n, k;
int a[N];
int main(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a, a + n);
	int sum = 0;
	for(int i = n-1; i >= 0 ; i-=k){
		sum += (a[i] - 1) * 2;
	}
	cout << sum << "\n";
	return 0;
}

  CDesign Tutorial: Make It Nondeterministic

模拟

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;

int n;
char s1[N][60];
char s2[N][60];
int a[N];
int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> s1[i] >> s2[i];
	}
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int p=3;//可以选任意一个为handle
	for(int i = 0; i < n-1; i++){
		bool b1=strcmp(s1[a[i]], s1[a[i+1]]) == -1;
		bool b2=strcmp(s2[a[i]], s1[a[i+1]]) == -1;
		bool b3=strcmp(s1[a[i]], s2[a[i+1]]) == -1;
		bool b4=strcmp(s2[a[i]], s2[a[i+1]]) == -1;
		if(p==3){
			if((b1|| b2) && (b3 || b4));
			else if(b1 || b2)
				p=1;//只能选第一个为handle
			else if(b3 || b4)
				p=2;//只能选第二个为handle
			else{
				cout<< "NO\n";
				return 0;
			}
		}
		else if(p == 2){
			if(b2 && b4)
				p=3;
			else if(b2)
				p=1;
			else if(b4)
				p=2;
			else{
				cout<< "NO\n";
				return 0;
			}
		}
		else if( p== 1){
			if(b1 && b3)
				p=3;
			else if(b1)
				p=1;
			else if(b3)
				p=2;
			else{
				cout<< "NO\n";
				return 0;
			}
		}
	}
	cout << "YES\n";
	return 0;
}

  

Codeforces Round #270 A B C

标签:force   i+1   else   pre   int   rcm   make   pac   test   

原文地址:https://www.cnblogs.com/YJing814/p/11179983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!