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

CF1332 Solution

时间:2020-04-02 11:48:14      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:cout   spl   inline   continue   return   div   ase   ems   ring   

前言

出题人:用心出题目, 用脚造数据。 C pretest竟然没有极限数据导致我fst了,好气啊。

正文

AB就不讲了。

C. K-Complete Word

考虑回文位和 \(i + k\) 位和 \(i\) 位要相同,把所有要求相同的一起找出来全部变成最多的那个就好了。

#include<bits/stdc++.h>
 
using namespace std;
 
#define N 200005
 
int T, n, k, cnt[27]; 
 
string s;
 
bool vis[N];
 
int main()
{
	ios::sync_with_stdio(false);
	cin >> T;
	while(T--)
	{
		int ans = 0;
		cin >> n >> k;
		for(int i = 0; i <= n; i++) vis[i] = 0;
		cin >> s;
		for(int i = 0; i < n; i++)
		{
			if(vis[i]) continue;
			memset(cnt, 0, sizeof(cnt));
			int j = i, num = 0;
			while(j < n) 
			{
				if(!vis[j]) cnt[s[j] - ‘a‘]++, num++;
				vis[j] = 1;
				int x = n - j - 1;
				if(!vis[x]) cnt[s[x] - ‘a‘]++, num++;
				vis[x] = 1;
				j += k;
			}
			int tmp = 0;
			for(int i = 0; i < 26; i++) tmp = max(tmp, cnt[i]);
			ans += num - tmp;
		}
		printf("%d\n", ans);
	}
	return 0;
}

D. Walk on Matrix

考虑构造,让Bob答案为0,最佳答案为 \(k\) 即可。

#include<bits/stdc++.h>
 
using namespace std;
 
int k, limit = 1, l = 0, all = (1 << 18) - 1, x = (1 << 17);
 
int main()
{
	cin >> k;
	cout << 3 << ‘ ‘ << 3 << endl;
	cout << all << ‘ ‘ << all << ‘ ‘ << k << endl;
	cout << all << ‘ ‘ << x << ‘ ‘ << x + k << endl;
	cout << k << ‘ ‘ << x + k << ‘ ‘ << k << endl;
	return 0;
}

E. Height All the Same

首先通过2操作我们可以发现直接把所有数 \(mod 2\) 一定是可以的。那么我们现在只需要考虑只有 \(0、1\) 的矩阵

Case1. (n & 1) && (m & 1)
\(sum\) 奇偶讨论一下可以发现无论怎样一定有解。

Case2. !((n & 1) && (m & 1)) && (sum & 1)

由于操作不能改变 \(sum\) 的奇偶性,那么可以发现无解。

Case3. !(sum & 1)

此时一定可以通过一些1和2操作来同时改变两个1的值。所以此时有解。
我们定义\(x, y\) 分别为 \(L, R\) 中偶数,奇数的数量。我们要求

\[\sum_{i = 0}^{\frac{nm}{2}}{x^{nm - 2i} \times y^{2i} \times C_{nm}^{2i}} (x + y)^{nm} = \sum_{i = 0}^{\frac{nm}{2}}{x^{nm - 2i} \times y^{2i} \times C_{nm}^{2i}} + \sum_{i = 1}^{\frac{nm}{2}}{x^{nm - 2i - 1} \times y^{2i - 1} \times C _{nm}^{2i - 1}} (y - x)^{nm} = \sum_{i = 0}^{\frac{nm}{2}}{x^{nm - 2i} \times y^{2i} \times C_{nm}^{2i}} - \sum_{i = 1}^{\frac{nm}{2}}{x^{nm - 2i - 1} \times y^{2i - 1} \times C _{nm}^{2i - 1}} \]

所以快速幂一下就出来了

#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
#define N 250005
const int mod = 998244353;
#define add(x, y) (x + y >= mod ? x + y - mod : x + y)
#define dec(x, y) (x < y ? x - y + mod : x - y)
 
ll Pow(ll x, ll k)
{
	ll ans = 1, base = x;
	while(k)
	{
		if(k & 1) ans = 1ll * ans * base % mod;
		base = 1ll * base * base % mod;
		k >>= 1;
	}
	return ans;
}
 
ll n, m, L, R;
 
int main()
{
	cin >> n >> m >> L >> R;
	if((n % 2) && (m % 2))
	{
		printf("%lld\n", Pow(R - L + 1, n * m));
	}
	else
	{
		ll x = 0, y = 0;
		if(L & 1) y++, L++;
		if((R & 1) && L <= R - 1) y++, R--;
		if(L <= R)
		{
			x += (R - L) / 2 + 1;
			y += R - L + 1 - x;
		}
		cout << (Pow(2, mod - 2) * (Pow(x + y, n * m) + Pow(y - x, n * m)) % mod + mod) % mod << endl;
	}
	return 0;
}

CF1332 Solution

标签:cout   spl   inline   continue   return   div   ase   ems   ring   

原文地址:https://www.cnblogs.com/LJB00131/p/12618498.html

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