Codeforces Round #676 (Div. 2)

Codeforces Round #676 (Div. 2)


A

考虑贪心:两个1显然填,两个0显然不用,一1一0随便。

#include<iostream>
#include<cstdio>
using namespace std;
int a, b;
int main()
{
	int x, T;
	scanf("%d", &T);
	while(T --)
	{
		scanf("%d %d", &a, &b);
		x =  a & b;
		printf("%lld
", (a ^ x) + (b ^ x));
	}
	return 0;
}

B

最简便的方法其实就是把住两个角。

分类 细节题。

#include<iostream>
#include<cstdio>
using namespace std;
const int N = 200 + 5;
int n;
char map[N][N];
int main()
{
	int T;
	scanf("%d", &T);
	while(T --)
	{
		scanf("%d", &n);
		for(int i = 0; i < n; ++ i) scanf("%s", map[i]);
		int cnt = 0;
		if(map[0][1] == '1') ++ cnt;
		if(map[1][0] == '1') ++ cnt;
		if(map[n - 1][n - 2] == '1') ++ cnt;
		if(map[n - 2][n - 1] == '1') ++ cnt;
		
		if(cnt == 0 || cnt == 4)
		{
			printf("2
");
			printf("%d %d
%d %d
", 1, 2, 2, 1);
		}
		else 
		{
			if(cnt == 2)
			{
				if(map[0][1] != map[1][0])
				{
					printf("2
");
					if(map[0][1] == '0') printf("%d %d
", 1, 2);
					else printf("%d %d
", 2, 1);
					if(map[n - 1][n - 2] == '1') printf("%d %d
", n, n - 1);
					else printf("%d %d
", n - 1, n);
				}
				else puts("0");
			}
			else
			{
				if(cnt == 1)
				{
					printf("1
");
					if(map[0][1] == '1') printf("%d %d
", 2, 1);
					if(map[1][0] == '1') printf("%d %d
", 1, 2);
					if(map[n - 1][n - 2] == '1') printf("%d %d
", n - 1, n);
					if(map[n - 2][n - 1] == '1') printf("%d %d
", n, n - 1);
				}
				else
				{
					printf("1
");
					if(map[0][1] == '0') printf("%d %d
", 2, 1);
					if(map[1][0] == '0') printf("%d %d
", 1, 2);
					if(map[n - 1][n - 2] == '0') printf("%d %d
", n - 1, n);
					if(map[n - 2][n - 1] == '0') pritf("%d %d
", n, n - 1);
				}
			}
		}
	}
	return 0;
}

C

构造有点奇妙,首先发现一旦中间出现回文串(奇数)就可以通过操作完成。

#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
const int SIZE = 1e5 + 5;
string s;
int n;
int main()
{
	getline(cin, s);
	n = s.size();
	printf("%d
", 5);
	printf("L %d
", n - 1);
	puts("L 2");
	printf("R %d
", n + 1);
	printf("L %d
", n * 2 - 1);
	printf("L %d
", n - 1);
	return 0;
}

D

真是一道送的题目,贪心+分类讨论细节题

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
long long x, y, c[7];
int main()
{
	int t;
	scanf("%d", &t);
	while(t --)
	{
		scanf("%lld %lld", &x, &y);
		long long ans;
		for(int i = 1; i <= 6; ++ i) scanf("%lld", &c[i]);
		if(x * y >= 0)
		{
			if(x <= 0 && y <= 0)
			{
				x = -x, y = -y;
				for(int i = 1; i <= 3; ++ i) swap(c[i], c[i + 3]);
			}
			if(x > y) 
			{
				swap(x, y), swap(c[2], c[6]), swap(c[3], c[5]);
			}
			ans = min(c[6] * x + c[2] * y, min(c[1] * x + c[2] * (y - x), c[3] * (y - x) + c[1] * y));
			printf("%lld
", ans);
		}
		else 
		{
			if(x < 0) x = -x;
			else 
			{
				y = -y;
				for(int i = 1; i <= 3; ++ i) swap(c[i], c[i + 3]);
			}
			ans = c[3] * x + c[2] * y;
			if(c[1] + c[3] < c[2]) ans = min(ans, c[3] * x + (c[1] + c[3]) * y);
			if(c[2] + c[4] < c[3]) ans = min(ans, (c[2] + c[4]) * x + c[2] * y);
			printf("%lld
", ans);
		}
	}	
	return 0;
}
原文地址:https://www.cnblogs.com/zach20040914/p/13861247.html