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. OLAP在大数据时代的挑战

    转行做数据相关的工作有近两年时间,除了具体技术,还有许多其它思考. 数据的价值 在涉及具体的技术前,先想一想为什么需要OLAP这样的系统,它有什么价值或者说在公司或部门这是不可取代的么? 可以带来哪些 ...

  2. PHP 常用的header头部定义汇总

    <?phpheader('HTTP/1.1 200 OK'); // ok 正常访问header('HTTP/1.1 404 Not Found'); //通知浏览器 页面不存在header(' ...

  3. 多个Excel文件快速导入到DB里面

    1 . 文件比较多,需要把这么多的数据都导入到DB里面,一个个导入太慢了,能想到的是先把数据整个到一个Excel中,然后再导入 2. 第一步准备合并Excel,新建一个新的excel,命名为total ...

  4. python httprequest, locust

    r = self.client.get("/orders", headers = {"Cookie": self.get_user_cookie(user[0] ...

  5. 安装springboot时遇到 LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.问题

    将工程外部jar包删除slf4j就可以运行.

  6. delphi 弹出选择目录窗口

    if not SelectDirectory( '请选择输出文件路径','/',directory) then begin Exit; end; 使用SelectDirectory函数注意要在use下 ...

  7. Selenium 功能总结大集合

    slenium自动化测试的一个利器: 总结了部分功能,成图,方便学习: 这是一张大图,大家看起来可能比较麻烦: 可以在我的github下载:selenium大图.xmind格式

  8. 初识Redis(1)

    Redis 是一款依据BSD开源协议发行的高性能Key-Value存储系统(cache and store). 它通常被称为数据结构服务器,因为值(value)可以是 字符串(String), 哈希( ...

  9. CSS深入理解之overflow

    CSS深入理解之overflow 前言 这是跟着张鑫旭重学CSS的overflow篇 基本属性 overflow有以下五个基本属性: 1.visible : 默认值,具体表现为,应用此属性后,子元素超 ...

  10. synchronized四要素及抽象

    面向对象,java的核心思想就是面向对象编程,以贴近人类在现实生活中的思考方式,任何事物我们都会把它抽象成一个对象,一辆车,一个人,对象是我们思考的基石. 我想说的是,我们写汉字的时候,不会在脑海中命 ...