Codeforces Round #796 (Div. 2)

C. Manipulating History

题意:初始只有一个字母 X X X
给一系列的变换规则(都用且只用一次,每次用只能变一个地方):

  • 子串1 -> 子串2
  • 子串3 -> 子串4
  • 子串i -> 子串j

再给出最终的串 Y Y Y

问最开始的字母 X X X是什么。

思路:将所有的变换规则串: 子 串 1 , 子 串 2 , 子 串 3 , 子 串 4 , . . . , 子 串 i , 子 串 j 子串1, 子串2,子串3,子串4,...,子串i,子串j 1234...ij和最终串 Y Y Y.
奇数的字母即为答案。

因为每次变换都会给出一对串,将初始字母所有变换规则的串最终串叠加在一起会发现:只有初始字母出现奇数次

// Problem: C. Manipulating History
// Contest: Codeforces - Codeforces Round #796 (Div. 2)
// URL: https://codeforces.com/contest/1688/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

/*
author: A Fei
*/ 
#include <bits/stdc++.h>

#define x first
#define y second
#define pi acos(-1) 
#define endl '\n'
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pb(x) push_back(x)
#define rep(i, l, r) for(int i = l; i <= (r); ++ i)
#define per(i, r, l) for(int i = r; i >= (l); -- i)

using namespace std;
typedef long long LL;
typedef double DB;
typedef pair<int, int> PII;
typedef pair<int, double> PID;
typedef pair<double, double> PDD;
template <typename T> void inline read(T &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}

int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
const int INF = 0x3f3f3f3f;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


int main()
{
    int tt;
    cin >> tt;
    while(tt --)
    {
    	int n;
    	cin >> n;
    	char ans = 0;
    	string s;
    	rep(i, 1, 2 * n)
    	{
    		cin >> s;
    		for(auto x : s) ans ^= x;
    	}
    	cin >> s;
    	for(auto x : s) ans ^= x;
    	cout << ans << endl;
    }
    
    
    
    
    return 0;
}
 

D. The Enchanted Forest

题意:
给定一个整数序列(长度为n),可选在任意位置开始。
进行 K K K步操作(每步操作按顺序分三个步骤):

  • 选择向左一步 or 向右一步 or 不动
  • 拿起该位置的数字,该位置变为0
  • 每个位置+1

问: K K K步之后,能拿到最大的数字之和。

思路:
初始数列和随时间的增量分开考虑。
K < = n K <= n K<=n

初始数列长度为 K K K连续区间最大值 + (1 ~ k − 1 k-1 k1)的等差数列

K > n K > n K>n

  • 初始序列:能拿完
  • 增量:在左(右)端点不动,剩n步时,向右(左)走;增量为:( K − n K - n Kn~ K − 1 K-1 K1)的等差数列。
// Problem: D. The Enchanted Forest
// Contest: Codeforces - Codeforces Round #796 (Div. 2)
// URL: https://codeforces.com/contest/1688/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

/*
author: A Fei
*/ 
#include <bits/stdc++.h>

#define x first
#define y second
#define pi acos(-1) 
#define endl '\n'
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pb(x) push_back(x)
#define rep(i, l, r) for(int i = l; i <= (r); ++ i)
#define per(i, r, l) for(int i = r; i >= (l); -- i)

using namespace std;
typedef long long LL;
typedef double DB;
typedef pair<int, int> PII;
typedef pair<int, double> PID;
typedef pair<double, double> PDD;
template <typename T> void inline read(T &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}

int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
const int INF = 0x3f3f3f3f;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const int N = 2e5 + 10;
int a[N];
LL s[N];
int n, k;

int main()
{
    ios;
    int tt;
    cin >> tt;
    while(tt --)
    {
    	cin >> n >> k;
    	rep(i, 1, n) cin >> a[i];
    	rep(i, 1, n) s[i] = s[i - 1] + a[i];
    	
    	LL ans = 0;
    	if(k <= n)
    	{
    		rep(i, k, n) ans = max(ans, s[i] - s[i - k]);
    		ans += 1ll * k * (k - 1) / 2;
    	}
    	else 
    	{
    		// ans = s[n];
    		// for (int i = 1; i <= n; i++)ans += k - i;
    		ans = s[n] + 1ll * n * (2 * k - n - 1) / 2;
    	}
    	
    	cout << ans << endl;
    }
    
    
    
    
    return 0;
}

E. Railway System

额不会交互题,呜呜呜。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值