2021.1.17寒假打卡Day13

< CCUT 20210117 >

A - 小心FST!

Mia Hossain is a very good competitive programmer & spends his most of the time in programming contest. His wife is very much interested in competitive programming. In her free time she sits beside him & curiously watches how he solves problems. Sometimes she also helps him by giving valuable ideas. She has a sound math background. She is also at home in C programming.

One day Mia Hossain gave her wife a simple problem to solve & she immediately solved it. Can you solve this problem??

The problem is –

You are given three digits of a 3-digit number. Let’s denote the digits F, S & T as First digit, Second digit & Third digit respectively. You have to answer whether the 3-digit number is a multiple of 4 or not?

Constraints
1 <= F, S, T <= 9

Input
Input is given from Standard Input in the following format:
F S T

Output
If the 3-digit integer is a multiple of 4, then print YES otherwise, print NO.
You don’t have to print Note section.

Sample Input 1

2 4 8

Sample Output 1

YES

Sample Input 2

4 6 6

Sample Output 2

NO

判断是否是4的倍数

#include<iostream>
using namespace std;

int main (){
	int f,s,t,num;
	cin>>f>>s>>t;
	num=f*100+s*10+t;
	if(num%4==0) cout<<"YES";
	else cout<<"NO";
	return 0;
}

B - string类的简单技巧

You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k≤n) from the string s. Polycarp uses the following algorithm k times:

  • if there is at least one letter ‘a’, remove the leftmost occurrence and stop the algorithm, otherwise go to next item;

  • if there is at least one letter ‘b’, remove the leftmost occurrence and stop the algorithm, otherwise go to next item;

  • ……

  • remove the leftmost occurrence of the letter ‘z’ and stop the algorithm.

This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly k times, thus removing exactly k characters.

Help Polycarp find the resulting string.

Input
The first line of input contains two integers n and k (1≤k≤n≤4e5) — the length of the string and the number of letters Polycarp will remove.

The second line contains the string s consisting of n lowercase Latin letters.

Output
Print the string that will be obtained from s after Polycarp removes exactly k letters using the above algorithm k times.

If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).

Examples
Input

15 3
cccaabababaccbc

Output

cccbbabaccbc

Input

15 9
cccaabababaccbc

Output

cccccc

Input

1 1
u

Output


我居然没看懂题目意思🥴
看题解才明白每一次操作就是去除最左边的a,没有a就b,没有b就c……直到删掉一个字母,保证一次删一个。

#include<iostream>
#include<string>
using namespace std;
int flag[400000]={0};
int main(){
	int n,k,m=0;
	char v='a';
	cin>>n>>k;
	cin>>s;
	while(k--){
		while(v<='z'&&m){
			for(int i=0;i<n;i++){
				if (s[i]==v) {flag[i]=1;m=1;break;}
			}
			v++;
		}
		
	}
	for(int i=0;i<n;i++){
		if(!flag) cout<<s[i];
	}
	return 0;
}

C - 吐泡泡++

神秘的三角洲里还有一个传说中的谜题等你来解开!

据说三角洲里的小学生小明是个小天才。于是好多小朋友都想去买他亲手敲出来的字符串,以获得学神的保佑。但是天才小明,他总是在思考31维宇宙空间的奥秘,神游天外,所以在给小朋友们敲想要的字符串的时候,有时候会精神难以集中,重复按某些按钮,于是就会出现形如hhoww are youu这样的字符串。这样小朋友们肯定不满意呀,可怜的小明,他的字符串滞销了!!!请你帮帮他。

小明会给你字符串,如果相邻的字符相同,请消除他们,如果消除后又有相邻的字符相同
,继续消除,最后请给小明展示正确的字符串(删除顺序随意,最后的结果一样)。

Input
一行滞销的字符串,长度为1~2e5。

Output
输出正确的,不会滞销的字符串!

Examples
Input

hhoowaaaareyyoouu

Output

wre

Input

reallazy

Output

rezy

Input

abacabaabacabaa

Output

a

我一开始统计区间的思路就是有问题的。
听说栈很好用,可是我没用出来,就很尴尬。。。

#include<iostream>
#include<stack>
using namespace std;

char st[200001];
int tp;

int main(){
	char c=getchar();
	while(c!='\n'){
		if(tp&&c==st[tp]) --tp;
		else st[++tp]=c;
		c=getchar();
	}
	st[tp+1]='\0';
	printf("%s\n",st+1);
	return 0;
}

D - 简单的博弈

During their New Year holidays, Alice and Bob play the following game using an array a of n integers:

Players take turns, Alice moves first.

Each turn a player chooses any element and removes it from the array.

If Alice chooses even value, then she adds it to her score. If the chosen value is odd, Alice’s score does not change.

