Codeforces Round #706 (Div. 2)A--C

传送门

A. Split it!

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.

注意特判

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e8;
const int N=2*1e2+5;//?????????? 4e8
int n,m;
char s[N];
void solve()
{
	int ans=0;
	scanf("%d%d%s",&n,&m,s+1);
	int l=1,r=n;
	while(l<r)
	{
		if(s[l]!=s[r])  break;
		ans++;
		l++;r--;
	}
	if(ans>m||(l<=r&&ans==m))  puts("YES");
	else  puts("NO");
} 
signed main()
{
	int T;
	cin>>T;
    while(T--)  solve();
    return 0;
}

B. Max and Mex

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.

太坑了,太坑了,一直以为是一个有序的集合,结果还要离散化,害我WA了7发,分数跌了近一半

//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e8;
const int N=2*1e6+5;//?????????? 4e8
int n,m;
int a[N];
map < int , int > mp;
void solve()
{
	int cnt=0,ans=0,ret=0,flag=0,res=0;
	scanf("%d%d",&n,&m);
	mp.clear();
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	n=unique(a+1,a+n+1)-(a+1);
	for(int i=1;i<=n;i++)
	{
		if(!mp[a[i]])  ret++,mp[a[i]]=1;
		if(i==1&&a[i])  res=i;
		if(i!=1&&a[i]!=a[i-1]+1&&!res)  flag=a[i-1]+1,res=i;
	}
	if(m==0)
	{
		printf("%d\n",ret);
		return;
	}
	if(a[n]==n-1&&!res)
	{
		printf("%d\n",m+ret);
		return;
	}
	if((flag+a[n])&1)  flag++;
	if(!mp[(flag+a[n])/2]&&(flag+a[n])/2!=0)  ret++;
	printf("%d\n",ret);
}
signed main()
{
	int T;
	cin>>T;
    while(T--)  solve();
    return 0;
}

C. Diamond Miner

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–√.

有一说一,可不可以不要这么坑QWQ,不是说要精确到10-9吗?,结果要精确到10-15,害我又WA一发

#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
using namespace std;
const int p=1e9+7;
const int M=2e3+5;
const int N=2*1e6+5;//?????????? 4e8
int n;
double a[N],b[N];
double qr(double x,double y)
{
	return sqrt(x*x+y*y);
}
bool cmp(double x,double y)
{
	return abs(x)<abs(y);
}
void solve()
{
	int cnt=0,ret=0;
	double ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n*2;i++)
	{
		double x,y;
		scanf("%lf%lf",&x,&y);
		if(x==0)  a[++ret]=y;
		else  b[++cnt]=x;
	}
	sort(a+1,a+n+1,cmp);
	sort(b+1,b+n+1,cmp);
	for(int i=1;i<=n;i++)  ans+=qr(a[i],b[i]);
	printf("%.15lf\n",ans);
}
signed main()
{
//	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)  solve();
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值