集训队每周一赛2020-03-06(思维+暴力)

第二次周赛

    • A 我是A题
    • CodeForces 1305
    • 题解
  • B 我是B题
    • 计蒜客 A1530
    • 题解
  • C 我是C题
    • HDU 2673
    • 题解
  • D 我是D题
    • CodeForces 304B
    • 题解
  • E 我是E题
    • CodeForces 1311C
    • 题解
  • F 我是F题
    • CodeForces 1304B
    • 题解
  • G 我是G题
    • Gym 102302B
    • 题解
  • H 我是附加题
    • Kattis racingalphabet
    • 题解

A 我是A题

CodeForces 1305

Kuroni has daughters. As gifts for them, he bought necklaces and bracelets:
the -th necklace has a brightness , where all the are pairwise distinct (i.e. all are different),
the -th bracelet has a brightness , where all the are pairwise distinct (i.e. all are different).
Kuroni wants to give exactly one necklace and exactly one bracelet to each of his daughters. To make sure that all of them look unique, the total brightnesses of the gifts given to each daughter should be pairwise distinct. Formally, if the -th daughter receives a necklace with brightness and a bracelet with brightness , then the sums should be pairwise distinct. Help Kuroni to distribute the gifts.
For example, if the brightnesses are and , then we may distribute the gifts as follows:
Give the third necklace and the first bracelet to the first daughter, for a total brightness of .
Give the first necklace and the third bracelet to the second daughter, for a total brightness of .
Give the second necklace and the second bracelet to the third daughter, for a total brightness of .
Here is an example of an invalid distribution:
Give the first necklace and the first bracelet to the first daughter, for a total brightness of .
Give the second necklace and the second bracelet to the second daughter, for a total brightness of .
Give the third necklace and the third bracelet to the third daughter, for a total brightness of .
This distribution is invalid, as the total brightnesses of the gifts received by the first and the third daughter are the same. Don’t make them this upset!

Input

The input consists of multiple test cases. The first line contains an integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the number of daughters, necklaces and bracelets.
The second line of each test case contains distinct integers () — the brightnesses of the necklaces.
The third line of each test case contains distinct integers () — the brightnesses of the bracelets.

Output

For each test case, print a line containing integers , representing that the -th daughter receives a necklace with brightness . In the next line print integers , representing that the -th daughter receives a bracelet with brightness .
The sums should all be distinct. The numbers should be equal to the numbers in some order, and the numbers should be equal to the numbers in some order.
It can be shown that an answer always exists. If there are multiple possible answers, you may print any of them.

Example

Input
2
3
1 8 5
8 4 5
3
1 7 5
6 1 2
Output
1 8 5
8 4 5
5 1 7
6 2 1

Note

In the first test case, it is enough to give the -th necklace and the -th bracelet to the -th daughter. The corresponding sums are , , and .
The second test case is described in the statement.

题解

#include
#include
using namespace std;
int main()
{
	int i,j,a[1000],b[1000],t,n;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		for(i=0;i<n;i++)
		scanf("%d",&b[i]);
		sort(a,a+n);
		sort(b,b+n);
		for(i=0;i<n-1;i++)
		{
			if(a[i]+b[i]==a[i+1]+b[i+1])
			{
				swap(a[i],a[i+1]);									
			}
		}
		for(i=0;i<n-1;i++)
			printf("%d ",a[i]);
		printf("%d\n",a[n-1]);
		for(i=0;i<n-1;i++)
			printf("%d ",b[i]);
		printf("%d\n",b[n-1]);
	}
	return 0;
}

B 我是B题

计蒜客 A1530

