Codeforces Round #706 (Div. 2)

A. Split it!
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Kawashiro Nitori is a girl who loves competitive programming.

One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem.

Given a string s and a parameter k, you need to check if there exist k+1 non-empty strings a1,a2…,ak+1, such that
s=a1+a2+…+ak+ak+1+R(ak)+R(ak−1)+…+R(a1).
Here + represents concatenation. We define R(x) as a reversed string x. For example R(abcd)=dcba. Note that in the formula above the part R(ak+1) is intentionally skipped.

Input
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.

The first line of each test case description contains two integers n, k (1≤n≤100, 0≤k≤⌊n2⌋) — the length of the string s and the parameter k.

The second line of each test case description contains a single string s of length n, consisting of lowercase English letters.

Output
For each test case, print “YES” (without quotes), if it is possible to find a1,a2,…,ak+1, and “NO” (without quotes) otherwise.

You can print letters in any case (upper or lower).

Example
inputCopy
7
5 1
qwqwq
2 1
ab
3 1
ioi
4 2
icpc
22 0
dokidokiliteratureclub
19 8
imteamshanghaialice
6 3
aaaaaa
outputCopy
YES
NO
YES
NO
YES
NO
NO
Note
In the first test case, one possible solution is a1=qw and a2=q.

In the third test case, one possible solution is a1=i and a2=o.

In the fifth test case, one possible solution is a1=dokidokiliteratureclub.

题意:给你一长度为n的字符串s和一个k,求在s的基础上能否求出一个长度为2*k+1的字符串t,且t满足a1+a2+…+ak+ak+1+R(ak)+…+R(a2)+R(a1),R(ai)代表是ai的反串
思路:从两边开始判断有多少个相等的字符 如果个数大于等于k则可以

//将长度为n分为2k+1份,所以n必须大于等于2k+1
//整个字符串为ABC三个部分,A和C对称,将A和C细分,各大于等于k个字符
#include <bits/stdc++.h>
using namespace std;
void solve(){
	int n, k;
	string s;
	cin >> n >> k >> s;
	if (n < 2 * k + 1) {
		cout << "NO" << endl;
		return ;
	}
	for (int i = 0; i < k ; i++) {
		if (s[s.size() - i - 1] != s[i]){
			cout << "NO" << endl;
			return ;
		}
	}
	cout << "YES" << endl;
	return ;
}
int main(){
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


或者

int n=read(),k=read();
        scanf("%s",a+1);int cnt=0;
        for(int i=1;i<=n/2;i++)
        {
            if(a[i]==a[n-i+1])cnt++;
            else break;
        }
        if(cnt>=k&&(cnt*2!=n||cnt>k))puts("YES");
        else puts("NO");

B. Max and Mex
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a multiset S initially consisting of n distinct non-negative integers. A multiset is a set, that can contain some elements multiple times.

You will perform the following operation k times:

Add the element ⌈a+b2⌉ (rounded up) into S, where a=mex(S) and b=max(S). If this number is already in the set, it is added again.
Here max of a multiset denotes the maximum integer in the multiset, and mex of a multiset denotes the smallest non-negative integer that is not present in the multiset. For example:

mex({1,4,0,2})=3;
mex({2,5,1})=0.
Your task is to calculate the number of distinct elements in S after k operations will be done.

Input
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers n, k (1≤n≤105, 0≤k≤109) — the initial size of the multiset S and how many operations you need to perform.

The second line of each test case contains n distinct integers a1,a2,…,an (0≤ai≤109) — the numbers in the initial multiset.

It is guaranteed that the sum of n over all test cases does not exceed 105.

Output
For each test case, print the number of distinct elements in S after k operations will be done.

Example
inputCopy
5
4 1
0 1 3 4
3 1
0 1 4
3 0
0 1 4
3 2
0 1 2
3 2
1 2 3
outputCopy
4
4
3
5
3
Note
In the first test case, S={0,1,3,4}, a=mex(S)=2, b=max(S)=4, ⌈a+b2⌉=3. So 3 is added into S, and S becomes {0,1,3,3,4}. The answer is 4.

In the second test case, S={0,1,4}, a=mex(S)=2, b=max(S)=4, ⌈a+b2⌉=3. So 3 is added into S, and S becomes {0,1,3,4}. The answer is 4.

//mex如果大于n,每次op都会种类加一,考虑四舍五入性质
//mex如果小于n,计算式子值,如果在原有中出现过,则不会再变化,若没有,则加一后不再变化
#include <bits/stdc++.h>
using namespace std;
void solve(){
	int n, k;
	cin >> n >> k;
	int mex = 0, mx = 0;
	vector<int>ve;
	set<int>se;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		ve.push_back(x);
		se.insert(x);
		if (x > mx) mx = x;
	}
	if (k == 0) {
		cout << n << endl;
		return ;
	}
	sort(ve.begin(), ve.end());
	for (int i = 0; i < ve.size(); i++) {
		if (ve[i] == mex) mex++;
	}
	if (mex > mx) {
		cout << n + k << endl;
		return ;
	}
	int ans = (int)((mex + mx) / 2.0 + 0.5);
	if (se.find(ans) != se.end()) cout << n << endl;
	else cout << n + 1 << endl;
	return ;
}
int main(){
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


C. Diamond Miner
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Diamond Miner is a game that is similar to Gold Miner, but there are n miners instead of 1 in this game.

The mining area can be described as a plane. The n miners can be regarded as n points on the y-axis. There are n diamond mines in the mining area. We can regard them as n points on the x-axis. For some reason, no miners or diamond mines can be at the origin (point (0,0)).

Every miner should mine exactly one diamond mine. Every miner has a hook, which can be used to mine a diamond mine. If a miner at the point (a,b) uses his hook to mine a diamond mine at the point (c,d), he will spend (a−c)2+(b−d)2−−−−−−−−−−−−−−−√ energy to mine it (the distance between these points). The miners can’t move or help each other.

The object of this game is to minimize the sum of the energy that miners spend. Can you find this minimum?

Input
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤10) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤105) — the number of miners and mines.

