Codeforces Round #616 (Div. 2)

A. Even But Not Even

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Let’s define a number ebne (even but not even) if and only if its sum of digits is divisible by 2 but the number itself is not divisible by 2. For example, 13, 1227, 185217 are ebne numbers, while 12, 2, 177013, 265918 are not. If you’re still unsure what ebne numbers are, you can look at the sample notes for more clarification.

You are given a non-negative integer s, consisting of n digits. You can delete some digits (they are not necessary consecutive/successive) to make the given number ebne. You cannot change the order of the digits, that is, after deleting the digits the remaining digits collapse. The resulting number shouldn’t contain leading zeros. You can delete any number of digits between 0 (do not delete any digits at all) and n−1.

For example, if you are given s=222373204424185217171912 then one of possible ways to make it ebne is: 222373204424185217171912 → 2237344218521717191. The sum of digits of 2237344218521717191 is equal to 70 and is divisible by 2, but number itself is not divisible by 2: it means that the resulting number is ebne.

Find any resulting number that is ebne. If it’s impossible to create an ebne number from the given number report about it.

Input
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — 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≤3000) — the number of digits in the original number.

The second line of each test case contains a non-negative integer number s, consisting of n digits.

It is guaranteed that s does not contain leading zeros and the sum of n over all test cases does not exceed 3000.

Output
For each test case given in the input print the answer in the following format:

If it is impossible to create an ebne number, print “-1” (without quotes);
Otherwise, print the resulting number after deleting some, possibly zero, but not all digits. This number should be ebne. If there are multiple answers, you can print any of them. Note that answers with leading zeros or empty strings are not accepted. It’s not necessary to minimize or maximize the number of deleted digits.
Example
inputCopy
4
4
1227
1
0
6
177013
24
222373204424185217171912
outputCopy
1227
-1
17703
2237344218521717191
Note
In the first test case of the example, 1227 is already an ebne number (as 1+2+2+7=12, 12 is divisible by 2, while in the same time, 1227 is not divisible by 2) so we don’t need to delete any digits. Answers such as 127 and 17 will also be accepted.

In the second test case of the example, it is clearly impossible to create an ebne number from the given number.

In the third test case of the example, there are many ebne numbers we can obtain by deleting, for example, 1 digit such as 17703, 77013 or 17013. Answers such as 1701 or 770 will not be accepted as they are not ebne numbers. Answer 013 will not be accepted as it contains leading zeroes.

Explanation:

1+7+7+0+3=18. As 18 is divisible by 2 while 17703 is not divisible by 2, we can see that 17703 is an ebne number. Same with 77013 and 17013;
1+7+0+1=9. Because 9 is not divisible by 2, 1701 is not an ebne number;
7+7+0=14. This time, 14 is divisible by 2 but 770 is also divisible by 2, therefore, 770 is not an ebne number.
In the last test case of the example, one of many other possible answers is given. Another possible answer is: 222373204424185217171912 → 22237320442418521717191 (delete the last digit).

思路:

只需要在串里面找到两个奇数即可,因为两个奇数的组合是奇数,和是偶数,满足题意;

AC:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int  t;
	cin >>t;
	while(t--)
	{
		int n;
		cin >>n;
		string s;
		cin >>s;
		int cnt=0;
		string ss;
		for(int i=0;i<n;i++)
		{
			if((s[i]-'0')%2==1) ss+=s[i],cnt++;
			if(cnt==2) break;
		}
		if(cnt==2) cout <<ss<<endl;
		else cout <<-1<<endl;
	}
}

.
.

B. Array Sharpening

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You’re given an array a1,…,an of n non-negative integers.

Let’s call it sharpened if and only if there exists an integer 1≤k≤n such that a1<a2<…ak+1>…>an. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:

The arrays [4], [0,1], [12,10,8] and [3,11,15,9,7,4] are sharpened;
The arrays [2,8,2,8,6,5], [0,1,1,0] and [2,5,6,9,8,8] are not sharpened.
You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1≤i≤n) such that ai>0 and assign ai:=ai−1.

Tell if it’s possible to make the given array sharpened using some number (possibly zero) of these operations.

Input
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤15 000) — 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≤3⋅105).

The second line of each test case contains a sequence of n non-negative integers a1,…,an (0≤ai≤109).

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

Output
For each test case, output a single line containing “Yes” (without quotes) if it’s possible to make the given array sharpened using the described operations, or “No” (without quotes) otherwise.

Example
inputCopy
10
1
248618
3
12 10 8
6
100 11 15 9 7 8
4
0 1 1 0
2
0 0
2
0 1
2
1 0
2
1 1
3
0 1 0
3
1 0 1
outputCopy
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
No
Note
In the first and the second test case of the first test, the given array is already sharpened.

In the third test case of the first test, we can transform the array into [3,11,15,9,7,4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3<11<15 and 15>9>7>4.

In the fourth test case of the first test, it’s impossible to make the given array sharpened.

题意:

一个数列 让你进行一系列变换之后变成先递增再递减的数列(一直递增的也符合要求),每一次的操作是:可以对任意一个大于0的数使它变小;

思路:(假设数列下标从0开始)
假设这个k存在,那么k+1左边的数(不包括k+1)一定满足a[i]>=i;如果不满足那么此时这个数一定是k+1;从k+1开始后面每一个数至少是前一个数的-1,所以后面每一个数都是min(a[i-1]-1,a[i]);
直到最后一个数,如果求得最后一个数小于0的话,就不符合题意;

AC:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3*1e5+7;
int a[N];
int main()
{
	int t;
	cin >>t;
	while(t--)
	{
		int n;
		cin >>n;
		int ans=-1;
		for(int i=0;i<n;i++) cin >>a[i];
		for(int i=0;i<n;i++)
		{
			if(a[i]<i)
			{
				ans=i;
				break;
			}
		}
		if(n==1||ans==-1)
		{
			cout <<"Yes"<<endl;
			continue;
		}
		//int res=a[ans-1];
		for(int i=ans;i<n;i++) a[i]=min(a[i-1]-1,a[i]);
		if(a[n-1]>=0) cout <<"Yes"<<endl;
		else cout <<"No"<<endl;
	}	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值