coderforces #387 Servers(模拟)
Servers
2 seconds
256 megabytes
standard input
standard output
There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n.
It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to perform it, and di — the time needed to perform this task in seconds. All ti are distinct.
To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored.
Write the program that determines which tasks will be performed and which will be ignored.
The first line contains two positive integers n and q (1 ≤ n ≤ 100, 1 ≤ q ≤ 105) — the number of servers and the number of tasks.
Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≤ ti ≤ 106, 1 ≤ ki ≤ n, 1 ≤ di ≤ 1000) — the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.
Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.
4 3
1 3 2
2 2 1
3 4 3
6
-1
10
3 2
3 2 3
5 1 2
3
3
8 6
1 3 20
4 2 1
6 5 5
10 1 1
15 3 6
21 8 8
6
9
30
-1
15
36
In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10).
In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
【分析】可能有更简单的方法吧,我这个方法比较笨,直接循环模拟时间(天数)。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 10000000000000
#define met(a,b) memset(a,b,sizeof a)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
using namespace std;
const int N = 1e6+;
const int M = 4e5+;
int n,m,k,tot=;
struct man{
int k,d;
}a[N];
int main()
{
//int vis[1000000];
int mark[];
met(mark,);
int s,t,t1,t2,p,dir;
scanf("%d%d",&n,&m);
while(m--){
scanf("%d%d%d",&s,&t,&t1); a[s].k=t;a[s].d=t1;
}
tot=n;
for(int i=;i<=;i++){
//if(i==15)printf("!!!%d\n",a[15].k);
//printf("i=%d\n",i);
if(!a[i].k){
tot=;
for(int j=;j<=n;j++){
if(mark[j])mark[j]--;
if(mark[j]<)tot++;
//printf("#%d\n",j,mark[j]);
}
continue;
}
//printf("!!!%d %d\n",i,tot);
if(tot<a[i].k){
printf("-1\n");
tot=;
for(int j=;j<=n;j++){
if(mark[j])mark[j]--;
if(mark[j]<)tot++;
//printf("#%d\n",j,mark[j]);
}
continue;
}
else {
tot=;
p=a[i].k;
int sum=;
for(int j=;j<=n;j++){ if(mark[j]==&&p!=){
mark[j]=a[i].d;
sum+=j;
p--;
}
if(mark[j])mark[j]--;
if(mark[j]<)tot++;
}
printf("%d\n",sum);
}
}
return ;
}
coderforces #387 Servers(模拟)的更多相关文章
- Codeforces 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
- CoderForces 518C Anya and Smartphone (模拟)
题意:给定一个手机,然后一共有 n 个app,告诉你每个屏幕最多放 k 个,现在要你运行 m 个app,每次都从第一个屏幕开始滑动,每运行一个,它就和前一个交换位置,第一个就不换了,现在问你要滑动多少 ...
- AC日记——神奇的幻方 洛谷 P2615(大模拟)
题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...
- sendmessage()模拟鼠标点击
{鼠标软模拟:好处就是不会真的移动鼠标 开始按钮 坐标 x=386y=387 }sendmessage(hookHwnd,messages.WM_LBUTTONDOWN ,0,$0180017A); ...
- UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据
题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...
- 使用Java函数接口及lambda表达式隔离和模拟外部依赖更容易滴单测
概述 单测是提升软件质量的有力手段.然而,由于编程语言上的支持不力,以及一些不好的编程习惯,导致编写单测很困难. 最容易理解最容易编写的单测,莫过于独立函数的单测.所谓独立函数,就是只依赖于传入的参数 ...
- 模拟实现ATM+购物商城程序
流程图: 需求: ATM:模拟实现一个ATM + 购物商城程序额度 15000或自定义实现购物商城,买东西加入 购物车,调用信用卡接口结账可以提现,手续费5%支持多账户登录支持账户间转账记录每月日常消 ...
- RHCE-EXAM 模拟题目
真实考试环境说明: 你考试所用的真实物理机器会使用普通账号自动登陆,登陆后,桌面会有两个虚拟主机图标,分别是system1和system2.所有的考试操作都是在system1和system2上完成.S ...
- HDU 3269 P2P File Sharing System(模拟)(2009 Asia Ningbo Regional Contest)
Problem Description Peer-to-peer(P2P) computing technology has been widely used on the Internet to e ...
随机推荐
- Extjs4 -- Ext.loader命名空间的配置
初次使用extjs4的版本,在配置学习Ext.Loader()进行js文件的动态加载机制,由于各种原因导致多次失败,纠结2天,现将解决时出现的问题及需要注意事项进行记录 开发环境myeclipse8. ...
- 在easyui的treeGrid中添加checkbox(jquery)
jsp界面,也可用在aspx.html等前台界面中: <script type="text/javascript"> function show(checkid){ v ...
- android 解析XML 工具类
/** * Created by John on 2016/3/29. */ public class XmlParser { private static final String ns = nul ...
- string的实现
面试常常用到string类的实现,自己总结了一下: #pragma once #include <iostream> #include <cassert> #include & ...
- extjs之apply
ext.apply(Ext.Form.VTypes,{}) {}里面的内容如下: { password:function (val.field) { if(field.initialPassField ...
- local认证
文件路径 用途 示例 备注 #gedit /usr/local/etc/raddb/sites-available/default #gedit /usr/local/etc/raddb/sites- ...
- 重读高程3: c2-3 script元素
1. 异步脚本一定会在页面的load事件前执行,但可能会在domC ontentLoaded事件触发之前或者之后执行.
- ios 开发中 动态库 与静态库的区别
使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...
- 查看数据库中没有进行comment的字段
为落实数据库规范,既每个表字段都需要有comment注释,所以需要过滤生产表中没有comment的字段,搜索出还不错的过滤语句 show full columns from table where C ...
- 简述Git(Linux、Android~~开源)
Git——源代码管理软件,Android及Linux内核,驱动开发的过程中涉及的大量的源代码,都由Git管理 (一)安装Git Ubuntu Linux10.10或更新的版本,使用下面命令来安装Git ...