题意:给定 n 个工作的最好开始时间,和持续时间,现在有两种方法,第一种,如果当前的工作能够恰好在最好时间开始,那么就开始,第二种,如果不能,那么就从前找最小的时间点,来完成。

析:直接暴力,每次都先去看看能不能在最好时间完成,如果不能,就去找最小的时间点。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. #define freopenr freopen("in.txt", "r", stdin)
  17. #define freopenw freopen("out.txt", "w", stdout)
  18. using namespace std;
  19. typedef long long LL;
  20. typedef pair<int, int> P;
  21. const int INF = 0x3f3f3f3f;
  22. const double inf = 0x3f3f3f3f3f3f;
  23. const LL LNF = 0x3f3f3f3f3f3f;
  24. const double PI = acos(-1.0);
  25. const double eps = 1e-8;
  26. const int maxn = 1e2 + 100;
  27. const int mod = 1e9 + 7;
  28. const int dr[] = {-1, 0, 1, 0};
  29. const int dc[] = {0, 1, 0, -1};
  30. const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  31. int n, m;
  32. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  33. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  34. inline int Min(int a, int b){ return a < b ? a : b; }
  35. inline int Max(int a, int b){ return a > b ? a : b; }
  36. inline LL Min(LL a, LL b){ return a < b ? a : b; }
  37. inline LL Max(LL a, LL b){ return a > b ? a : b; }
  38. inline int gcd(int a, int b){ return b ? gcd(b, a%b) : a; }
  39. inline int lcm(int a, int b){ return a * b / gcd(a, b); }
  40. inline bool is_in(int r, int c){
  41. return r >= 0 && r < n && c >= 0 && c < m;
  42. }
  43. struct Node{
  44. int l, r;
  45. Node() { }
  46. Node(int ll, int rr) : l(ll), r(rr) { }
  47. bool operator < (const Node &p) const{
  48. return l < p.l;
  49. }
  50. };
  51. Node a[205];
  52.  
  53. int main(){
  54. while(scanf("%d", &n) == 1){
  55. int s, d;
  56. int cnt = 1;
  57. a[0] = Node(0, 0);
  58. cin >> s >> d;
  59. printf("%d %d\n", s, s+d-1);
  60. a[cnt++] = Node(s, s+d-1);
  61. for(int i = 1; i < n; ++i){
  62. cin >> s >> d;
  63. --d;
  64. sort(a, a+cnt);
  65. if(a[cnt-1].r < s){
  66. printf("%d %d\n", s, s+d);
  67. a[cnt++] = Node(s, s+d);
  68. continue;
  69. }
  70.  
  71. bool ok = false;
  72. for(int j = 0; j < cnt-1; ++j){
  73. if(s > a[j].r && s+d < a[j+1].l){
  74. ok = true;
  75. printf("%d %d\n", s, s+d);
  76. a[cnt++] = Node(s, s+d);
  77. break;
  78. }
  79. }
  80. if(!ok){
  81. bool ok1 = false;
  82. for(int j = 1; j < cnt; ++j){
  83. if(a[j].l - a[j-1].r > d+1){
  84. printf("%d %d\n", a[j-1].r+1, a[j-1].r+d+1);
  85. a[cnt++] = Node(a[j-1].r+1, a[j-1].r+d+1);
  86. ok1 = true;
  87. break;
  88. }
  89. }
  90. if(!ok1){
  91. printf("%d %d\n", a[cnt-1].r+1, a[cnt-1].r+1+d);
  92. a[cnt] = Node(a[cnt-1].r+1, a[cnt-1].r+d+1);
  93. ++cnt;
  94. }
  95. }
  96.  
  97. }
  98. }
  99. return 0;
  100. }

CodeForces 730G Car Repair Shop (暴力)的更多相关文章

  1. 【CodeForces 730H】Car Repair Shop

    BUPT 2017 summer training (for 16) #1F 题意 依次有n (1 ≤ n ≤ 200) 个车要修理,每个车希望在s[i]时刻开始修理,时长d[i],如果s[i]后面没 ...

  2. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

  3. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  4. Codeforces Gym 100637G G. #TheDress 暴力

    G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...

  5. [ An Ac a Day ^_^ ] CodeForces 691F Couple Cover 花式暴力

    Couple Cover Time Limit: 3000MS   Memory Limit: 524288KB   64bit IO Format: %I64d & %I64u Descri ...

  6. Codeforces 626D Jerry's Protest(暴力枚举+概率)

    D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  7. Educational Codeforces Round 12 B. Shopping 暴力

    B. Shopping 题目连接: http://www.codeforces.com/contest/665/problem/B Description Ayush is a cashier at ...

  8. CodeForces 586B Laurenty and Shop

    F - Laurenty and Shop Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  9. codeforces 650D D. Image Preview (暴力+二分+dp)

    题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...

随机推荐

  1. Android应用程序项目结构

    Android应用程序项目结构 [src]:JAVA源代码目录 [gen]:由系统自动生成的JAVA源码文件,不可修改,只可查看和使用 加载的和依赖的类库 [assets]:本地存储文件的一个文件夹 ...

  2. PHP获得真实客户端的真实IP REMOTE_ADDR,HTTP_CLIENT_IP,HTTP_X_FORWARDED_FOR[]转载

    REMOTE_ADDR 是你的客户端跟你的服务器“握手”时候的IP.如果使用了“匿名代理”,REMOTE_ADDR将显示代理服务器的IP. HTTP_CLIENT_IP 是代理服务器发送的HTTP头. ...

  3. css三大特性

    层叠性: 当多个样式(样式的优先级相同)作用于同一个(同一类)标签时,样式发生了冲突,总是执行后边的代码(后边代码层叠前边的代码).和标签调用选择器的顺序没有关系. 继承性: 文字的大多属性都可以继承 ...

  4. linux signal 列表

    Linux 信号表   Linux支持POSIX标准信号和实时信号.下面给出Linux Signal的简表,详细细节可以查看man 7 signal. 默认动作的含义如下: Term    终止进程 ...

  5. Spring Boot使用MyBatis 3打印SQL的配置

    普通Spring下的XML文件配置: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE co ...

  6. Shiro note

    我们需要实现Realms的Authentication 和 Authorization.其中 Authentication 是用来验证用户身份,Authorization 是授权访问控制,用于对用户进 ...

  7. MySQL基础笔记(六) 存储过程与函数

    写在开头:本文所有的示例都是基于workers表,表中保存了某公司的员工姓名.性别.工资.年龄和居住城市,如下: +----+-----------+--------+--------+------+ ...

  8. HDU 3080 The plan of city rebuild(prim和kruskal)

    The plan of city rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  9. 配置pydot环境

    第一次配置pydot环境,过程还是比較曲折,看来对这样的模式还不是非常熟悉.断断续续弄了两天弄好了.都是些小要求,小细节问题. 安装的顺序也非常重要: 1.安装python-2.7.8.amd64.m ...

  10. [CSAPP]Bufbomb实验报告

    Bufbomb实验报告 实验分析: level 0-3从test開始制运行,通过函数getbuf向外界读取一串内容(buf). Level 4 是通过參数-n,程序运行testn函数,调用getbuf ...