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的更多相关文章

  1. 【CodeForces 730H】Delete Them

    BUPT 2017 summer training (for 16) #1E 题意 找到匹配要删除的文件名们但不匹配其它文件名们的表达式.其中?匹配所有字符,其它字符匹配本身. 题解 如果某个位置出现 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【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 ...

  5. 【codeforces 546A】Soldier and Bananas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【codeforces 762B】USB vs. PS/2

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

  7. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  8. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  9. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

随机推荐

  1. c++ 入门之深入探讨拷贝函数和内存分配

    在c++入门之深入探讨类的一些行为时,说明了拷贝函数即复制构造函数运用于如下场景: 对象作为函数的参数,以值传递的方式传给函数. 对象作为函数的返回值,以值的方式从函数返回 使用一个对象给另一个对象初 ...

  2. [options] 未与 -source 1.6 一起设置引导类路径

    用ant与eclipse编译Cassandra 1.2.19,出现了“ [options] 未与 -source1.6一起设置引导类路径”的警告,并出现了一些编译错误,提示编译失败,上网找了很 多资料 ...

  3. Servlet 转发请求与重定向,以及路径问题

    转发请求 当一个servlet接收到请求后,如果需要将请求转发给另外一个servlet或者jsp文件,可使用下面这种方法: package cn.ganlixin.servlet; import ja ...

  4. Java Core - Class文件结构之魔数、版本号、常量池

    下图是一个.java文件被编译器编译后产生的二进制的class文件的内容:由图可知,class文件是用两位16进制数来表示的一个字节. 1个字节就是1Byte,1Byte=8bit. 一.魔数(CAF ...

  5. 【转】Docker部署Tomcat及Web应用

    Docker部署Tomcat及Web应用 - Scofield_No1的博客 - CSDN博客https://blog.csdn.net/qq_32351227/article/details/786 ...

  6. MySQL数据库性能优化思路与解决方法(二转)

    原文:http://bbs.landingbj.com/t-0-242512-1.html 1.锁定表 尽管事务是维护数据库完整性的一个非常好的方法,但却因为它的独占性,有时会影响数据库的性能,尤其是 ...

  7. [转帖]PAT 计算机程序设计能力考试

    PAT 计算机程序设计能力考试 https://blog.csdn.net/bat67/article/details/52134211 [官方简介] 计算机程序设计能力考试(Programming ...

  8. Linux(CentOS7)命令学习摘要

    1. 修改机器名 hostnamectl set-hostname newname 2. hosts主机存放位置 /etc/hosts 3. 安装tigervncserver, 然后使用vncserv ...

  9. mybatis源码分析(四)---------------代理对象的生成

    在mybatis两种开发方式这边文章中,我们提到了Mapper动态代理开发这种方式,现在抛出一个问题:通过sqlSession.getMapper(XXXMapper.class)来获取代理对象的过程 ...

  10. shell expr用法

    expr 计算整数变量值 使用方法如下: linux-zpycfm:/home/test/shell # s=+ -bash: +: command not found linux-zpycfm:/h ...