Similarly, if Bob chooses odd value, then he adds it to his score. If the chosen value is even, then Bob’s score does not change.

If there are no numbers left in the array, then the game ends. The player with the highest score wins. If the scores of the players are equal, then a draw is declared.

For example, if n=4 and a=[5,2,7,3], then the game could go as follows (there are other options):

  • On the first move, Alice chooses 2 and get two points. Her score is now 2. The array a is now [5,7,3].
  • On the second move, Bob chooses 5 and get five points. His score is now 5. The array a is now [7,3].
  • On the third move, Alice chooses 7 and get no points. Her score is now 2. The array a is now [3].
  • On the last move, Bob chooses 3 and get three points. His score is now 8. The array a is empty now.

Since Bob has more points at the end of the game, he is the winner.
You want to find out who will win if both players play optimally. Note that there may be duplicate numbers in the array.

Input
The first line contains an integer t (1 ≤ t ≤ 104) — the number of test cases. Then t test cases follow.

The first line of each test case contains an integer n (1 ≤ n ≤ 2e5) — the number of elements in the array a.

The next line contains n integers a1,a2,…,an (1 ≤ ai ≤ 109) — the array a used to play the game.

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

Output
For each test case, output on a separate line:
“Alice” if Alice wins with the optimal play;
“Bob” if Bob wins with the optimal play;
“Tie”, if a tie is declared during the optimal play.

Example
Input

4
4
5 2 7 3
3
3 2 1
4
2 2 2 2
2
7 8

Output

Bob
Tie
Alice
Alice

不论能不能加分,就拿最大的数,一个是让自己多得分,一个是让对手不能得高分😁

#include<iostream>
#include<algorithem>
using namespace std;

int a[200010];

int main(){
	int t;cin>>t;
	while(t--){
		int n,alice=0,bob=0;cin>>n;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a,a+n+1);
		for(int i=0;i<n;i++){
			if(i%2==0&&a[i]%2==0) alice+=a[i];
			else if(i%2!=0&&a[i]%2!=0) bob+=a[i];
		}
		if(a>b)cout<<"Alice"<<endl;
		if(a<b)cout<<"Bob"<<endl;
		if(a==b) cout<<"Tie"<<endl;
	}
	return 0;
}

E - 寒假太长

小公举有一个长度为 n 的序列 a. 还是因为放假太长的缘故,所以小公举有很多时间来复制这个序列并相连。问最长递增序列的长度是多少?

如果序列A可以通过序列B删除几个元素得到 (可能不删除或者删除全部) 。那么序列A称为序列B的子序列。所求的最长递增序列为拼接后序列的子序列

Input
第一行输入组数t.。
每组测试样例第一行输入序列a的长度n(1 <= n <= 1e5)

第二行输入n个用空格隔开的数a1,a2,……,an(1 <= ai <= 1e9)。
测试样例中n的总和不超过1e5.

Output
输出复制后最长递增序列的长度。

Example
Input

2
4
4 3 2 1
6
3 1 6 1 5 7

Output

4
5

Note
第一个样例拼接后的结果为 4 3 2 1;4 3 2 1 ;4 3 2 1;4 3 2 1 最长递增子序列为 x x x 1;x x 2 x ;x 3 x x ; 4 x x x 。x表示不取。

set去重,但是我不知为何WA

#include <iostream>
#include <set>
using namespace std;

int main(){
	set<int> s;
	int t;
	cin>>t;
	while(t--){
		int n,c;
		cin>>n;
		while(n--){
			cin>>c;
			s.insert(c);
		}
		cout<<s.size()<<endl;
	}
	return 0;
}

F - 简单的铲屎官技巧

SR有一只猫,他的猫是一个真正的美食家!根据一周中的某一天决定他吃某种食物:

星期一、四、星期日他吃鱼;
星期二和星期六他吃炖兔肉;
在一周的其他日子里,他吃鸡肉。

SR准备去旅行,他已经收拾好背包。他的背包中包含:
a天份量的鱼食;
b天份量的炖兔肉;
c天份量的鸡肉。

SR不得不选择一周中的某一天开始他的旅行,这样他的猫就可以尽可能长时间不用额外购买食物。请你决定SR应该选择一周中的哪一天开始他的旅行,并输出猫在一次旅行中不需要额外购买食物就可以吃的最大天数。

Input
三个数 a,b,c(1 <= a, b, c <= 7e8)

Output
输出猫在一次旅行中不需要额外购买食物就可以吃的最大天数。

Examples
样例输入1

2 1 1

样例输出1

4

样例输入2

3 2 2

样例输出2

7

样例输入3

1 100 1

样例输出3

3

样例输入4

30 20 10

样例输出4

39

