---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