“Abiyoyo, Abiyoyo.”
“Abiyoyo, Abiyoyo.”
“Abiyoyo, yo yoyo yo yoyo.”
Once upon a time there was a little boy, who played a ukulele. He’d go around town: clink, clunk, CLONK! Of course, the grownups would be busy, and they would say: “Take that thing out of here. We are talking. Git!” And they would kick him out of the house.
Now, in this town they used to tell stories. The old people used to tell stories about the monsters and giants that lived in the old days! They used to tell a story about Abiyoyo. They said he was as tall as a house, and could eat people up. Of course, nobody believed it, but they told the stories anyway.
But one day, the sun rose, blood red over the hill, and the first people that got up and looked out of their window. They saw a great big shadow in front of the sun, and they could feel the whole ground shake.
Women screamed. Strong men fainted.
They said: “Run for your lives! Abiyoyo’s coming!” Down through the fields he came. He came to the sheep, pasture and grabs a whole sheep. Yeowp! He eats it down in one bite. He comes to the cow pasture. Yuhk!
Just then the boy woke up. The boy rubbed his eyes and said: “Hey, what is coming over the fields? Oh, it is Abiyoyo.” He grabbed his ukulele. Over the fields he went, right up to where Abiyoyo was. People screamed “Don’t go near him! He will eat you alive!”
There was Abiyoyo. He had long fingernails because he never cut them. He had slobbery teeth because he never brushed them. Matted hair because he never combed it. Stinking feet because he never washed them. He was just about to come down with his claws, when the boy whipped out his ukulele.
Abiyoyo, Abiyoyo Abiyoyo, Abiyoyo Abiyoyo, yo yoyo yo yoyo Abiyoyo, yo yoyo yo yoyo.
Well, the monster had never heard a song about himself before, and a foolish grin spread across his face. And started to dance.
Abiyoyo, Abiyoyo.Abiyoyo,Abiyoyo.
The boy went faster.
Abiyoyo, yo yoyo, yo yoyo Abiyoyo, yoyo yoyo, ho ho ho ho ho ho ho ho.Abiyoyo,yoyoyo,yoyoyoAbiyoyo,yoyoyoyo,hohohohohohohoho.
The giant got out of breath. He staggered. He fell down flat on the ground.
“Booooom!” A hunter fired, and the Abiyoyo died. People streamed out of their houses, and ran across the fields.
They sang many times:
Abiyoyo, Abiyoyo.Abiyoyo,Abiyoyo.
Then they all sang:
Abiyoyo, yo yoyo yo yoyo.Abiyoyo,yoyoyoyoyoyo.
Abiyoyo, yo yoyo yo yoyo.Abiyoyo,yoyoyoyoyoyo.

Input

This problem has several test cases. The first line of the input contains an integer tt (1 \le t \le 20)(1≤t≤20) which is the number of test cases.
Then tt cases follow. For each test, a line contains an integer k (1 \le k \le 20)k(1≤k≤20) which means that people sang k times:
Abiyoyo, Abiyoyo.Abiyoyo,Abiyoyo.

Output

For each case, output all what they sang after the death of Abiyoyo in several lines.

样例输入
3
2
5
1
样例输出
Abiyoyo, Abiyoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, yo yoyo yo yoyo.
Abiyoyo, yo yoyo yo yoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, yo yoyo yo yoyo.
Abiyoyo, yo yoyo yo yoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, yo yoyo yo yoyo.
Abiyoyo, yo yoyo yo yoyo.

题解

#include
int main()
{
	int t,k,i;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&k);
		for(i=0;i<k;i++)
		{
			printf("Abiyoyo, Abiyoyo.\n");
		}
		printf("Abiyoyo, yo yoyo yo yoyo.\nAbiyoyo, yo yoyo yo yoyo.\n");		
	}
	return 0;
 } 

C 我是C题

HDU 2673

Acmer in HDU-ACM team are ambitious, especially shǎ崽, he can spend time in Internet bar doing problems overnight. So many girls want to meet and Orz him. But Orz him is not that easy.You must solve this problem first.
The problem is :
Give you a sequence of distinct integers, choose numbers as following : first choose the biggest, then smallest, then second biggest, second smallest etc. Until all the numbers was chosen .
For example, give you 1 2 3 4 5, you should output 5 1 4 2 3

Input
There are multiple test cases, each case begins with one integer N(1 <= N <= 10000), following N distinct integers.
Output
Output a sequence of distinct integers described above.