Note
在第一个例子中,开始旅行的最佳时间是周日。在这种情况下,猫会在周日和周一吃鱼,周二吃炖兔肉,周三吃鸡肉。所以,经过四天的旅行,所有的食物都将被吃掉。

在第二个例子中,SR可以在一周中的任何一天开始他的旅行。在任何情况下,只有一个星期的食物供应。

在第三个例子中,SR可以在除了星期三、星期六和星期日外的任何一天开始他的旅行。在这种情况下,猫将在三天内吃三个不同的菜。尽管如此,在三天的旅行后,背包里会有99份炖兔肉,在旅行的第四天什么也吃不下。

#include<iostream>
using namespace std;

int recipe[8]={1,1,2,3,1,3,2,1};

int main(){
	int a,b,c,cnt[8]={0},d,max=0;
	cin>>a>>b>>c;
	for(int i=1;i<=7;i++){
		d=i;
		while(!((a=0)&&(b=0)&&(c=0))){
			if(++d>7) d%=7;
			if(recipe[d]==1) {--a;++cnt[i];}
			if(recipe[d]==2) {--b;++cnt[i];}
			if(recipe[d]==3) {--c;++cnt[i];}
		}
		max=max>cnt[i]?max:cnt[i];
	}
	cout<<max;
	return 0;
} 

本地WA,找错中🐌

G - 简单的分组技巧

There are n athletes in front of you. Athletes are numbered from 1 to n from left to right. You know the strength of each athlete — the athlete number i has the strength si.

You want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team.

You want the strongest athlete from the first team to differ as little as possible from the weakest athlete from the second team. Formally, you want to split the athletes into two teams A and B so that the value |max(A)−min(B)| is as small as possible, where max(A) is the maximum strength of an athlete from team A, and min(B) is the minimum strength of an athlete from team B.

For example, if n=5 and the strength of the athletes is s=[3,1,2,6,4], then one of the possible split into teams is:

first team: A=[1,2,4],
second team: B=[3,6].
In this case, the value |max(A)−min(B)| will be equal to |4−3|=1. This example illustrates one of the ways of optimal split into two teams.

Print the minimum value |max(A)−min(B)|.

Input
The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases in the input. Then t test cases follow.

Each test case consists of two lines.

The first line contains positive integer n (2 ≤ n ≤ 50) — number of athletes.

The second line contains n positive integers s1,s2,…,sn (1 ≤ si ≤ 1000), where si — is the strength of the i-th athlete. Please note that s values may not be distinct.

Output
For each test case print one integer — the minimum value of |max(A)−min(B)| with the optimal split of all athletes into two teams. Each of the athletes must be a member of exactly one of the two teams.

Example
Input

5
5
3 1 2 6 4
6
2 1 3 2 4 3
4
7 9 3 1
2
1 1000
3
100 150 200

Output

1
0
2
999
50

Note
The first test case was explained in the statement.

In the second test case, one of the optimal splits is A=[2,1], B=[3,2,4,3], so the answer is |2−2|=0.

排好序,相邻两数最小的那个差值就是答案,题目并没有对其他成员做要求,无需考虑整体差值。

#include<iostream>
#include<algorithem>
using namespace std;

int a[200010];

int main(){
	int t;cin>>t;
	while(t--){
		int n,min=1000;cin>>n;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a,a+n+1);
		for(int i=1;i<n;i++){
			min=min<(a[i]-a[i-1])?min:a[i]-a[i-1];
		}
		cout<<min<<endl;
	}
	return 0;
}

H - 简单的桶排

给定一个由 n 个整数组成的数组 a 。玩家可以执行以下操作几次。 在单次操作中,他可以选择数组中的一个元素 ( 让我们称它为 ak ) 并删除它,所有等于 ak + 1 和 ak - 1 的元素都会被一并删除,这样的一次操作可以得到 ak 分。

得到尽可能多的分数。

输入
第 1 行包含 1 个整数 n (1 ≤ n ≤ 105) ——代表数组元素个数。

第 2 行包含 n 个整数: a1, a2, …, an (1 ≤  ai  ≤ 105).

输出
输出 1 个整数代表能获得的最大分数。

样例
输入

2
1 2

输出

2

输入

3
1 2 3

输出

4

输入

9
1 2 1 3 2 2 2 2 3

输出

10

提示
在第 3 个样例中,第一次操作我们需要选择任意一个等于 2 的元素。在这一次操作之后,数组变成 [2,2,2,2] 。然后我们再做4次操作,每一次操作都选择一个等于2的元素。这样小图最多能得 10 分。

利用桶a[n]统计好数字的个数;
然后从 1 开始动态规划,如果我选择了 i,那么到 i 为止的分数 f [ i ] 应为f [i - 2] + i * a[ i ] ;如果没选 i ,f [ i ] = f [i - 1];

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值