Rokua P1158 Missile intercept sequencing

Source: Internet
Author: User

---restore content starts---

Rokua P1158 Missile Intercept
Sort of a tricky enumeration.

Test instructions uses two systems to intercept the missile, and the cost of a system equals the missile that was farthest from him in the missile that the system intercepted.
and the distance of the system squared

Sort each missile by a distance of 1 from the system,
And then enumerate the n--0 to select the missiles as the system 1 the furthest capable of intercepting missiles.
Then you can update the next System 2 missiles to intercept the farthest from the System 2

1#include <cstdio>2#include <cmath>3#include <cstdlib>4#include <cstring>5#include <string>6#include <algorithm>7#include <iomanip>8#include <iostream>9 using namespacestd;Ten  One Const intMAXN =100011, INF =1e9; A structnode{ -     intX,Y,R1,R2;  - }; the intN,xs,ys,xt,yt,r1,r2,ans; - node A[MAXN]; -  -InlineBOOLCMP (node A,node b) + { -     returnA.r1 <b.r1; + } A  atInlineintSqrintx) - { -     returnx*x; - } -  - intMain () in { -scanf"%d%d%d%d",&xs,&ys,&xt,&YT);  toscanf"%d",&n); +      for(intI=1; i<=n;i++)  -     { thescanf"%d%d", &a[i].x,&a[i].y);  *a[I].r1 = Sqr (a[i].x-xs) + SQR (a[i].y-ys);  $a[I].r2 = Sqr (a[i].x-xt) + SQR (a[i].y-YT); Panax Notoginseng     } -Sort (A +1, a+n+1, CMP);  ther2 =0 ; +Ans =inf; A      for(inti=n;i>=0; i--)  the     { +         if(a[i].r1 + r2 < ans) ans = a[i].r1 + R2;//R2 cost of the System 2 -         if(a[i].r2 > r2) r2 =a[i].r2;  $         //update the next system 2 the one that is farthest from the system to intercept the missile . $     } -printf"%d\n", ans);  -     return 0 ;  the}

---restore content ends---

Rokua P1158 Missile intercept sequencing

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.