CodeForces 730G Car Repair Shop (暴力)
题意:给定 n 个工作的最好开始时间,和持续时间,现在有两种方法,第一种,如果当前的工作能够恰好在最好时间开始,那么就开始,第二种,如果不能,那么就从前找最小的时间点,来完成。
析:直接暴力,每次都先去看看能不能在最好时间完成,如果不能,就去找最小的时间点。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e2 + 100;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline int gcd(int a, int b){ return b ? gcd(b, a%b) : a; }
inline int lcm(int a, int b){ return a * b / gcd(a, b); }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Node{
int l, r;
Node() { }
Node(int ll, int rr) : l(ll), r(rr) { }
bool operator < (const Node &p) const{
return l < p.l;
}
};
Node a[205]; int main(){
while(scanf("%d", &n) == 1){
int s, d;
int cnt = 1;
a[0] = Node(0, 0);
cin >> s >> d;
printf("%d %d\n", s, s+d-1);
a[cnt++] = Node(s, s+d-1);
for(int i = 1; i < n; ++i){
cin >> s >> d;
--d;
sort(a, a+cnt);
if(a[cnt-1].r < s){
printf("%d %d\n", s, s+d);
a[cnt++] = Node(s, s+d);
continue;
} bool ok = false;
for(int j = 0; j < cnt-1; ++j){
if(s > a[j].r && s+d < a[j+1].l){
ok = true;
printf("%d %d\n", s, s+d);
a[cnt++] = Node(s, s+d);
break;
}
}
if(!ok){
bool ok1 = false;
for(int j = 1; j < cnt; ++j){
if(a[j].l - a[j-1].r > d+1){
printf("%d %d\n", a[j-1].r+1, a[j-1].r+d+1);
a[cnt++] = Node(a[j-1].r+1, a[j-1].r+d+1);
ok1 = true;
break;
}
}
if(!ok1){
printf("%d %d\n", a[cnt-1].r+1, a[cnt-1].r+1+d);
a[cnt] = Node(a[cnt-1].r+1, a[cnt-1].r+d+1);
++cnt;
}
} }
}
return 0;
}
CodeForces 730G Car Repair Shop (暴力)的更多相关文章
- 【CodeForces 730H】Car Repair Shop
BUPT 2017 summer training (for 16) #1F 题意 依次有n (1 ≤ n ≤ 200) 个车要修理,每个车希望在s[i]时刻开始修理,时长d[i],如果s[i]后面没 ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
- [ An Ac a Day ^_^ ] CodeForces 691F Couple Cover 花式暴力
Couple Cover Time Limit: 3000MS Memory Limit: 524288KB 64bit IO Format: %I64d & %I64u Descri ...
- Codeforces 626D Jerry's Protest(暴力枚举+概率)
D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Educational Codeforces Round 12 B. Shopping 暴力
B. Shopping 题目连接: http://www.codeforces.com/contest/665/problem/B Description Ayush is a cashier at ...
- CodeForces 586B Laurenty and Shop
F - Laurenty and Shop Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- codeforces 650D D. Image Preview (暴力+二分+dp)
题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...
随机推荐
- [NOIP2000] 提高组 洛谷P1018 乘积最大
题目描述 今年是国际数学联盟确定的“2000――世界数学年”,又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的数学智力竞赛的活动,你的一个好朋友XZ也有幸得 ...
- isNaN+parseFloat进行统计以及对NaN的处理【JS验证数字】
今天遇到这么一个需求: 对数据进行统计,可是在统计的时候parseFloat的时候出来一个NaN.后来用isNaN判断,如果是NaN,就给其设置一个初值. 先看对两个方法的解释 parseFloat: ...
- 黑黛增发罗林川:如何三年开1000家连锁店?_深度案例_i黑马
黑黛增发罗林川:如何三年开1000家连锁店?_深度案例_i黑马 黑黛增发
- maven打包时的三方包的选择顺序
在一个项目有多个模块引用多个版本的某个插件(或者叫三方包.jar包等)时,如何解决版本冲突问题?最终选用某个版本还是选择几个版本? maven在遇到上面的情况时,会智能处理版本冲突,最终选择一个版本, ...
- Linux信号通讯编程
信号通讯流程为: ①进程A/内核选择信号 ②发送信号 ③进程B接收信号并处理 Linux系统支持的全部信号均定义在/usr/include/asm/signal.h.当中常见的信号有: ①SIGKIL ...
- Android Studio一些简单设置
简单设置 1.默认主题设置 默认的 Android Studio 为灰色界面,能够选择使用炫酷的黑色界面. Settings --> Appearance --> Them ...
- 吉哥系列故事——完美队形II(hdu4513+Manacher)
吉哥系列故事--完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...
- 【转载】HTTP协议与WEB本质
当你在浏览器地址栏敲入"http://www.csdn.net/",然后猛按回车,呈现在你面前的,将是csdn的首页了(这真是废话,你会认为这是理所当然的).作为一个开发者,尤其是 ...
- 运算符与类型转换 mogondb简介
运算符与类型转换 1.运算符 (1)分类 算术运算符.关系运算符.逻辑运算符.位运算符.赋值运算符.其他运算符 >.算术运算符: 运算符 描述 + 把两个操作数相加 - 从第一个操作数中减去 ...
- 【CODEFORCES】 C. Dreamoon and Strings
C. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...