Easy Problemset Gym100851E

来源:互联网 发布:win8能装ubuntu 编辑:程序博客网 时间:2024/06/04 18:36

**题意:**n 个裁判编号为1到n。每个裁判都准备了一定数量的难易程度为 pi 的问题。现在需要选择 k 个问题。
选择的过程如下:
每次从一个裁判地方选一个,然后n个裁判轮着选,知道选够为止。
先从第一个裁判的问题列表中从前往后选一个(如果该裁判地方已经没有问题可选了直接选难度为50的题目),如果选中的问题难易程度大于等于已选所有问题的难易程度之和,则该问题被加入比赛,否则丢弃。
然后接着在下一个裁判的问题列表里选。

思路:这题只要弄明白题目意思,剩下的就只是模拟了。

代码:

#include<cstdio>#include<cstring>#include<cstdlib>#include<stack>#include<queue>#include<utility>#include<vector>#include<cmath>#include<set>#include<map>#include<iostream>#include<algorithm>using namespace std;typedef long long LL;int n, k;vector<int> vec[11];  //保存裁判们问题的难度系数int cnt[11];  //每个裁判准备的问题数目int pos[11];  //存第i个裁判的问题列表已经处理到哪个位置了int main(){    freopen("easy.in", "r", stdin);    freopen("easy.out", "w", stdout);    while(scanf("%d%d", &n, &k) == 2){        for(int i=0; i<11; i++){            vec[i].clear();        }        memset(pos, 0, sizeof(pos));        for(int i=1; i<=n; i++){            scanf("%d", &cnt[i]);            int tmp;            for(int j=1; j<=cnt[i]; j++){                scanf("%d", &tmp);                vec[i].push_back(tmp);            }        }        int ans = 0;        while(k > 0){            for(int i=1; i<=n; i++){                if(pos[i] < cnt[i]){                    if(vec[i][pos[i]] >= ans){                        ans += vec[i][pos[i]];                        pos[i]++;                        k--;                    }                    else{                        pos[i]++;                    }                }                else{                    ans += 50;                    k--;                }                if(k == 0)break;            }        }        printf("%d\n", ans);    }    return 0;}