Topic 1:
Title Description
Given the length of 4 ^ sticks, if there are 3 ^ sticks in them, they can form a TRIANGLE and output ^ TRIANGLE; If they cannot form triangles, but there are 3 ^ sticks in them, they can form degenerate triangles (the sum of any two sides is greater than or equal to the third side, but not triangles), output ^ SEGMENT; Otherwise, output {IMPOSSIBLE.
Note: the stick cannot be broken, nor can it be used only part of its length.
Input format
A line of 4 , integers, the length of 4 , sticks.
Output format
If there are 3 ^ sticks in them, they can form a TRIANGLE and output ^ TRIANGLE; If they cannot form triangles, but there are three wooden sticks in them, they can form degenerate triangles, and output {SEGMENT; Otherwise, output {IMPOSSIBLE.
By @PC_DOS
Input and output samples
Enter #1 copy
4 2 1 3
Output #1 copy
TRIANGLE
Enter #2 copy
7 2 2 4
Output #2 copy
SEGMENT
Enter #3 copy
3 5 9 1
Output #3 copy
IMPOSSIBLE
Solution: sort the four wooden sticks first. Just judge whether at least one of the longest or shortest two wooden sticks can form a triangle with the two wooden sticks of the length between them. If it cannot form a triangle, judge whether it can become a degenerate triangle.
The code is as follows
#include"stdio.h" #include"stdlib.h" int x[4]; int com(const void *a,const void *b) { return *(int *)a-*(int *)b; } int dfs(int a,int b,int c) { if(x[c]-x[a]<x[b]&&x[c]-x[b]<x[a]&&x[a]+x[b]>x[c]) return 1; if(x[a]+x[b]>=x[c]) return 0; else return -1; } int main() { int m,i,j; for(m=0;m<4;m++) scanf("%d",&x[m]); qsort(x,4,sizeof(int),com); dfs(0,1,2); dfs(1,2,3); if(dfs(0,1,2)==1||dfs(1,2,3)==1) printf("TRIANGLE"); else if(dfs(0,1,2)==-1&&dfs(1,2,3)==-1) printf("IMPOSSIBLE"); else printf("SEGMENT"); return 0; }
Topic 2:
Thematic translation
Small Y, small w and small D play the dice (six sided) game. Whoever throws the most points will win. Now the scores of small Y and small W are known. Please help small D find out her probability of winning
be careful:
1. Output with "numerator / denominator". In particular, if it is impossible to win, output "0 / 1", and 100% win, output "1 / 1"
2. Little Y and little W are very gentlemanly. If little D scores the same as them, they will also be counted as little D winning
Input and output samples
Enter #1 copy
4 2
Output #1 copy
1/2
Description / tips
Dot will go to Transylvania if she is lucky to roll 4, 5 or 6 points.
Solution: find the maximum value of the two numbers and judge the result exceeding the maximum value
The code is as follows
#include"stdio.h" int max(int a,int b) { if(a>b) return a; return b; } int main() { int a,b,n,m=0; scanf("%d%d",&a,&b); a=max(a,b); for(n=6;n>=1;n--) { if(n>=a) m++; } if(m==6) printf("1/1"); else if(m==1) printf("1/6"); else if(m%2==0)//2 and 4 printf("%d/%d",m/2,3); else if(m==3) printf("1/2"); else if(m==0) printf("0/1"); else if(m==5) printf("5/6"); return 0; }
Topic 3:
Title Description (abandon all kinds of messy stories)
Given a number n, it is required to scramble all digits of N and form a possible and smallest number (the smallest decimal may contain leading 0). Now there is a "minimum number". Please judge whether this "minimum number" is the minimum number.
The first line of input n does not contain a leading 0.
The assumed minimum number entered on the second line may contain a leading 0. The minimum number of questions after sorting shall not contain leading 0.
Input format
Two lines. The first line is the given number N. The second line is the "decimal" of the assumed N reorganization.
Output format
a line. If the minimum number entered is the minimum number of N, output "OK". Otherwise, output "WRONG_ANSWER".
Translated by LiM_817
Input and output samples
Enter #1 copy
3310 1033
Output #1 copy
OK
Enter #2 copy
4 5
Output #2 copy
WRONG_ANSWER
Problem solution: this problem is a problem of examining strings. You can't use arrays!!
1. After reading the string, convert the string array into an integer array (a[],b []). First, judge whether the lengths of the two strings are the same. If it is different, output "WRONG_ANSWER". If it is the same, then sort the integer array converted from the first string, find the first array element that is not 0, and exchange the array element with a[0].
2. Judge whether array s of a is equal to array b [].
3. When the string length is 1, do not change the value.
The code is as follows
#include"stdio.h" #include"string.h" #include"stdlib.h" int com(const void *a,const void *b) { return *(int *)a-*(int *)b; } int main() { char s[10],s1[10]; gets(s); gets(s1); if(strlen(s)!=strlen(s1)) printf("WRONG_ANSWER"); else if(strlen(s)==strlen(s1)) { int i,a[10],b[10],t,sign=0; for(i=0;i<strlen(s);i++) { a[i]=s[i]-'0'; } for(i=0;i<strlen(s);i++) { b[i]=s1[i]-'0'; } qsort(a,strlen(s),sizeof(int),com); if(strlen(s)>1) { t=0; while(a[t]==0) t++; i=a[t]; a[t]=a[0]; a[0]=i; } for(i=0;i<strlen(s);i++) { if(a[i]!=b[i]) { sign=1; printf("WRONG_ANSWER"); break; } } if(sign!=1) printf("OK"); } return 0; }
Topic 4:
Thematic translation
Title Description: n boards are given on a coordinate axis. The space occupied by each board is [(k-1)m,(k-1)m+l] (L < m). A frog jumps from the origin 0. Each jump is d away. Ask where the frog will fall at last (the jump ends when it falls on the board). Input: four integers n, D, m, l in a row. Output: an integer, that is, the frog's last landing point 1 < = n, D, m, l < = 10 ^ 6, l < M
Translated by rare detective
Input and output samples
Enter #1 copy
2 2 5 3
Output #1 copy
4
Enter #2 copy
5 4 11 8
Output #2 copy
20
The title is to ask for the first time not to jump on the top of the board, the essence of this problem is i=(((t-1)*m+l)/d)*d+d;
I started with i+=d, which is out of time. Why is I = ((t-1) * m + L) / d) * d + d? Jump to the longest place on this board, add a d, jump out of the board, t + +, and judge whether to jump to the next board.
The code is as follows
#include"stdio.h" int main() { long long int n,d,m,l,t,i=0,sign=0; scanf("%lld%lld%lld%lld",&n,&d,&m,&l);//The board length is l. for(t=1;t<=n;t++) { if((t-1)*m>i) break; while((t-1)*m+l>=i) i=(((t-1)*m+l)/d)*d+d; } printf("%lld",i); return 0; }
Topic 5:
Topic description
king Copa, a website about Codeforces, is often reported, which makes it popular among people who want to use the website for training and competition. Recently, Copa realized that to conquer the world, he needs to organize the world Codeforces championship. He hopes that after this competition, the smartest people will be selected to be his subordinates, and then the hardest part of conquering the world will be completed.
The last round of Codeforces world finals will be held on MM DD, YY, where DD is the date of the day, mm is the month of the month, and YY is the last two places of the year. Bob was lucky to be a finalist from Berland. But there is a problem: according to the competition rules, all contestants must be at least 18 years old at the final. Bob was born in BY, BM, BD. The date is recorded on his passport, and a copy of his passport has been sent to the organizer. But Bob learned that dates are written differently in different countries. For example, in the United States, write the month first, then the date, and finally the year.
Bob wanted to know if it was possible to rearrange the numbers of his birth date so that he would be at least 18 years old on the day of YY, MM and DD. He saw that in his country, the dates were written in different order. Please help him. According to another strange rule, qualified contestants must be born in the same century as the final date. If the final day happens to be the contestant's # 18th birthday, he can participate.
Because we only consider the final year from 2001 to 2099, we use the following rule: if the number of years can be divided by 4 , then the year is a leap year.
Input format:
The first line includes three numbers DD, mm and YY, and the second line includes three numbers BD, BM and BY. The data guarantees the correctness of the two dates, and , BY , and , YY , are guaranteed in [01, 99].
Output format:
If it is possible to rearrange the order of birth dates so that Bob is at least 18} years old on the day of the game, then output YES. If not, NO is output.
Input and output samples
Enter #1 copy
01.01.98 01.01.80
Output #1 copy
YES
Enter #2 copy
20.10.20 10.02.30
Output #2 copy
NO
Enter #3 copy
28.02.74 28.02.64
Output #3 copy
NO
Solution:
1. Set two month arrays. One is leap year and the other is not leap year.
2. When inputting, the holding time is input in the order of day, month and year. The order of birth dates is uncertain. We should take all situations into account.
3. If you are 18 years old or equal, the year of birth + 18 < the year of holding, or the year of birth + 18 = the year of holding, the month of birth < the month of holding, or the year of birth + 18 = the year of holding, the month of birth = the month of holding, and the date of birth < = the day of holding.
4. Consider whether it is a leap year.
The code is as follows:
#include"stdio.h" int r[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//Number of days per month int r1[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; int t[3]; int ss(int a,int b,int c)//Sun Moon year { if(c%4!=0&&c>0) { if(b<=12&&b>=1&&a<=r[b]) { if((c+18<t[2])||(t[2]==c+18&&t[1]>b)||(t[2]==c+18&&t[1]==b&&t[0]>=a)) return 1; else return 0; } else return 0; } if(c%4==0&&c>0) { if(b<=12&&c>=1&&b>=1&&a<=r1[b]) { if((c+18<t[2])||(t[2]==c+18&&t[1]>b)||(t[2]==c+18&&t[1]==b&&t[0]>=a)) return 1; else return 0; } else return 0; } if(c==0) return 0; } int main() { int a,b,c; scanf("%d.%d.%d",&t[0],&t[1],&t[2]);//Hold day month year fixed scanf("%d.%d.%d",&a,&b,&c);//Irregular birth if(ss(a,b,c)||ss(a,c,b)||ss(b,a,c)||ss(b,c,a)||ss(c,b,a)||ss(c,a,b)) printf("YES"); else printf("NO"); return 0; }
Topic 6:
Thematic translation
-
Give a sequence ^ a, find an operation sequence whose length does not exceed ^ 3n ^ and make each element in the sequence ^ a ^ equal.
-
Define an operation as: Select (i,j,x) triples, satisfy that i,j is the legal subscript of the sequence, X is a non negative integer within 10 ^ 9, and let ai: = ai − x ⋅ i,aj: = aj + X ⋅ i.
-
It must be ensured that every element in the sequence # a # at any time in the operation process is non negative.
-
When outputting, first output the number of operations # k, and then output the sequence of # k # lines of operations.
-
Number of data groups t ≤ 10 ^ 4, sequence length n ≤ 10 ^ 4, element size 1 ≤ ai ≤ 10 ^ 5.
Input and output samples
Enter #1 copy
3 4 2 16 4 18 6 1 2 3 4 5 6 5 11 19 1 1 3
Output #1 copy
2 4 1 2 2 3 3 -1 4 1 2 4 2 4 5 2 3 3 4 5 1
Solution:
1.a[i]: = a[i] − x ⋅ i,a[j]: = the value of a[j] + X ⋅ I, a[i]+a[j] is constant, so no matter how to operate the array, the sum is constant. The meaning of the topic is to make all values equal to the average value, then sum% n= 0
2. We can use a[1] as an article, because no matter what, each number can divide by 1. My idea is to move all values to a[1], and then divide the number equally from a[1] to each number. (step n-1)
3. How to move other numbers to a[1] (two steps at most). There are two cases. One is a[i]%i==0, which moves by itself; One is a[i]%i= 0. In this case, first borrow a[i]/i+1)*i-a[i] from a [i], and then move.
4. So the worst case is only 3 * (n-1) steps.
5. Use a number to record how many steps to take, then use a structure to store the data in the steps, and finally traverse the output.
The code is as follows:
#include"stdio.h" #include"string.h" struct node { int i; int y; int x; }d[30001]; int main() { int n,m,t,a[10009],i; scanf("%d",&n); for(m=0;m<n;m++) { int sum=0,p=0; memset(d,0,sizeof(struct node)); scanf("%d",&t);//Operation sequence with length not exceeding 3t for(i=1;i<=t;i++) { scanf("%d",&a[i]); sum+=a[i]; } if(sum%t!=0) printf("-1\n"); else { for(i=2;i<=t;i++) { if(a[i]%i!=0) { d[p].i=1,d[p].y=i,d[p].x=(a[i]/i+1)*i-a[i]; a[1]-=(a[i]/i+1)*i-a[i]; a[i]+=(a[i]/i+1)*i-a[i]; p++; } if(a[i]%i==0) { d[p].i=i,d[p].y=1,d[p].x=a[i]/i; a[1]+=a[i]; a[i]=0; p++; } } for(i=2;i<=t;i++) { d[p].i=1;d[p].y=i,d[p].x=sum/t; a[1]-=sum/t; a[i]+=sum/t; p++; } printf("%d\n",p); for(i=0;i<p;i++) printf("%d %d %d\n",d[i].i,d[i].y,d[i].x); } } return 0; }