Educational Codeforces Round 148 (Rated for Div. 2)(A~E)

Educational Codeforces Round 148 (Rated for Div. 2)

New Palindrome

题意:

给你一个回文串,长度不超过50,问能不能重新排列出一个新的回文串。如果可以输出YES,否则输出NO。

思路:

直接找有没有不同的对,有就输出YES。因为不同的对可以调换位置。

代码:

#include<iostream>
#include<queue>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<map>
#include<algorithm>
#include<deque>
#include<stack>
#include<set>
#include <unordered_map>
#include<math.h>
#include<string.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;

#define pb push_back
#define coutl cout<<"------------"<<endl;
#define fi first
#define se second

#define ire(x) scanf("%d",&x)
#define iire(a,b) scanf("%d %d",&a,&b)
#define lre(x) scanf("%lld",&x)
#define llre(a,b) scanf("%lld %lld",&a,&b)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define endl "\n"
#define PI acos(-1.0)

#define int long long

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> PII;
typedef pair<double, int> PDI;
typedef pair<ll, ll> PLL;
typedef pair<double, double> PDD;
typedef pair<double, pair<int, double> > PDID;
typedef pair<char, char> PCC;
typedef pair<char, pair<int, int> > PCII;
typedef pair<int, pair<int, int> > PIII;
typedef pair<int, pair<int, pair<int, int> > > PIIII;
typedef pair<ll, pair<int, int> > PLII;

const int maxn = 3e5 + 7;
const int N = 1e6 + 7;
const int M = 1e6 + 7;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1);
const double eps = 1e-8;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll qmi(ll a, ll b, ll p) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % p; a = a * a % p; b >>= 1; } return ans; }
int lowbit(int x) { return x & (-x); }

string s;

void solve() {
	cin >> s;
	int n = s.size();
	s = " " + s;
	n /= 2;
	for (int i = 2; i <= n; i++) {
		if (s[i] != s[i - 1]) {
			cout << "YES" << endl;
			return;
		}
	}
	cout << "NO" << endl;
}

signed main() {
	IOS;
	int t = 1;
	cin >> t;
	while (t--)	solve();
}

Maximum Sum

题意:

个一个数组,有两种操作,删掉最小的两个数或者删掉最大的一个数,问操作k次后,数组的和最大是多少。n<=2e5,k<n/2,k<99999。

思路:

有三种删除方法

  • 全部删最大
  • 全部删最小
  • 删一部分最小,删一部分最大,枚举分界点就行了。

代码:

#include<iostream>
#include<queue>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<map>
#include<algorithm>
#include<deque>
#include<stack>
#include<set>
#include <unordered_map>
#include<math.h>
#include<string.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;

#define pb push_back
#define coutl cout<<"------------"<<endl;
#define fi first
#define se second

#define ire(x) scanf("%d",&x)
#define iire(a,b) scanf("%d %d",&a,&b)
#define lre(x) scanf("%lld",&x)
#define llre(a,b) scanf("%lld %lld",&a,&b)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define endl "\n"
#define PI acos(-1.0)

#define int long long

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> PII;
typedef pair<double, int> PDI;
typedef pair<ll, ll> PLL;
typedef pair<double, double> PDD;
typedef pair<double, pair<int, double> > PDID;
typedef pair<char, char> PCC;
typedef pair<char, pair<int, int> > PCII;
typedef pair<int, pair<int, int> > PIII;
typedef pair<int, pair<int, pair<int, int> > > PIIII;
typedef pair<ll, pair<int, int> > PLII;

const int maxn = 3e5 + 7;
const int N = 1e6 + 7;
const int M = 1e6 + 7;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1);
const double eps = 1e-8;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll qmi(ll a, ll b, ll p) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % p; a = a * a % p; b >>= 1; } return ans; }
int lowbit(int x) { return x & (-x); }

int n, k;
int a[maxn];
int sum[maxn];
int ne[maxn];

void solve() {
	cin >> n >> k;
	int ans = 0;
	for (int i = 1; i <= n; i++)	cin >> a[i], ans += a[i];
	sort(a + 1, a + n + 1);
	int ans1 = ans, ans2 = ans;
	ne[n + 1] = 0;
	int num = ans;
	ans = 0;
	for (int i = n; i >= 1; i--)	ne[i] = ne[i + 1] + a[i];
	for (int i = 1; i <= n; i++)	sum[i] = sum[i - 1] + a[i];
	for (int i = 1; i <= n; i+= 2) {
		if((i+1)/2<=k)	ans = max(num - sum[i + 1] - ne[n - (k - (i + 1) / 2) + 1], ans);
	}
	for (int i = n; i > n - k; i--)	ans1 -= a[i];
	for (int i = 1; i <= n; i += 2)	ans2 -= (a[i] + a[i + 1]);
	ans = max({ ans, ans1, ans2 });
	cout << ans << endl;
}

signed main() {
	IOS;
	int t = 1;
	cin >> t;
	while (t--)	solve();
}

Contrast Value

题意:

给一个数组,它的价值是|a[1]-a[2]|+|a[2]-a[3]|+…,要找到也个最短的且价值与a相等的子序列。输出子序列的长度。

思路:

可以发现,单调的一个串中间的部分都是多余的,可以删除。比如1,2,3.它的贡献是2,把中间的2删掉之后还是2.所以只要把所有单调子串中间的部分去掉即可。具体看代码。

代码:

#include<iostream>
#include<queue>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<map>
#include<algorithm>
#include<deque>
#include<stack>
#include<set>
#include <unordered_map>
#include<math.h>
#include<string.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;

#define pb push_back
#define coutl cout<<"------------"<<endl;
#define fi first
#define se second