Each of the next 2n lines contains two space-separated integers x (−108≤x≤108) and y (−108≤y≤108), which represent the point (x,y) to describe a miner’s or a diamond mine’s position. Either x=0, meaning there is a miner at the point (0,y), or y=0, meaning there is a diamond mine at the point (x,0). There can be multiple miners or diamond mines at the same point.

It is guaranteed that no point is at the origin. It is guaranteed that the number of points on the x-axis is equal to n and the number of points on the y-axis is equal to n.

It’s guaranteed that the sum of n for all test cases does not exceed 105.

Output
For each test case, print a single real number — the minimal sum of energy that should be spent.

Your answer is considered correct if its absolute or relative error does not exceed 10−9.

Formally, let your answer be a, and the jury’s answer be b. Your answer is accepted if and only if |a−b|max(1,|b|)≤10−9.

Example
inputCopy
3
2
0 1
1 0
0 -1
-2 0
4
1 0
3 0
-5 0
6 0
0 3
0 1
0 2
0 4
5
3 0
0 4
0 -3
4 0
2 0
1 0
-3 0
0 -10
0 -2
0 -10
outputCopy
3.650281539872885
18.061819283610362
32.052255376143336
Note
In the first test case, the miners are at (0,1) and (0,−1), while the diamond mines are at (1,0) and (−2,0). If you arrange the miners to get the diamond mines in the way, shown in the picture, you can get the sum of the energy 2–√+5–√.

//vector类型必须为double,如果int则ans计算过程会溢出,但xx类型又必须int,否则输入会超时
//靠在垂直墙和地板的两根木板,不交叉,长度之和才最小
#include "bits/stdc++.h"
using namespace std;

int main(){
	int t;
	cin >> t;
	while (t--) {
		vector<double>x, y;
		int n;
		cin >> n;
		for (int i = 1; i <= 2 * n; i++) {
			int xx, yy;
			cin >> xx >> yy;
			xx = abs(xx);
			yy = abs(yy);
			if (xx == 0) y.push_back(yy);
			else x.push_back(xx);
		}
		double ans = 0;
		sort(x.begin(), x.end());
		sort(y.begin(), y.end());
		for (int i = 0; i < x.size(); i++) {
			ans += sqrt(x[i] * x[i] + y[i] * y[i]);
		}
		printf("%.14lf\n", ans);
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值