当前位置:网站首页>Missile interception -- UPC winter vacation training match
Missile interception -- UPC winter vacation training match
2022-07-05 01:50:00 【Porter hunter of the program】
subject
Background
after 11 Years of hiding one's strength and cultivating one's obscurity , A country has developed a new missile interception system , Any missile whose distance from it does not exceed its working radius can be successfully intercepted by it . When the working radius is 0 when , It can intercept missiles in exactly the same position . But the missile interception system also has such defects : Each system can only set the working radius once a day . And the use cost of the day , Is the sum of the squares of the working radii of all systems .
One day , The radar caught the enemy's missiles coming . Because the system is still in the experimental stage , So only two systems are working . If the current requirement is to intercept all missiles , Please calculate the minimum use cost of this day .
Input
The first line contains 4 It's an integer x1、y1、x2、y2, Every two integers are separated by a space , The coordinates of the two missile interception systems are (x1,y1)、(x2,y2).
The second line contains 1 It's an integer N(1≤N≤100000), Express N Missiles . Next N That's ok , Two integers per line x、y, Separated by a space , Represents the coordinates of a missile (x,y). The coordinates of different missiles may be the same .
Output
There is only one line of output , Contains an integer , That is, the minimum use cost of the day .
The sample input
0 0 10 0 2 -3 3 10 0
Sample output
18
Tips and data range limitations
Two points (x1,y1)、(x2,y2) The square of the distance between is (x1−x2)2+(y1−y2)2.
The working radius of the two systems r1、r2 Sum of squares of , Refer to r1、r2 Take the squares respectively and then sum , namely r12+r22.
about 100% The data of ,1≤N≤100000, And the absolute value of all coordinate components does not exceed 1000.
Thought analysis
Wrong thinking : At the beginning of this question, I thought that this missile was intercepted by the nearest interception system , But the result is WA.
Ah , Still too simple .If you follow my idea , Later, I came up with a good example , On a number axis ,0 and 5 Is the location of the interception system , Now if it's in -5 and 4 There is a missile at , Obviously, our previous thinking is wrong , This only needs to be used in 0 The interception system of the location is ok .The right way of thinking : The correct way to do this is to follow 1 Sort by the distance of , Then find a suitable dividing point i Make part of it intercepted by the first interception system , The other part is intercepted by the second interception system . In this way, we can find the minimum sum of squares
I don't say much nonsense , Code up
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+10;
ll xa,xb,ya,yb;
struct node{
ll x,y;
ll disa,disb;
}a[N];
ll da,db;
ll n;
bool cmp(node c,node d){
return c.disa>d.disa;
}
int main()
{
cin>>xa>>ya>>xb>>yb;// Enter the location coordinates of the two interception systems
cin>>n;// Enter the number of missiles
for(ll i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;// Enter the first i Position coordinates of missiles
a[i].disa=(a[i].x-xa)*(a[i].x-xa)+(a[i].y-ya)*(a[i].y-ya);// Calculate to a The square of the distance
a[i].disb=(a[i].x-xb)*(a[i].x-xb)+(a[i].y-yb)*(a[i].y-yb);// Calculate to b The square of the distance
}
sort(a+1,a+1+n,cmp);// Sort according to the position from the first interception system
ll ans=INT_MAX;// Define a variable to store the answer , Assign the initial value to infinity
ll r2=0;// Define a variable to record the radius set by the second interception system
for(ll i=1;i<=n+1;i++){
ll r1=a[i].disa;// Radius of the first interception system
r2=max(r2,a[i-1].disb);// Find the interception radius of the second interception system
ans=min(r1+r2,ans);// Find the most suitable decomposition point is the sum of the squares of the minimum distance
}
cout<<ans;
return 0;
}
Examples of operation process
边栏推荐
- es使用collapseBuilder去重和只返回某个字段
- Runc hang causes the kubernetes node notready
- batchnorm. Py this file single GPU operation error solution
- Logstash、Fluentd、Fluent Bit、Vector? How to choose the appropriate open source log collector
- 微信小程序:最新wordpress黑金壁纸微信小程序 二开修复版源码下载支持流量主收益
- He was laid off.. 39 year old Ali P9, saved 150million
- Wechat applet: the latest WordPress black gold wallpaper wechat applet two open repair version source code download support traffic main revenue
- Wechat applet: independent background with distribution function, Yuelao office blind box for making friends
- STM32 series - serial port UART software pin internal pull-up or external resistance pull-up - cause problem search
- 力扣剑指offer——二叉树篇
猜你喜欢
He was laid off.. 39 year old Ali P9, saved 150million
Three properties that a good homomorphic encryption should satisfy
Practice of tdengine in TCL air conditioning energy management platform
JS implementation determines whether the point is within the polygon range
Restful fast request 2022.2.1 release, support curl import
JVM's responsibility - load and run bytecode
Win: use PowerShell to check the strength of wireless signal
增量备份 ?db full
Yyds dry inventory swagger positioning problem ⽅ formula
[CTF] AWDP summary (WEB)
随机推荐
WCF: expose unset read-only DataMember property- WCF: Exposing readonly DataMember properties without set?
Interesting practice of robot programming 15- autoavoidobstacles
PowerShell: use PowerShell behind the proxy server
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
Win: use PowerShell to check the strength of wireless signal
Main window in QT application
Win: use shadow mode to view the Desktop Session of a remote user
Codeforces Round #770 (Div. 2) ABC
es使用collapseBuilder去重和只返回某个字段
Pytorch fine tuning (Fortune): hollowed out design or cheating
流批一體在京東的探索與實踐
batchnorm. Py this file single GPU operation error solution
142. Circular linked list II
Hedhat firewall
220213c language learning diary
Interesting practice of robot programming 16 synchronous positioning and map building (SLAM)
力扣剑指offer——二叉树篇
Matrixone 0.2.0 is released, and the fastest SQL computing engine is coming
Advanced conditional statements of common SQL operations
[Chongqing Guangdong education] National Open University spring 2019 1042 international economic law reference questions