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

CF#316 Div.2

时间:2015-08-14 06:29:06      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

第一篇文章

额大半夜 爬起来做CF

SB题被hack之后还是错 没药救了

E题再有3分钟就调出来了

读题要认真,写题要专心QAQ

Problem A Elections

#include <cstdio>
#include <algorithm>
using namespace std;
#pragma warning (disable : 4996)

int f[101];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		int ma = -1, mai;
		for (int j = 1; j <= n; j++)
		{
			int t;
			scanf("%d", &t);
			if (ma < t)
			{
				ma = t;
				mai = j;
			}
		}
		f[mai]++;
	}
	int ma = -1, mai;
	for (int i = 1; i <= n; i++)
		if (ma < f[i])
		{
			ma = f[i];
			mai = i;
		}
	printf("%d", mai);
	return 0;
}

Problem B Simple Game

对就是这题!

#include <cstdio>
#pragma warning (disable : 4996)

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	if (m == 1 && n == 1) printf("%d", 1);
	else if (2 * m < n + 1) printf("%d", m + 1);
	else printf("%d", m - 1);
	return 0;
}

Problem C Replacement

#include <cstdio>
#pragma warning (disable : 4996)

char a[300002];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	scanf("%s", a + 1);
	int now = 0, ans = 0;
	for (int i = 1; i <= n; i++)
		if (a[i] == ‘.‘) now++;
		else if (now >= 1) 
		{
			ans += now - 1;
			now = 0;
		}
	if (now > 1) ans += now - 1;
	for (int i = 1; i <= m; i++)
	{
		int x;
		char c;
		scanf("%d %c", &x, &c);
		if (a[x] == c || (a[x] != ‘.‘&&c != ‘.‘));
		else if (c == ‘.‘)
		{
			if ((a[x - 1] != ‘.‘) && (a[x + 1] != ‘.‘));
			else if ((a[x - 1] == ‘.‘) ^ (a[x + 1] == ‘.‘)) ans += 1;
			else ans += 2;
		}
		else
		{
			if ((a[x - 1] != ‘.‘) && (a[x + 1] != ‘.‘));
			else if ((a[x - 1] == ‘.‘) ^ (a[x + 1] == ‘.‘)) ans -= 1;
			else ans -= 2;
		}
		printf("%d\n", ans);
		a[x] = c;
	}
	return 0;
}

Problem E Pig and Palindromes

#include <cstdio>
#include <cstring>
using namespace std;
#pragma warning (disable : 4996)

#define mod 1000000007
char a[501][501];
int f[2][501][501];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%s", a[i] + 1);
	f[0][1][1] = a[1][1] == a[n][m];
	for (int i = 3; i <= ((n + m) >> 1) + 1; i++)
	{
		bool o = i & 1;
		memset(f[o], 0, sizeof f[o]);
		for (int j = 1; j < i&&j <= n; j++)
			if (i - j <= m)
				for (int k = 1; k < i&&k <= n; k++)
					if (i - k <= m)
					{
						int x1 = j, y1 = i - j, x2 = n + 1 - k, y2 = m + 1 - i + k;
						if (a[x1][y1] == a[x2][y2])
						{
							if (x1 > 1)
							{
								if (x2 < n) f[o][j][k] = (f[o][j][k] + f[!o][x1 - 1][n - x2]) % mod;
								if (y2 < m) f[o][j][k] = (f[o][j][k] + f[!o][x1 - 1][n - x2 + 1]) % mod;
							}
							if (y1 > 1)
							{
								if (x2 < n) f[o][j][k] = (f[o][j][k] + f[!o][x1][n - x2]) % mod;
								if (y2 < m) f[o][j][k] = (f[o][j][k] + f[!o][x1][n - x2 + 1]) % mod;
							}
						}
					}
	}
	int ans = 0;
	if ((n + m) & 1)
	{
		int i = ((n + m) >> 1) + 1;
		bool o = i & 1;
		for (int j = 1; j < i&&j <= n; j++)
			if (i - j <= m)
			{
				int x1 = j, y1 = i - j;
				if (x1 < n)
					ans = (ans + f[o][j][n - x1]) % mod;
				if (y1 < m)
					ans = (ans + f[o][j][n - x1 + 1]) % mod;
			}
	}
	else
	{
		int i = ((n + m) >> 1) + 1;
		bool o = i & 1;
		for (int j = 1; j < i&&j <= n; j++)
			if (i - j <= m)
				ans = (ans + f[o][j][n + 1 - j]) % mod;
	}
	printf("%d", ans);
	return 0;
}

又臭又长 滚动数组

碎觉去了

还有一题明天上课写

CF#316 Div.2

标签:

原文地址:http://www.cnblogs.com/liyh98/p/4728874.html

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