【CodeForces 730H】Car Repair Shop
BUPT 2017 summer training (for 16) #1F
题意
依次有n (1 ≤ n ≤ 200) 个车要修理,每个车希望在s[i]时刻开始修理,时长d[i],如果s[i]后面没有那么多空的时间,那么就选最小的可行的起点。\(s_i, d_i (1 ≤ s_i ≤ 10^9, 1 ≤ d_i ≤ 5·10^6)\)
题解
模拟,先看从s[i]时刻开始修理,和之前i-1个是否冲突。如果冲突,就枚举每个s[j]+d[j]时刻开始,看是否冲突,再从中选择最小的时刻。
代码
#include <cstdio>
#include <algorithm>
#define N 201
#define inf 0x3f3f3f3f
using namespace std;
int n;
int s[N],d[N];
bool ck(int i,int j){
return s[j]>s[i]+d[i]-1 || s[i]>s[j]+d[j]-1;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d%d",&s[i],&d[i]);
for(int i=1;i<=n;++i){
bool fromS=true;
for(int j=1;j<i;++j)
if(!ck(i,j))
fromS=false;
if(!fromS){
int ss=inf;
for(int j=0;j<i;++j){
s[i]=s[j]+d[j]+(j==0);
bool valid=true;
for(int k=1;k<i;++k)
valid&=ck(i,k);
if(valid) ss=min(s[i],ss);
}
s[i]=ss;
}
printf("%d %d\n",s[i],s[i]+d[i]-1);
}
return 0;
}
【CodeForces 730H】Car Repair Shop的更多相关文章
- 【CodeForces 730H】Delete Them
BUPT 2017 summer training (for 16) #1E 题意 找到匹配要删除的文件名们但不匹配其它文件名们的表达式.其中?匹配所有字符,其它字符匹配本身. 题解 如果某个位置出现 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【20.23%】【codeforces 740A】Alyona and copybooks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【15.07%】【codeforces 625A】Guest From the Past
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【codeforces 546A】Soldier and Bananas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 762B】USB vs. PS/2
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
随机推荐
- Really Big Numbers CodeForces - 817C (数学规律+二分)
C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Day1 Numerical simulation of optical wave propagation之标量衍射理论基本原理(一)
<Numerical simulation of optical wave propagation>内容 1. 介绍光波传输的基础理论.离散采样方法.基于MATLAB平台的编码实例以及具 ...
- spring security运行流程图(转)
原文:http://blog.csdn.net/u011511684/article/details/31394493 示例下载地址:http://download.csdn.net/detail/u ...
- git rebase的用法
改变基 一个git库,开发人员在master分支的Bcommit的时候,创建了一个dev分支,此时Bcommit是dev分支的基,然后分别进行两个分支的开发. 进行到master提交了Dcommit, ...
- Alibaba Cloud Toolkit for Eclipse & ECS、EDAS 或容器服务 Kubernetes
UserGuide_V2.1.0http://toolkit.aliyun.com/eclipse/?spm=5176.2020520130.105.3.3c3b697bOHma9f&msct ...
- C语言操作WINDOWS系统存储区数字证书相关函数详解及实例
C语言操作WINDOWS系统存储区数字证书相关函数详解及实例 以下代码使用C++实现遍历存储区证书及使用UI选择一个证书 --使用CertOpenSystemStore打开证书存储区. --在循环中 ...
- [官网]How to use distributed transactions with SQL Server on Docker
How to use distributed transactions with SQL Server on Docker https://docs.microsoft.com/en-us/sql/l ...
- Setting property 'source' to 'org.eclipse.jst.jee.server:hczm' did not find a matching property
- 极验3.0滑动拼图验证的使用--java
[ 前言: 在登录其他网站的时候,看到有个滑动拼图的验证觉得挺好玩的,以前做一个图片验证的小demo,现在发现很多网站都开始流行滑动拼图的验证了,今天也想自己动手来弄一个. 废话不多说,开始撸起来! ...
- linux pstree命令
pstree命令可以使进程以tree的形式显示 pstree -ssystemd─┬─UVPHostd───6*[{UVPHostd}] ├─acpid ├─2*[agetty] ├─crond ├─ ...