当前位置:网站首页>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;
}
边栏推荐
- Vue router route cache
- Write some DP
- 【暑期每日一题】洛谷 P1601 A+B Problem(高精)
- EF core reading text type is slow_ EF core is slow to read large string fields
- do end用法的妙处
- MapReduce各阶段步骤
- Introduction to logback filter
- CFdiv1+2-Bash and a Tough Math Puzzle-(线段树单点区间维护gcd+总结)
- 我想问一下,我flink作业是以upsert-kafka的方式写入数据的,但是我在mysql里面去更
- @RequestMapping 用法详解
猜你喜欢
Scala 高阶(九):Scala中的模式匹配

Segger's hardware anomaly analysis

JS day 4 process control (if statement and switch statement)
![[summer daily question] Luogu p6461 [coci2006-2007 5] trik](/img/bf/c0e03f1bf477730f0b3661b3256d1d.png)
[summer daily question] Luogu p6461 [coci2006-2007 5] trik
![【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK](/img/bf/c0e03f1bf477730f0b3661b3256d1d.png)
【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK

Prometheus and grafana

Paper reading (62):pointer networks

How can electronic component trading enterprises solve warehouse management problems with ERP system?

美智光电IPO被终止:年营收9.26亿 何享健为实控人

监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
随机推荐
I'd like to ask, my flick job writes data in the way of upsert Kafka, but I'm more careful in MySQL
[MySQL] - [subquery]
3-global exception handling
Thinkphp6 realizes database backup
状态机dp(简单版)
使用自定义注解校验list的大小
What is the function of fileappender in logback?
logback 中FileAppender具有什么功能呢?
JS break and continue and return keywords
logback简介及引入方法
ef core 读取text类型慢_ef core读取大字符串字段慢
[summer daily question] Luogu p6320 [coci2006-2007 4] sibice
Practice of online problem feedback module (XVII): realize the online download function of excel template
08 dynamic programming
【暑期每日一题】洛谷 P6336 [COCI2007-2008#2] BIJELE
小D的刺绣
电子元器件贸易企业如何借助ERP系统,解决仓库管理难题?
STM32 operation w25q256 w25q16 SPI flash
监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
Segger's hardware anomaly analysis