码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 747C:Servers(模拟)

时间:2016-12-31 22:50:40      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:eof   blank   tar   ring   时间   nbsp   ++   memcpy   操作   

http://codeforces.com/problemset/problem/747/C

题意:有n台机器,q个操作。每次操作从ti时间开始,需要ki台机器,花费di的时间。每次选择机器从小到大开始,如果可以完成任务,那么输出id总和,否则输出-1.

思路:简单的模拟,注意如果不能完成任务,那么ser数组是不能更新的。

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <cstring>
 5 #include <string>
 6 #include <cmath>
 7 #include <queue>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 using namespace std;
12 #define INF 0x3f3f3f3f
13 #define N 100010
14 typedef long long LL;
15 int t[N], d[N], k[N];
16 LL ser[105], tmp[105];
17 
18 int main() {
19     int n, q, k, t, d;
20     memset(ser, 0, sizeof(ser));
21     memset(tmp, 0, sizeof(tmp));
22     cin >> n >> q;
23     for(int i = 1; i <= q; i++) {
24         scanf("%d%d%d", &t, &k, &d);
25         int cnt = 0, ans = 0;
26         memcpy(tmp, ser, sizeof(tmp));
27         for(int j = 1; j <= n && cnt < k; j++) {
28             if(tmp[j] <= t) {
29                 cnt++; tmp[j] = t + d;
30                 ans += j;
31             }
32         }
33         if(cnt < k) {
34             printf("-1\n");
35         } else {
36             memcpy(ser, tmp, sizeof(ser));
37             printf("%d\n", ans);
38         }
39     }
40     return 0;
41 }

 

Codeforces 747C:Servers(模拟)

标签:eof   blank   tar   ring   时间   nbsp   ++   memcpy   操作   

原文地址:http://www.cnblogs.com/fightfordream/p/6240395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!