UVALive-7470-Easy Problemset(模拟)
来源:互联网 发布:python for loop 编辑:程序博客网 时间:2024/04/29 04:52
Perhaps one of the hardest problems of any ACM ICPC contest is to create a problemset with a
reasonable number of easy problems. On Not Easy European Regional Contest this problem is solved
as follows.
There are n jury members (judges). They are numbered from 1 to n. Judge number i had prepared
pi easy problems before the jury meeting. Each of these problems has a hardness between 0 and 49 (the
higher the harder). Each judge also knows a very large (say infinite) number of hard problems (their
hardness is 50). Judges need to select k problems to be used on the contest during this meeting.
They start to propose problems in the ascending order of judges numbers. The first judge takes the
first problem from his list of remaining easy problems (or a hard problem, if he has already proposed all
his easy problems) and proposes it. The proposed problem is selected for the contest if its hardness
is greater than or equal to the total hardness of the problems selected so far, otherwise it
is considered too easy. Then the second judge does the same etc.; after the n-th judge, the first one
proposes his next problem, and so on. This procedure is stopped immediately when k problems are
selected.
If all judges have proposed all their easy problems, but they still have selected less than k problems,
then they take some hard problems to complete the problemset regardless of the total hardness.
Your task is to calculate the total hardness of the problemset created by the judges.
Input
The input file contains several test cases, each of them as described below.
The first line of the input file contains the number of judges n (2 ≤ n ≤ 10) and the number of
problems k (8 ≤ k ≤ 14). The i-th of the following n lines contains the description of the problems
prepared by the i-th judge. It starts with pi (1 ≤ pi ≤ 10) followed by pi non negative integers between
0 and 49 — the hardnesses of the problems prepared by the i-th judge in the order they will be proposed.
Output
For each test case, output a only integer — the total hardness of the selected problems — on a line by
itself.
Note:
In the first example, three problems with hardnesses of 0, 1, and 1 are selected first. Then the
first judge proposes the problem with hardness 3 and it is selected, too. The problem proposed by
the second judge with hardness 1 is not selected, because it is too easy. Then the problems proposed
by the third, the first, and the second judges are selected (their hardnesses are 5, 12 and 23). The
following three proposed problems with hardness of 17, 1 and 20 are not selected, and the problemset
is completed with a problem proposed by the third judge with hardness of 49. So the total hardness of
the problemset is 94.
In the second example, three problems with hardnesses of 1, 1, and 2 are selected first. The second
problem of the first judge (hardness 3) is too easy. The second judge is out of his easy problems, so he
proposes a problem with hardness 50 and it is selected. The third judge’s problem with hardness 5 is
not selected. The judges decide to take 6 more hard problems to complete the problemset, which gives
the total hardness of 54 + 6·50 = 354.
Sample Input
3 8
5 0 3 12 1 10
4 1 1 23 20
4 1 5 17 49
3 10
2 1 3
1 1
2 2 5
Sample Output
94
354
题意:多组数据,第一行给出N,K,代表接着有N行,总共需要选取K个数。接着N行每行第一个数字为P,代表后面有P个数字。接着从上往下从左往右选数,只有当所选数总和小于等于待选数时,才可以选择待选数,如果当前位置空着,那么就把当前位置数值看成50,如果最后数不够选,那么全部用50补齐。输出最终选择数的总和
代码
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<queue>#include<string.h>#include<math.h>using namespace std;const int maxn=15;int num[maxn][maxn];int main(){ int N;//行数 int K; while(~scanf("%d%d",&N,&K)) { memset(num,-1,sizeof(num)); int max_p=22;//最大列数 for(int i=1; i<=N; i++) //建图 { int P; scanf("%d",&P); max_p=max(max_p,P); for(int j=1; j<=P; j++) scanf("%d",&num[i][j]); } int num_k=0;//已经找到的数量 int sum=0;//已经找到的总和 for(int j=1; j<=max_p&&num_k!=K; j++) { for(int i=1; i<=N&&num_k!=K; i++) { if(num[i][j]!=-1) { if(num[i][j]>=sum) { num_k++; sum+=num[i][j]; } } else { if(sum<=50) { num_k++; sum+=50; break; } } if(num_k==K) break; } } if(K>num_k) sum=sum+(K-num_k)*50; printf("%d\n",sum); } return 0;}
- UVALive-7470-Easy Problemset(模拟)
- 【模拟】NEERC15 E Easy Problemset (Codeforces GYM 100851)
- Easy Problemset Gym100851E
- LightOJ - 1374 Confusion in the Problemset (模拟)
- UVALive 6833Miscalculation (模拟)
- uvalive 4254(二分+模拟)
- UVALive 7139 Rotation(模拟)
- UVALive 4264 Message (模拟)
- UVALive - 4264 Message (模拟)
- UVALive 3667 Ruler (模拟)
- UVALive 4222 Dance(模拟)
- Appearance Analysis UVALive(模拟)
- So Easy!!! (栈模拟)
- UVALive 4290 Easy Climb(dp + 精简状态 + 优先队列)
- UVALive 6089 Nine (暴力模拟)
- UVaLive/LA 6805 Pantun Grader(模拟)
- UVALive 6832Bit String Reordering (模拟)
- UVALive 7146 Defeat the Enemy(模拟)
- scrollview中嵌套高德地图,触摸冲突解决
- 导航栏背景颜色,字体颜色
- POJ 3783 Balls(扔鸡蛋问题——DP动态规划)
- 【安卓开发】Android系统中Parcelable和Serializable的区别
- 怎么通过CorelDRAW创建斜角效果
- UVALive-7470-Easy Problemset(模拟)
- Linux各版本root本地密码破解方法
- Android常用的物理按键及其触发事件
- ListView多选操作模式详解CHOICE_MODE_MULTIPLE与CHOICE_MODE_MULTIPLE_MODAL
- SHELL 中分界符(EOF)的用法
- XML解析之DOM4J
- C#入门2.1——C#程序结构
- Py2与Py3和谐共处
- 用lipo合并模拟器Framework与真机Framework【转载】