Codeforces Round #341 (Div. 2)

 

在家都变的懒惰了,好久没写题解了,补补CF

 

模拟 A - Wet Shark and Odd and Even

#include <bits/stdc++.h>

typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int main(void)	{
	std::vector<int> vec;
	int n;	scanf ("%d", &n);
	ll sum = 0;
	for (int x, i=1; i<=n; ++i)	{
		scanf ("%d", &x);
		sum += x;
		if (x & 1)	vec.push_back (x);
	}
	std::sort (vec.begin (), vec.end ());
	int sz = vec.size ();
	if (sz > 0 && (sz & 1))	sum -= vec[0];
	printf ("%I64d\n", sum);

	return 0;
}

 

暴力 B - Wet Shark and Bishops

开始想错了,当成斜率相等的。还好1000范围不大,统计矩阵每条对角线上的个数加点小优化就过了,代码丑。。。

#include <bits/stdc++.h>

typedef long long ll;
const int N = 2e5 + 5;
bool vis[2][1005][1005];
int b[1005][1005];
std::pair<int, int> a[N];

ll cal(int x)	{
	return 1ll * x * (x - 1) / 2;
}
int get_num1(int x, int y)	{
	int xx = x, yy = y;
	int ret = 0;
	while (xx >= 1 && yy >= 1)	{
		if (b[xx][yy])	ret++, vis[1][xx][yy] = true;
		xx--;	yy--;
	}
	xx = x + 1, yy = y + 1;
	while (xx <= 1000 && yy <= 1000)	{
		if (b[xx][yy])	ret++, vis[1][xx][yy] = true;
		xx++;	yy++;
	}
	return ret;
}

int get_num0(int x, int y)	{
	int xx = x, yy = y;
	int ret = 0;
	while (xx <= 1000 && yy >= 1)	{
		if (b[xx][yy])	ret++, vis[0][xx][yy] = true;
		xx++;	yy--;
	}
	xx = x - 1, yy = y + 1;
	while (xx >= 1 && yy <= 1000)	{
		if (b[xx][yy])	ret++, vis[0][xx][yy] = true;
		xx--;	yy++;
	}
	return ret;
}

int main(void)	{
	int n;	scanf ("%d", &n);
	for (int i=0; i<n; ++i)	{
		scanf ("%d%d", &a[i].first, &a[i].second);
		b[a[i].first][a[i].second] = 1;
	}
	ll ans = 0;
	for (int i=0; i<n; ++i)	{
		int x = a[i].first, y = a[i].second;
		if (!vis[0][x][y])	{
			ans += cal (get_num0 (x, y));
			vis[0][x][y] = true;
		}
		if (!vis[1][x][y])	{
			ans += cal (get_num1 (x, y));
			vis[1][x][y] = true;
		}
	}
	printf ("%I64d\n", ans);

	return 0;
}

 

期望 C - Wet Shark and Flowers

E = sum (1000 * 乘积是p的倍数的概率)

#include <bits/stdc++.h>

typedef long long ll;
const int N = 1e5 + 5;
const int EPS = 1e-8;
int l[N], r[N];
double pos[N];

int main(void)	{
	int n, p;	scanf ("%d%d", &n, &p);
	for (int i=1; i<=n; ++i)	{
		scanf ("%d%d", &l[i], &r[i]);
		pos[i] = 1.0 * (r[i] / p - ((l[i]-1) / p)) / (r[i] - l[i] + 1);
	}
	l[0] = l[n], r[0] = r[n], pos[0] = pos[n];
	double ans = 0;
	for (int i=0; i<=n; ++i)	{
		if (i < n)	ans += pos[i] * 1.0 + (1.0 - pos[i]) * pos[i+1];
		if (i > 0)	ans += pos[i] * 1.0 + (1.0 - pos[i]) * pos[i-1];
	}
	ans *= 1000;
	printf ("%.8f\n", ans);

	return 0;
}

 

数学(浮点) D - Rat Kwesh and Cheese

都取log,用long double,精度逆天!powl (): pow的long double版

#include <bits/stdc++.h>

std::string ans[12] = {
"x^y^z", "x^z^y", "(x^y)^z", "(x^z)^y", "y^x^z", "y^z^x",
"(y^x)^z", "(y^z)^x", "z^x^y", "z^y^x", "(z^x)^y", "(z^y)^x"
};

typedef long double ldouble;
const double EPS = 1e-10;
ldouble best;
int id;

bool better(ldouble val)	{
	if (fabs (val - best) < EPS)	return false;
	else if (best < val)	{
		best = val;
		return true;
	}
	return false;
}

void try2(ldouble x, ldouble y, ldouble z, int pos)	{
	//(x ^ y) ^ z
	ldouble val = z * y * log (x);
	if (better (val))	id = pos;
}

void try1(ldouble x, ldouble y, ldouble z, int pos)	{
	//x ^ y ^ z
	ldouble val = powl (y, z) * log (x);
	if (better (val))	id = pos;
}

int main(void)	{
	ldouble x, y, z;	std::cin >> x >> y >> z;
	best = -1e12;	id = -1;
	try1 (x, y, z, 0);
	try1 (x, z, y, 1);
	try2 (x, y, z, 2);
	try2 (x, z, y, 3);
	try1 (y, x, z, 4);
	try1 (y, z, x, 5);
	try2 (y, x, z, 6);
	try2 (y, z, x, 7);
	try1 (z, x, y, 8);
	try1 (z, y, x, 9);
	try2 (z, x, y, 10);
	try2 (z, y, x, 11);
	std::cout << ans[id] << '\n';

	return 0;
}

 

你可能感兴趣的:(Codeforces Round #341 (Div. 2))