Sample Input
5
1 2 3 4 5
Sample Output
5 1 4 2 3

题解

#include 
#include 
using namespace std;
int main() {
    int a[10000], i, j, n;
    while (~scanf("%d", &n)) {
        for (i = 0; i < n; ++i) scanf("%d", a + i);
        sort(a, a + n);
        for (i = 0, j = n - 1; i <= (n - 1) / 2 - 1; i++, j--) {
            printf("%d %d ", a[j], a[i]);
        }
        if (n % 2) printf("%d\n", a[i]);
        else printf("%d %d\n", a[j], a[i]); 
    }
    return 0;
}

D 我是D题

CodeForces 304B

Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar’s scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.集训队每周一赛2020-03-06(思维+暴力)_第1张图片In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.

题解

#include
int sum(int y,int m,int d)
{   
    char x[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};     
    int i,s=0;    
    for(i=1;i<y;i++)           
        if(i%4==0 && i%100!=0 || i%400==0)           
            s+=366;      
        else           
            s+=365;  
    if(y%4==0 && y%100!=0 || y%400==0)       
        x[2]=29;    
    for(i=1;i<m;i++)       
        s+=x[i];   
    s+=d;   
    return s;
}
int main()
{    
    int y1,m1,d1,y2,m2,d2;    
    long long s1,s2;      
    scanf("%d:%d:%d",&y1,&m1,&d1);      
    scanf("%d:%d:%d",&y2,&m2,&d2);    
    s1=sum(y1,m1,d1);    
    s2=sum(y2,m2,d2);    
    if (s1>s2)       
        printf("%ld\n",s1-s2);    
    else       
    printf("%ld\n",s2-s1);
}

E 我是E题

CodeForces 1311C

You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s=“abca” then you have to press ‘a’, then ‘b’, ‘c’ and ‘a’ again.
You know that you will spend m wrong tries to perform the combo and during the i-th try you will make a mistake right after pi-th button (1≤pi I.e. if s=“abca”, m=2 and p=[1,3] then the sequence of pressed buttons will be ‘a’ (here you’re making a mistake and start performing the combo from the beginning), ‘a’, ‘b’, ‘c’, (here you’re making a mistake and start performing the combo from the beginning), ‘a’ (note that at this point you will not perform the combo because of the mistake), ‘b’, ‘c’, ‘a’.
Your task is to calculate for each button (letter) the number of times you’ll press it.
You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1≤t≤104) — the number of test cases.
Then t test cases follow.
The first line of each test case contains two integers n and m (2≤n≤2⋅105, 1≤m≤2⋅105) — the length of s and the number of tries correspondingly.
The second line of each test case contains the string s consisting of n lowercase Latin letters.
The third line of each test case contains m integers p1,p2,…,pm (1≤pi It is guaranteed that the sum of n and the sum of m both does not exceed 2⋅105 (∑n≤2⋅105, ∑m≤2⋅105).
It is guaranteed that the answer for each letter does not exceed 2⋅109.

Output

For each test case, print the answer — 26 integers: the number of times you press the button ‘a’, the number of times you press the button ‘b’, …, the number of times you press the button ‘z’.

Example

Input
3
4 2
abca
1 3
10 5
codeforces
2 8 3 2 9
26 10
qwertyuioplkjhgfdsazxcvbnm
20 10 1 2 3 5 10 5 9 4
Output
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 9 4 5 3 0 0 0 0 0 0 0 0 9 0 0 3 1 0 0 0 0 0 0 0
2 1 1 2 9 2 2 2 5 2 2 2 1 1 5 4 11 8 2 7 5 1 10 1 5 2

Note

The first test case is described in the problem statement. Wrong tries are “a”, “abc” and the final try is “abca”. The number of times you press ‘a’ is 4, ‘b’ is 2 and ‘c’ is 2.
In the second test case, there are five wrong tries: “co”, “codeforc”, “cod”, “co”, “codeforce” and the final try is “codeforces”. The number of times you press ‘c’ is 9, ‘d’ is 4, ‘e’ is 5, ‘f’ is 3, ‘o’ is 9, ‘r’ is 3 and ‘s’ is 1.

题解

#include
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
int a[maxn];
int cnt[26];
int main() 
{
	int i, t, n, m, tmp, cur;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d%d", &n, &m);
		scanf("%s", s + 1);
		for(i = 1; i <= n; i++) 
			a[i] = 0;
		for(i = 0; i < 26; i++) 
			cnt[i] = 0;		
		for(i = 0; i < m; i++)
		{
			scanf("%d", &tmp);
			a[tmp]++;
		}
		for(i = 1, cur = m + 1; i <= n; i++) 
		{
			cnt[s[i] - 'a'] += cur, cur -= a[i];
		}
		for(i = 0; i < 25; i++) 
			printf("%d ", cnt[i]);
		printf("%d", cnt[25]);
		if(t) printf("\n");
	}
	return 0;
}

