您的位置:首页 > 其它

HDOJ 5252 追星族

2015-06-04 17:42 495 查看
对于n个点,先按时间排序。二分答案,对于二分的当前值dis,我们将每个点向外扩展dis个距离,也就是个正方形。这个点和前一个时间点差的时间d也作为前一个距离,向外扩展d。。。。求交以后存在矩形,那么二分当前值存在,否则不存在。。。。

#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 50005
#define maxm 100005
#define eps 1e-12
#define mod 1000003
#define INF 0x3f3f3f3f
#define PI (acos(-1.0))
#define lowbit(x) (x&(-x))
#define mp make_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid
#define rson o<<1 | 1, mid+1, R
#pragma comment(linker, "/STACK:102400000,102400000")
#define pii pair<int, int>
typedef long long LL;
typedef unsigned long long ULL;
//typedef int LL;
using namespace std;
LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}
LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}
// head

struct node
{
LL x, y, t;
}a[maxn];
int n;

int cmp(node aa, node bb)
{
return aa.t < bb.t;
}

bool check(LL dis)
{
LL x1 = -10000000000LL;
LL y1 = -10000000000LL;
LL x2 = 10000000000LL;
LL y2 = 10000000000LL;
for(int i = 1; i <= n; i++) {
LL t = 0;
if(i != 1) t = a[i].t - a[i-1].t;
t *= 2;
x1 -= t;
y1 -= t;
x2 += t;
y2 += t;
LL t1 = 2 * (a[i].y - a[i].x);
LL t2 = 2 * (a[i].y + a[i].x);
x1 = max(x1, t1 - dis);
y1 = max(y1, t2 - dis);
x2 = min(x2, t1 + dis);
y2 = min(y2, t2 + dis);
if(x1 > x2 || y1 > y2) return false;
}
return true;
}

void work()
{
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%lld%lld%lld", &a[i].x, &a[i].y, &a[i].t);
sort(a+1, a+n+1, cmp);
LL top = 40000000000LL, bot = 0, mid, res;
while(top >= bot) {
mid = bot + (top - bot) / 2;
if(check(mid)) res = mid, top = mid-1;
else bot = mid+1;
}
if(res % 2) printf("%lld/2\n", res);
else printf("%lld/1\n", res / 2);
}

int main()
{
int _;
scanf("%d", &_);
for(int i = 1; i <= _; i++) {
printf("Case #%d:\n", i);
work();
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: