RCC 2014 Warmup (Div. 2) 蛋疼解题总结

A. Elimination
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output


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 leastn·m people go to the finals, and the total amount of used problems in all rounds is as small as possible.

Input

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.

Output

In the first line, print a single integer — the minimum number of problems the jury needs to prepare.

Sample test(s)
input
1 10
7 2
1
output
2
input
2 2
2 1
2
output
0

题意:为了进final举办淘汰赛,赛制有两种,一种是取前n个人晋级,需要用c个题目,另一种是取第一名需要c个题目,每次比赛都会特别邀请k个人,问选m*n个人最少

用多少题目。

sl: 没有更水的了,可惜开始没读懂题。对于最后余下的不足n的人数只要比较left*d和c的大小就好了, 其余的比较n*d和c的大小就好了。

  1 #include<cstdio>

 2 #include<cstring>
 3 #include<algorithm>
 4 #include<vector>
 5 #include<queue>
 6 using namespace std;
 7 const int MAX = 1e3+10;
 8 int main()
 9 {
10     int c,d,n,m,k; int ans;
11     while(scanf("%d %d",&c,&d)==2)
12     {
13         ans=0;
14         scanf("%d %d",&n,&m); scanf("%d",&k);
15         int tot=n*m-k;
16         if(tot<=0) printf("0 ");
17         else
18         {
19             int x=tot/m; int cnt=tot/n; int cc=tot%n;
20             if(n*d<=c) ans=n*cnt*d;
21             else ans=c*cnt;
22             if(cc*d<c) ans+=cc*d;
23             else ans+=c;
24             printf("%d ",ans);
25         }
26 
27     }
28     return 0;
29 }

B. Crash
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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 ≤ 1051 ≤ k ≤ 105) — the number of previous unique solutions and the identifier of the participant.

Output

A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.

Sample test(s)
input
2
0 1
1 1
output
YES
input
4
0 1
1 2
1 1
0 2
output
NO
input
4
0 1
1 1
0 1
0 2
output
YES

 题意:就是给出每个人的编号和提交顺序,问是不是按时间顺序给出的(每个人的代码号都是从0开始递增的和别人无关)

sl:根据题意只要判断每个人的代码号书不是在前面出现过,没出现过的话直接判断是不是跟上一个数字连续就行。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<vector>
 5 #include<queue>
 6 #include<set>
 7 using namespace std;
 8 const int MAX = 1e5+10;
 9 vector<int> G[MAX];
10 set<int> cnt[MAX];
11 int main()
12 {
13     int n;    int x,k;
14     while(scanf("%d",&n)==1)
15     {
16         int flag=1;
17         for(int i=0;i<n;i++)
18         {
19             scanf("%d %d",&x,&k);
20             int m=G[k].size();
21             if(!m)
22             {
23                 if(x==0) G[k].push_back(x),cnt[k].insert(x);
24                 else flag=0,G[k].push_back(x),cnt[k].insert(x);
25             }
26             else if(cnt[k].count(x)) continue;
27             else if(G[k][m-1]==x-1) G[k].push_back(x),cnt[k].insert(x);
28             else flag=0;
29         }
30         if(flag) printf("YES ");
31         else printf("NO ");
32     }
33     return 0;

34 } 

C. Football
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n 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.

Input

The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).

Output

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 ≤ nai ≠ 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 from 1 to n.

If a tournir that meets the conditions of the problem does not exist, then print -1.

Sample test(s)
input
3 1
output
3
1 2
2 3
3 1

 题意:有n个小组,每个小组要进行k场比赛并且每次只能和对手比一场,给出对战表。

sl:可以暴力过,也可以两个for循环过。(当时着急了直接暴力做的10min1Y)

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<vector>
 5 #include<queue>
 6 using namespace std;
 7 const int MAX = 1e3+10;
 8 int vis[MAX][MAX],ans[MAX];
 9 vector<int> G[MAX];
10 int main()
11 {
12     int n,k,tot;
13     while(scanf("%d %d",&n,&k)==2)
14     {
15         tot=0;
16         memset(vis,0,sizeof(vis));
17         memset(ans,0,sizeof(ans));
18         for(int i=1;i<=n;i++)
19         {
20             for(int j=1;j<=n;j++) if(i!=j)
21             {
22                 if(ans[i]==k) break;
23                 if(!vis[i][j])
24                 {
25                     tot++;
26                     vis[i][j]=vis[j][i]=1;
27                     ans[i]++;
28                     G[i].push_back(j);
29                 }
30             }
31         }
32         int flag=1;
33         for(int i=1;i<=n;i++) if(ans[i]!=k) flag=0;
34         if(!flag) printf("-1 ");
35         else
36         {
37             printf("%d ",tot);
38             for(int i=1;i<=n;i++) for(int j=0;j<G[i].size();j++)
39             printf("%d %d ",i,G[i][j]);
40         }
41     }
42     return 0;

43 } 

