# [CodeForces - 1304] C - Air Conditioner【区间交集问题】

•  题意：从0时刻开始，会按时间顺序来n个客人，每个客人有各自的满意温度区间。0时刻的初始温度为m. 每一时刻我们可以调节温度为 +1 或 -1. 问是否可以使得n个客人全部满意。

### 思路

END

#include <iostream>
#include <cstdio>
using namespace std;

{
int x = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -f; c = getchar(); }
while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
return x * f;
}

const int maxN = 105;
const char ans[2][5] = {"NO", "YES"};

int n, m;

struct node{
int l, r, t;
node() {}
node(int a, int b, int c): l(a), r(b), t(c) {}
};

bool judge(node &n1, node n2)
{
if(n1.r < n2.l || n1.l > n2.r) //无交集
return false;
if(n1.l < n2.l)
n1.l = n2.l;
if(n1.r > n2.r)
n1.r = n2.r;
return true;
}

int main()
{
while(TAT -- )
{
node now = node(m, m, 0), info;
bool flag = true;
for(int i = 0; i < n; ++ i )
{
int mx = info.t - now.t;
now = node(now.l - mx, now.r + mx, info.t);
if(judge(now, info)) continue;
else flag = false;
}
printf("%s\n", ans[flag]);
}
return 0;
}

02-21 108
02-17 150
05-06 137