当前位置:网站首页>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
边栏推荐
- RichView TRVStyle MainRVStyle
- PHP 基础篇 - PHP 中 DES 加解密详解
- Codeforces Global Round 19 ABC
- Huawei machine test question: longest continuous subsequence
- 85.4% mIOU! NVIDIA: using multi-scale attention for semantic segmentation, the code is open source!
- DOM basic syntax
- Can financial products be redeemed in advance?
- Roads and routes -- dfs+topsort+dijkstra+ mapping
- R语言用logistic逻辑回归和AFRIMA、ARIMA时间序列模型预测世界人口
- runc hang 导致 Kubernetes 节点 NotReady
猜你喜欢
Express routing, express middleware, using express write interface
One plus six brushes into Kali nethunter
R language uses logistic regression and afrima, ARIMA time series models to predict world population
R语言用logistic逻辑回归和AFRIMA、ARIMA时间序列模型预测世界人口
Kibana installation and configuration
Li Kou Jianzhi offer -- binary tree chapter
The application and Optimization Practice of redis in vivo push platform is transferred to the end of metadata by
"2022" is a must know web security interview question for job hopping
Interesting practice of robot programming 15- autoavoidobstacles
Runc hang causes the kubernetes node notready
随机推荐
85.4% mIOU! NVIDIA: using multi-scale attention for semantic segmentation, the code is open source!
Codeforces Round #770 (Div. 2) ABC
Tla+ through examples (XI) -- propositional logic and examples
What is the current situation and Prospect of the software testing industry in 2022?
Interpretation of mask RCNN paper
Wechat applet: wechat applet source code download new community system optimized version support agent member system function super high income
One plus six brushes into Kali nethunter
Win:使用组策略启用和禁用 USB 驱动器
Restful Fast Request 2022.2.1发布,支持cURL导入
Visual studio 2019 set transparent background (fool teaching)
es使用collapseBuilder去重和只返回某个字段
Yyds dry inventory jetpack hit dependency injection framework Getting Started Guide
Application and development trend of image recognition technology
Vulnstack3
Nebula Importer 数据导入实践
Timescaledb 2.5.2 release, time series database based on PostgreSQL
Wechat applet: exclusive applet version of the whole network, independent wechat community contacts
Database postragesq role membership
Stored procedure and stored function in Oracle
Practice of tdengine in TCL air conditioning energy management platform