cf(417A,B,C)
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.
The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination.
As a result of all elimination rounds at least n·m people should go to the finals. You need to organize elimination rounds in such a way, that at least n·m people go to the finals, and the total amount of used problems in all rounds is as small as possible.
The first line contains two integers c and d (1 ≤ c, d ≤ 100) — the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≤ n, m ≤ 100). Finally, the third line contains an integer k(1 ≤ k ≤ 100) — the number of the pre-chosen winners.
In the first line, print a single integer — the minimum number of problems the jury needs to prepare.
1 10 7 2 1
2
2 2 2 1 2
0
#include <iostream> #include <stdio.h> #include <stdlib.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; int a[200010]; int main() { int c,d,n,m,k; cin>>c>>d>>n>>m>>k; int tem=n*m-k; if(tem<=0){cout<<0<<endl;} else { if((double)c/(double)n<(double)d) { int t=tem/n,sheng=tem-t*n,hh=sheng*d; if(hh<c) cout<<c*t+hh<<endl; else cout<<c*t+c<<endl; }else cout<<tem*d<<endl; } return 0; }
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x — the number of different solutions that are sent before the first solution identical to A, and k — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
The first line of the input contains an integer n (1 ≤ n ≤ 105) — the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 ≤ x ≤ 105; 1 ≤ k ≤ 105) — the number of previous unique solutions and the identifier of the participant.
A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.
2 0 1 1 1
YES
4 0 1 1 2 1 1 0 2
NO
4 0 1 1 1 0 1 0 2
YES
题目读不懂是硬伤T_T!!!!巨简单的水题目读不懂都成了超级难题T_T。。。。。
#include <iostream> #include <stdio.h> #include <stdlib.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; int a[100010]; int main() { memset(a,-1,sizeof(a)); int n,flag=0; cin>>n; for(int i=0;i<n;i++) { int x,k; cin>>x>>k; if(a[k]+1<x) flag=1; a[k]=max(a[k],x); } if(flag)cout<<"NO"<<endl; else cout<<"YES"<<endl; return 0; }
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided inton teams and played several matches, two teams could not play against each other more than once.
The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.
Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.
The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).
In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from1 to n.
If a tournir that meets the conditions of the problem does not exist, then print -1.
3 1
3 1 2 2 3 3 1
模拟题,每个队赢了对手k场,让我们模拟输出。。。不过并不是一定每两个队都有比赛,两个队之间可能比赛也可能不比赛,当然最多也就只有n*(n-1)/2场比赛咯
#include <iostream> #include <stdio.h> #include <stdlib.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; int a[2010]; int main() { int n,k; cin>>n>>k; if((n*(n-1))/2>=n*k) { cout<<n*k<<endl; for(int i=1;i<=n;i++) a[i]=i; for(int i=n+1;i<=2*n;i++) a[i]=a[i-n]; int s=2,e=1+k; for(int i=1;i<=n;i++) { for(int j=s;j<=e;j++) printf("%d %d\n",i,a[j]); s++,e++; } } else printf("-1\n"); return 0; }