Problem A
A. Key racestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of scharacters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds.
If connection ping (delay) is t milliseconds, the competition passes for a participant as follows:
- Exactly after t milliseconds after the start of the competition the participant receives the text to be entered.
- Right after that he starts to type it.
- Exactly t milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game.
InputThe first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
OutputIf the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
Examplesinput5 1 2 1 2outputFirstinput3 3 1 1 1outputSecondinput4 5 3 1 5outputFriendshipNoteIn the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22milliseconds. So, it is be a draw.
水题.
1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 int main(){ 5 int s; 6 int v1,v2,t1,t2; 7 cin>>s>>v1>>v2>>t1>>t2; 8 int s1=s*v1+2*t1; 9 int s2=s*v2+2*t2; 10 if(s1==s2){ 11 cout<<"Friendship"<<endl; 12 }else if(s1>s2){ 13 cout<<"Second"<<endl; 14 }else{ 15 cout<<"First"<<endl; 16 } 17 return 0; 18 }
problem B
B. The number on the boardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSome natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
InputThe first line contains integer k (1 ≤ k ≤ 109).
The second line contains integer n (1 ≤ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
OutputPrint the minimum number of digits in which the initial number and n can differ.
Examplesinput3
11output1input3
99output0NoteIn the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
题意:找出一个数字它的每个位数的和大于等于K,并且与n的不同的位数最小。
1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 char a[100010]; 7 int cha[11]; 8 int main(){ 9 int k; 10 cin>>k; 11 scanf("%s",&a); 12 memset(cha,0,sizeof(cha)); 13 int len=strlen(a),sum=0; 14 for(int i=len-1;i>=0;i--){ 15 int xx=a[i]-'0'; 16 sum+=xx; 17 cha[xx]++; 18 } 19 if(sum>=k){ 20 cout<<0<<endl; 21 }else{ 22 int num=0; 23 bool flag=false; 24 for(int i=0;i<9;i++){ 25 for(int j=cha[i];j>0;j--){ 26 sum+=(9-i); 27 num++; 28 if(sum>=k){ 29 flag=true; 30 break; 31 } 32 } 33 if(flag) break; 34 } 35 cout<<num<<endl; 36 } 37 }