F 我是F题

CodeForces 1304B

Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings “pop”, “noon”, “x”, and “kkkkkk” are palindromes, while strings “moon”, “tv”, and “abab” are not. An empty string is also a palindrome.
Gildong loves this concept so much, so he wants to play with it. He has n distinct strings of equal length m. He wants to discard some of the strings (possibly none or all) and reorder the remaining strings so that the concatenation becomes a palindrome. He also wants the palindrome to be as long as possible. Please help him find one.

Input

The first line contains two integers n and m (1≤n≤100, 1≤m≤50) — the number of strings and the length of each string.
Next n lines contain a string of length m each, consisting of lowercase Latin letters only. All strings are distinct.

Output

In the first line, print the length of the longest palindrome string you made.
In the second line, print that palindrome. If there are multiple answers, print any one of them. If the palindrome is empty, print an empty line or don’t print this line at all.

Examples

Input
3 3
tab
one
bat
Output
6
tabbat
Input
4 2
oo
ox
xo
xx
Output
6
oxxxxo
Input
3 5
hello
codef
orces
Output
0
Input
9 4
abab
baba
abcd
bcde
cdef
defg
wxyz
zyxw
ijji
Output
20
ababwxyzijjizyxwbaba

Note

In the first example, “battab” is also a valid answer.
In the second example, there can be 4 different valid answers including the sample output. We are not going to provide any hints for what the others are.
In the third example, the empty string is the only valid palindrome string.

题解

在这里插入代#include<iostream>
#include
using namespace std;
char s[105][55];
int mp[1005],a[1005];
int m;
int check(int i,int j)
{
	for(int k=0;k<m;k++)
	{
		if(s[i][k]!=s[j][m-k-1])
		return 0;
	}
	return 1;
}
int main()
{
	int i, j, n, cnt=0, tmp=-1, flag=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%s",s[i]);		
	}
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(check(i,j))
			{
				a[++cnt]=i;
				a[++cnt]=j;
			}
		}
	}
	for(i=1;i<=cnt;i++)
		mp[a[i]]=1;
	for(i=1;i<=n;i++)
	{
		if(mp[i]!=1)
		{
			flag=0;
			for(j=0;j<m;j++)
			{
				if(s[i][j]!=s[i][m-j-1])
				{
					flag=1;
					break;
				}
			}
			if(flag==0)
				tmp=i;
		}
	}
	if(tmp!=-1)
	printf("%d\n",(cnt+1)*m);
	else
	printf("%d\n",cnt*m);
	for(i=1;i<=cnt;i++)
	{
		if(i%2==1)
			printf("%s",s[a[i]]);
	}
	if(tmp!=-1)
		printf("%s",s[tmp]);
	for(i=cnt;i>=2;i--)
	{
		if(i%2==0)
			printf("%s",s[a[i]]);
	}
	printf("\n");
	return 0;
} 码片

G 我是G题

Gym 102302B

After your death, you’re sent to a mysterious room. There are two guardian cats and two doors, one goes to heaven of AC problems and another goes to hell NO. One cat likes all divisors of an integer a and the other cat likes all multiples of an integer b. You where asked to write all integers that satisfies both. If you answer correctly, you may go to heaven of AC problems, full of balloons, otherwise you’re sent to hell NO.

