当前位置:网站首页>UPC little C's King Canyon
UPC little C's King Canyon
2022-07-29 07:34:00 【A little Yu】
First of all , The title is not clear , Is o n The farthest distance between two points .
I didn't write the code , Ask the coach for .
ps:gramham Algorithm video b standing
Title Description
Small C I especially like hitting primary school students “ Kingly pesticide ”, however , Today's little C But in the glory of the king, he was abused by the opposite side . as everyone knows , At present, the farthest distance of the king's glory attack is Huang Zhong , But small C Always playing with Huang Zhong being abused , Because he doesn't know when to turn it up . Small at this moment C Fighting with the opposite team in the middle , He thinks it is necessary for him to choose a suitable position to open , So that we can fight more enemy heroes . This is the time , Small C I also found a lot of soldiers and wild monsters nearby , He believes that these things can also increase experience , So we should also fight . Small C So I was thinking , If only I could hit everything in the whole King Canyon , But these things are always moving , And my own big move is not far enough , that , If I know the location of everything , My big trick is to hit everything , How far is the shortest ? however , Small C Fantasy again , He wants to know the square of the shortest distance .
Input
Here you are. N, It means enemy hero 、 Soldier 、 The sum of wild monsters .
Next N That's ok , Two numbers per line , Represents a small C The location of the thing to hit .Output
a line , It means small C Want to know the answer .
The sample input Copy
4 0 0 0 1 1 1 1 0Sample output Copy
2Tips
about 10% The data of ,N <= 100.
about 30% The data of ,N <= 1000.
about 100% The data of ,N <= 50000
Each coordinate is -10000 to 10000 Between the value of the
#include<bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i)
#define mem(a) memset ( (a), 0, sizeof (a))
#define str(a) strlen (a)
int n, top;
struct Node{
int x;
int y;
}node[60000], stack[60000];
int dist(Node p1, Node p2) {
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
int mult(Node p1, Node p2, Node p0) {
return ((p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y));
}
int cmp(Node a, Node b) {
if ( mult(a, b, node[0]) > 0)
return 1;
else if ( mult(a, b, node[0]) == 0 && dist(a, node[0]) < dist(b, node[0]))
return 1;
return 0;
}
void Gramham() {
int k = 0 ;
REP(i, 1, n - 1)
if ( node[k].y > node[i].y || ((node[k].y == node[i].y) && node[k].x > node[i].x))
k = i;
Node tmp;
tmp = node[0];
node[0] = node[k];
node[k] = tmp;//node[0] and node[k] swap
sort(node + 1, node + n, cmp);
top = 2;
stack[0] = node[0];
stack[1] = node[1];
stack[2] = node[2];
REP(i, 3, n - 1) {
while(top > 1 && mult(node[i], stack[top], stack[top - 1]) >= 0)
top --;
stack[++ top] = node[i];
}
}
int main() {
cin >> n;
REP(i, 0, n - 1)
cin >> node[i].x >> node[i].y;
Gramham();
int ans = -1;
REP(i, 0, top)
REP(j, i + 1, top)
if ( ans < dist(stack[i], stack[j]))
ans = dist(stack[i], stack[j]);
cout << ans << endl;
return 0;
}
边栏推荐
- 我,28岁,测试员,10月无情被辞:想给还在学测试 的人提个醒......
- [summer daily question] Luogu P6500 [coci2010-2011 3] zbroj
- 状态机dp(简单版)
- 信用卡购物积分
- BeanUtils.setProperty()
- OA项目之会议通知(查询&是否参会&反馈详情)
- Scala 高阶(九):Scala中的模式匹配
- Spingboot integrates the quartz framework to realize dynamic scheduled tasks (support real-time addition, deletion, modification and query tasks)
- 树莓派的启动流程
- mysql 单表最多能存多少数据?
猜你喜欢

OA项目之会议通知(查询&是否参会&反馈详情)

Segger's hardware anomaly analysis

梳理市面上的2大NFT定价范式和4种解决方案

分析25个主要DeFi协议的路线图 预见DeFi未来的七大趋势

QT topic: basic components (button class, layout class, output class, input class, container class)

js第四天流程控制(if语句和switch语句)

Job 7.28 file IO and standard IO

Docker's latest super detailed tutorial - docker creates, runs, and mounts MySQL

Meeting notice of OA project (Query & whether to attend the meeting & feedback details)

How does MySQL convert rows to columns?
随机推荐
【MYSQL】-【子查询】
Spingboot integrates the quartz framework to realize dynamic scheduled tasks (support real-time addition, deletion, modification and query tasks)
蓝桥杯A组选数异或
RoBERTa:A Robustly Optimized BERT Pretraining Approach
I, 28, a tester, was ruthlessly dismissed in October: I want to remind people who are still learning to test
我想问一下,我flink作业是以upsert-kafka的方式写入数据的,但是我在mysql里面去更
log4qt内存泄露问题,heob内存检测工具的使用
Scala higher order (IX): pattern matching in Scala
[summer daily question] Luogu p7760 [coci2016-2017 5] tuna
log4j Layout简介说明
Vue router route cache
国内数字藏品的乱象与未来
logback简介及引入方法
【深度学习】数据准备-pytorch自定义图像分割类数据集加载
力扣(LeetCode)209. 长度最小的子数组(2022.07.28)
Embroidery of little D
小D的刺绣
mysql 单表最多能存多少数据?
Logback log level introduction
Sqlmap(SQL注入自动化工具)