#define ire(x) scanf("%d",&x)
#define iire(a,b) scanf("%d %d",&a,&b)
#define lre(x) scanf("%lld",&x)
#define llre(a,b) scanf("%lld %lld",&a,&b)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define endl "\n"
#define PI acos(-1.0)

#define int long long

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> PII;
typedef pair<double, int> PDI;
typedef pair<ll, ll> PLL;
typedef pair<double, double> PDD;
typedef pair<double, pair<int, double> > PDID;
typedef pair<char, char> PCC;
typedef pair<char, pair<int, int> > PCII;
typedef pair<int, pair<int, int> > PIII;
typedef pair<int, pair<int, pair<int, int> > > PIIII;
typedef pair<ll, pair<int, int> > PLII;

const int maxn = 3e5 + 7;
const int N = 1e6 + 7;
const int M = 1e6 + 7;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1);
const double eps = 1e-8;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll qmi(ll a, ll b, ll p) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % p; a = a * a % p; b >>= 1; } return ans; }
int lowbit(int x) { return x & (-x); }

int n;
int sum[maxn];
int a[maxn];
int b[maxn];

void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++)	cin >> b[i];
	a[1] = b[1];
	int cnt = 1;
	for (int i = 2; i <= n; i++)
		if (b[i] != b[i - 1])
			a[++cnt] = b[i];
	n = cnt;
	for (int i = 1; i <= n - 1; i++)
		sum[i] = sum[i - 1] + abs(a[i] - a[i + 1]);
	if (sum[n - 1] == 0) {
		cout << 1 << endl;
		return;
	}
	int ans = 2;
	for (int i = 1; i <= n; i++) {
		if (i + 2 <= n) {
			if (a[i] < a[i + 1] && a[i + 1] > a[i + 2])	ans++;
			if (a[i] > a[i + 1] && a[i + 1] < a[i + 2])	ans++;
		}
	}
	cout << ans << endl;
}

signed main() {
	IOS;
	int t = 1;
	cin >> t;
	while (t--)	solve();
}

Red-Blue Operations (Hard Version)

题意:给一个数组,有q组操作,每组操作ki次,问操作完后数组中最小数最大是多少,n,q<=2e5。每次操作过程如下:

设当前操作次数为cnt;
选一个数,如果它是红色,则+cnt,如果是蓝色,则-cnt,
然后cnt++,如果当前是红色,变成蓝色,否则变成红色。

思路:

如果k小于n就直接加,如果k大于n就把加放在后面,后面全部加,前面的分组每一组为+cnt,-(cnt+1)如果k-n是偶数,那就要减(k-n)/2,如果是奇数,就减(k-n+1)/2。
具体看代码。

代码:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#define int long long
#define endl '\n'

using namespace std;

const int maxn = 3e5 + 7;
const int inf = 1e18;

int n, q, a[maxn];

signed main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> q;
	int sum = 0;
	for(int i = 1; i <= n; i ++ )	cin >> a[i], sum += a[i];
	sort(a + 1, a + n + 1);
	vector<int> f(n + 2, inf);
	for(int i = 1; i <= n; i ++ )
		f[i + 1] = min(f[i], a[i]) + 1;
	while(q -- ){
		int k;
		cin >> k;
		if(k < n){
			cout << min(f[k + 1], a[k + 1]) << ' ';
		}
		else {
			int ans = 0;
			int s = sum;
			if((k - n) % 2 == 0){
				ans = f[n + 1] + k - n;
				s += n * (k + k - n + 1) / 2 - (k - n) / 2;
			}
			else {
				ans = min(f[n] + k - n + 1, a[n]);
				s += (n - 1) * (k + k - n + 2) / 2 - (k - n + 1) / 2;
			}
			cout << min(ans, s / n) << ' ';
		}
	}
	cout << endl;
}

Combinatorics Problem

题意:点上面的链接吧,都是公式,不好表达

o(〃‘▽’〃)o

思路:

首先可以发现,因为C(x, y),如果x 小于 y就没意义,所以b[k]以前的数都没意义,最后只要求b[k~n]的异或和就行了。
令f[i][j]表示当k等于i是,b中符合条件的第j个数字

f[i][j]=C(i+j-1,i)*a[1]+…+C(i,i)*a[j];
f[i][j-1]=C(i+j-2,i)*a[1]+…+C(i,i)*a[j-1];
f[i-1][j]=C(i+j-2,i-1)*a[1]+…+C(i-1,i-1)*a[j];

由组合数的递推式C(n,m)=C(n-1,m-1)+C(n-1,m)可以推出公式:f[i][j]=f[i-1][j]+f[i][j-1]

代码:

#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
#define endl '\n'

using namespace std;

const int mod = 998244353;
const int maxn = 1e7 + 7;

int n, x, y, m, k;

signed main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	vector<int> a(n + 1);
	cin >> a[1];
	cin >> x >> y >> m >> k;
	for(int i = 2; i <= n; i ++ )
		a[i] = (a[i - 1] * x + y) % m;
	vector<vector<int>> f(k + 1, vector<int>(n + 1, 0));
	for(int i = 1; i <= n; i ++ )
		f[0][i] = f[0][i - 1] + a[i];
	for(int i = 1; i <= k; i ++ ){
		f[i][1] = a[1];
		for(int j = 2; j <= n; j ++ ){
			f[i][j] = (f[i][j - 1] + f[i - 1][j]) % mod;
		}
	}
	int ans = 0;
	for(int i = 1; i <= (n - k + 1); i ++ )
		ans ^= ((k + i - 1) * f[k][i]);
	cout << ans << endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法和数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来说是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来说,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

方哲Beans

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值