Input

The input consists of two integers a and b, where 1 ≤ b ≤ a ≤ 1012.

Output

The output consists of one line with all integers from smallest to largest that satisfies both guardian cats.

Examples

Input
12 3
Output
3 6 12
Input
10 3
Output
Input
128 2
Output
2 4 8 16 32 64 128

题解

#include
#include
#define ll long long
using namespace std;
int main()
{
	ll i,j=0,a,b,c[100005];
	scanf("%lld%lld",&a,&b);
	for(i=1;i*i<=a;i++)
	{
		if(a%i==0)
		{
			c[j++]=i;
			if(i!=a/i)
			c[j++]=a/i;			
		}
	}
	sort(c,c+j);
	for(i=0;i<j;i++)
	{
		if(c[i]%b==0)
		printf("%lld ",c[i]);
	}
	return 0;
}

H 我是附加题

Kattis racingalphabet

Soccer coach Joe has invented a new fitness game that he thinks will help his players’ agility and fitness. The center circle of the soccer pitch has a diameter of 60 feet. He marks 28 evenly-spaced points on the circumference of the circle. On the first point (arbitrarily chosen) he places a pile of tokens all inscribed with the letter ’A’. On the second point he places a pile of ’B’ tokens, and so on, covering 26 of the 28 points. He places a pile of blanks (or space-characters) on the 27th point and a pile of disks imprinted with single quotation marks, on the last point.
集训队每周一赛2020-03-06(思维+暴力)_第2张图片
He gives each player a slip of paper containing an aphorism, such as “WINNING ISN’T EVERYTHING IT’S THE ONLY THING” Notice that the only punctuation marks allowed are spaces and single quotation marks. Each player gets a different aphorism.
A player starts outside the circle next to the first letter of his aphorism and, on Joe’s “GO” signal, the player picks up his first disk and then takes off running around the outside of the circle, picking up the remaining disks in the order that the corresponding letters appear in the aphorism. A smart player will take the shortest route, possibly changing direction, between consecutive letters of his aphorism.
One of the assistant coaches makes a note of the player’s time. Although Joe initially envisioned all of his 20 players running around the circle simultaneously, this idea was scrapped due to contusions and fractures.
Joe wants you to write a program to estimate the expected time for one smart player to complete each of the aphorisms. Assume for simplicity that the player runs at 15 feet per second between stops for pickups and that each pickup takes 1 second.

Input

The input begins with a number N, (1≤N≤20) giving the number of aphorisms to follow. N lines follow, each one containing an aphorism made up of upper-case letters, single quotation marks, and spaces. Each aphorism will be between 8 and 120 characters inclusive.

Output

For each aphorism give the time for a smart player to complete the task. Your answer should be accurate to within 10−6 seconds.

Sample Input 1

3
WINNING ISN’T EVERYTHING IT’S THE ONLY THING
WINNERS DON’T WAIT FOR CHANCES THEY TAKE THEM
PAIN IS ONLY TEMPORARY BUT VICTORY IS FOREVER

Sample Output 1

187.6156641641
190.4108599662
193.1036536692

题解

#include
#include
#define pi 3.1415926535
#define min(a,b) a
int dis(int i,int j)
{
	if(i-j>=0)
	return i-j;
	else return i-j+28;
}
int main()
{
	int i,t,len,sum,a[125];
	char s[125];
	scanf("%d\n",&t);
	while(t--)
	{
		sum=0;
		gets(s);
		len=strlen(s);
		for(i=0;i<len;i++)
		{
			if(s[i]==' ')
			a[i]=26;
			else if(s[i]=='\'')
			a[i]=27;
			else a[i] = s[i]-'A';
		}
		for(i=0;i<len-1;i++)
		{
			sum+=(min(dis(a[i],a[i+1]),dis(a[i+1],a[i])));
		}
		double s = 60.0*pi*sum/28.0;
		double time = s/15.0+len;
		printf("%.10lf\n",time);
	}
}

你可能感兴趣的:(比赛)