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

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

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

 #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define INF 0x3f3f3f3f
#define N 100010
typedef long long LL;
int t[N], d[N], k[N];
LL ser[], tmp[]; int main() {
int n, q, k, t, d;
memset(ser, , sizeof(ser));
memset(tmp, , sizeof(tmp));
cin >> n >> q;
for(int i = ; i <= q; i++) {
scanf("%d%d%d", &t, &k, &d);
int cnt = , ans = ;
memcpy(tmp, ser, sizeof(tmp));
for(int j = ; j <= n && cnt < k; j++) {
if(tmp[j] <= t) {
cnt++; tmp[j] = t + d;
ans += j;
}
}
if(cnt < k) {
printf("-1\n");
} else {
memcpy(ser, tmp, sizeof(ser));
printf("%d\n", ans);
}
}
return ;
}

Codeforces 747C:Servers(模拟)的更多相关文章

  1. 【50.00%】【codeforces 747C】Servers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  3. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  4. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  5. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  6. Codeforces 679B. Barnicle 模拟

    B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...

  7. CodeForces 382C【模拟】

    活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...

  8. codeforces 719C (复杂模拟-四舍五入-贪心)

    题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑...

  9. CodeForces 705C Thor (模拟+STL)

    题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...

随机推荐

  1. uedit修改文件上传路劲,支持api文件接口

    首先修改一个东西ueditor/ueditor.config.js serverUrl: URL + "php/controller.php" 原来 serverUrl: &quo ...

  2. C指针-const char* p到底是什么不可以改变

    char a = 'w'; char b = 'q'; const char* p = &a; p = &b; printf("%c",p[0]); 如上一段代码, ...

  3. MySQL(无GUI) Windows安装和启动

    1.在官网http://dev.mysql.com/downloads/下载 MySQL Community Server 2.解压后是这个样子: 3.找到cmd,并且用管理员权限启动,必须!不然那没 ...

  4. 利用JavaScript生成随机数字!

    <!DOCTYPE html> <html> <head> <title>1-99的随机数字</title> <script type ...

  5. RSA+DES动态加密

    RSA可以用于加密,其加密强度很高,被人攻克的可能性极小.但是其加密速度很慢,如果对一段长数据进行加密是不现实的.因为无论加密还是解密都需要很长时间.所以通常是先用对称加密算法(DES, AES等)对 ...

  6. Spring整理

    Bean配置 1. <context:component-scan base-package="com.test" />这个包下的Spring注解才有效 属性文件自动解 ...

  7. ECMAScript 5中的数据属性和访问器属性

    简介 ECMAScript 定义的对象中有两种特殊的属性, 这两种特殊的属性在你定义对象属性时就会赋予, 我们在必要时可以改写这两种特殊的属性让其属性的访问更加的合理化, 这两种特殊的属性称呼及作用如 ...

  8. .net DropDownList静态联动

    1.前台 <span id="spnClient" style="margin-left: 30px; margin-top: 10px"> < ...

  9. pypi上传库

    把程序打包上传到PyPi版本库中 转自 1 首先必须要按照以下文件结构 ├── douban │   ├── cli.py │   ├── douban.py │   ├── douban_token ...

  10. jee websocket搭建总结

    1.使用框架spring+springmvc+mybatis+jdk7+tomcat7+maven 2.基本原理: a. WebSocket协议是一种双向通信协议,它建立在TCP之上,同http一样通 ...