Codeforces Round #270 A B C

Posted yjing814

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #270 A B C相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #270 D. Design Tutorial: Inverse the Problem

Codeforces 270E Flawed Flow 网络流问题

Codeforces Round #316 (Div. 2) A

[2016-04-01][codeforces][659D][Bicycle Race]

Educational Codeforces Round 7 A

Codeforces Global Round 19