D. Cunning Gena
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they will solve the problems for him.

The participants are offered m problems on the contest. For each friend, Gena knows what problems he can solve. But Gena's friends won't agree to help Gena for nothing: the i-th friend asks Gena xi rubles for his help in solving all the problems he can. Also, the friend agreed to write a code for Gena only if Gena's computer is connected to at least ki monitors, each monitor costs b rubles.

Gena is careful with money, so he wants to spend as little money as possible to solve all the problems. Help Gena, tell him how to spend the smallest possible amount of money. Initially, there's no monitors connected to Gena's computer.

Input

The first line contains three integers nm and b (1 ≤ n ≤ 1001 ≤ m ≤ 201 ≤ b ≤ 109) — the number of Gena's friends, the number of problems and the cost of a single monitor.

The following 2n lines describe the friends. Lines number 2i and (2i + 1) contain the information about the i-th friend. The 2i-th line contains three integers xiki and mi (1 ≤ xi ≤ 1091 ≤ ki ≤ 1091 ≤ mi ≤ m) — the desired amount of money, monitors and the number of problems the friend can solve. The (2i + 1)-th line contains mi distinct positive integers — the numbers of problems that the i-th friend can solve. The problems are numbered from 1 to m.

Output

Print the minimum amount of money Gena needs to spend to solve all the problems. Or print -1, if this cannot be achieved.

Sample test(s)
input
2 2 1
100 1 1
2
100 2 1
1
output
202
input
3 2 5
100 1 1
1
100 1 1
2
200 1 2
1 2
output
205
input
1 2 1
1 1 1
1
output
-1

 题意:有m个问题,同时有n个人每个人能解决mi个问题,雇佣这个人花xi元,并且这个人需要ki个显示器,每个显示器b元。问解决m个问题最少花费多少钱

sl:看上去有点想背包。可以把问题个数想成背包容量,就是一个0-1背包。需要按显示器的个需求排序,因为同样解决m个问题用的显示器越少越好么。

状态方程  dp[state|cover]=min(dp[state|cover],dp[state]+x);

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 typedef long long LL;
 6 const int MAX = 1<<21;
 7 const LL inf = 1LL<<62;
 8 struct P
 9 {
10     int x,k,m;
11     int cover;
12     bool operator < (const P &rhs) const
13     {
14         return k<rhs.k;
15     }
16 } v[300];
17 LL dp[MAX];
18 int main()
19 {
20     int n,m,b; int a;
21     while(scanf("%d %d %d",&n,&m,&b)==3)
22     {
23         for(int i=0;i<n;i++)
24         {
25             scanf("%d %d %d",&v[i].x,&v[i].k,&v[i].m); v[i].cover=0;
26             for(int j=0;j<v[i].m;j++)
27             {
28                 scanf("%d",&a); v[i].cover|=(1<<(a-1));
29             }
30         }
31 
32         sort(v,v+n);
33         for(int j=0;j<=(1<<m)-1;j++) dp[j]=inf;
34         dp[0]=0;
35 
36         LL ans=inf;
37         for(int i=0;i<n;i++)
38         {
39             for(int j=((1<<m)-1);j>=0;j--)
40             {
41                 dp[j|v[i].cover]=min(dp[j|v[i].cover],dp[j]+v[i].x);
42             }
43             if(dp[(1<<m)-1]!=inf)
44             ans=min(ans,dp[(1<<m)-1]+(LL)v[i].k*(LL)b);
45 
46         }
47         if(ans>=inf) printf("-1 ");
48         else printf("%I64d ",ans);
49     }
50     return 0;

51 }

E. Square Table
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size n × m, consisting of positive integers such that the sum of the squares of numbers for each row and each column was also a square.

Since checking the correctness of the table manually is difficult, Misha asks you to make each number in the table to not exceed 108.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100)  — the size of the table.

Output

Print the table that meets the condition: n lines containing m integers, separated by spaces. If there are multiple possible answers, you are allowed to print anyone. It is guaranteed that there exists at least one correct answer.

Sample test(s)
input
1 1
output
1
input
1 2
output
3 4

 题意:很鸟蛋的一体,就是给出矩阵的行列,叫你给出一个矩阵,满足每一行的平方和仍然是某一个数的平方。每一列的平方和仍然是某一个数的平方。

sl:数学构造了,看了下别人的题解都是千奇百怪的,都很神奇有一个是这么写的

先构造出一个一维的长度为n的序列在用同样的方法构造出长度为m的序列 然后用长度为n的每一个元素去乘 长度为m的每个元素

构造出n*m个数字。

构造方法是:前n-1个(m个)数字为2最后一个是(n-2)(或 (m-2)) 可以证明确实正确。

附别人题解报告一份。

 http://codeforces.com/contest/417/submission/6398158

原文地址:https://www.cnblogs.com/acvc/p/3673557.html