hdu_4717 The Moving Points

第一道三分题, 自己YY的证明

考虑一下距离最远的两个点,记这个距离为d,记题目所求为ans,此时d==ans

1.下一刻他俩的距离比现在远:那么d在增加,如果没有其他两个点的距离超过d,那么ans在增加;如果有两个点的距离超过d,那么最远点对发生变化,d增大,ans依然处在增加的趋势

2.下一刻他俩的距离比现在近:那么d在减少,如果没有其他两个点的距离超过d,那么ans在减少;如果有两个点的距离此时超过了d,因为之前d是最大的,而且当前处于减小的趋势,此时超过d的那个点对必然处于远离的状态,那么转到情况1

其实,由情况1可以知道,一旦ans在增加的时候,是不会再减小了,所以一定可以用三分来解

由情况2可知,若ans处在减小的时候,下一时刻有可能继续减小,也有可能开始增加

综上,ans的变化趋势满足凸性,可以用三分来解

http://acm.hdu.edu.cn/showproblem.php?pid=4717

#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <fstream>
using namespace std;


//LOOP
#define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)


//OTHER
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define all(x) (x).begin(),(x).end()


//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define RS(s) scanf("%s", s)


//OUTPUT
#define WI(n) printf("%d\n", n)
#define WS(n) printf("%s\n", n)


//debug
//#define online_judge
#ifndef online_judge
#define debugt(a) cout << (#a) << "=" << a << " ";
#define debugI(a) debugt(a) cout << endl
#define debugII(a, b) debugt(a) debugt(b) cout << endl
#define debugIII(a, b, c) debugt(a) debugt(b) debugt(c) cout << endl
#define debugIV(a, b, c, d) debugt(a) debugt(b) debugt(c) debugt(d) cout << endl
#else
#define debugI(v)
#define debugII(a, b)
#define debugIII(a, b, c)
#define debugIV(a, b, c, d)
#endif

typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
const int INF = 0x3f3f3f3f;
const double eps = 1e-10;
const int MOD = 100000007;
const int MAXN = 1000010;
const double PI = acos(-1.0);


struct Point
{
    double x, y;
    Point(double x=0, double y=0):x(x),y(y) { }
    inline void read()
    {
        scanf("%lf%lf", &x, &y);
    }
};
typedef Point Vector;

int n;
Point p[400];
Vector v[400];
Point p1[400];
double ti, di;

double func(double t)
{
     double ret = 0;
     for(int i = 0;i < n;i++)
         for(int j = i+1;j < n;j++)
         {
             double x1 = p[i].x + v[i].x*t;
             double y1 = p[i].y + v[i].y*t;
             double x2 = p[j].x + v[j].x*t;
             double y2 = p[j].y + v[j].y*t;
             ret = max(ret,sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
         }
     return ret;
}

void fun()
{
    double L = 0, R = 1e10, M, RM;
    while (L + eps < R)
    {
        M = (L + R) / 2;
        RM = (M + R) / 2;
        if (func(M) <= func(RM)) R = RM;
        else L = M;
    }
    ti = R;
    di = func(R);
}

int main()
{
//    freopen("0.txt", "r", stdin);
    int ncase;
    RI(ncase);
    FE(tt, 1, ncase)
    {
        RI(n);
        REP(i, n)
        {
            scanf("%lf%lf", &p[i].x, &p[i].y);
            scanf("%lf%lf", &v[i].x, &v[i].y);
        }
        fun();
        printf("Case #%d: %.2lf %.2lf\n", tt, ti, di);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值