Hdu 4717 The Moving Points (three Points)

Source: Internet
Author: User

Connection: hdu 4717 The Moving Points

N points are given. Each point has an initial position (x, y) and the moving distance per unit of time. The vector form is given. The maximum and minimum values of the distance between n points are the minimum and minimum values.

Solution: similar to the trigger of the binary algorithm, because if we make the maximum value d between the time t and the required two into a function curve, the monotonicity should first decrease and then increase progressively, therefore, we use the three-way method to obtain the extreme value.

#include 
  
   #include 
   
    #include 
    
     #include using namespace std;const int N = 305;const double eps = 1e-6;struct point {    double x;    double y;}s[N], p[N];int n;void init () {    scanf("%d", &n);    for (int i = 0; i < n; i++)        scanf("%lf%lf%lf%lf", &s[i].x, &s[i].y, &p[i].x, &p[i].y);}inline double dis (double x, double y) {    return sqrt(x*x+y*y);}double cat (double k) {    double ans = 0;    for (int i = 0; i < n; i++) {        double xi = s[i].x + p[i].x * k;        double yi = s[i].y + p[i].y * k;        for (int j = i + 1; j < n; j++) {            double pi = s[j].x + p[j].x * k;            double qi = s[j].y + p[j].y * k;            ans = max(ans, dis(xi-pi, yi-qi));        }    }    return ans;}void solve () {    double l = 0;    double r = 0xffffff;    while (fabs(r-l) > eps) {        double tmp = (r-l)/3;        double midl = l + tmp;        double midr = r - tmp;        if (cat(midl) < cat(midr))            r = midr;        else            l = midl;    }    printf("%.2lf %.2lf\n", l, cat(l));}int main () {    int cas;    scanf("%d", &cas);    for (int i = 1; i <= cas; i++) {        init ();        printf("Case #%d: ", i);        solve();    }    return 0;}
    
   
  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.