Codeforces 617C Watering Flowers 【暴力 数据范围】
来源:互联网 发布:史丹利快报的淘宝店 编辑:程序博客网 时间:2024/04/27 01:51
A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.
You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.
The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000, - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain.
Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower.
It is guaranteed that all n + 2 points in the input are distinct.
Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.
2 -1 0 5 30 25 2
6
4 0 0 5 09 48 3-1 01 4
33
The first sample is (r12 = 5, r22 = 1):The second sample is (r12 = 1, r22 = 32):
恩,这题注意数据范围。#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<queue>#define ll __int64#define INF 0x3f3f3f3f#define inf 1LL<<63-1#define maxn 2020using namespace std;struct node{ ll dis1,dis2;};node pin[maxn];bool cmp(node a,node b){ return a.dis1<b.dis1;}ll dis(ll x0,ll y0,ll x,ll y){ return ((x-x0)*(x-x0)+(y-y0)*(y-y0));}int main(){ int n; ll x1,y1,x2,y2,x,y; while(~scanf("%d",&n)) { scanf("%I64d%I64d%I64d%I64d",&x1,&y1,&x2,&y2); for(int i=1;i<=n;++i) { scanf("%I64d%I64d",&x,&y); pin[i].dis1=dis(x,y,x1,y1); pin[i].dis2=dis(x,y,x2,y2); } pin[0].dis1=0; pin[0].dis2=0; sort(pin,pin+n+1,cmp); ll sum=inf,tem=0; for(int i=0;i<=n;++i) { tem=0; for(int j=i+1;j<=n;++j) tem=max(tem,pin[j].dis2); sum=min(sum,tem+pin[i].dis1); } if(n==1) sum=min(pin[1].dis1,pin[1].dis2); printf("%I64d\n",sum); } return 0;}1. 该
LL
使得整数文字类型long long
。 所以2LL
,是一种2型long long
。 如果没有LL
,字面只会类型int
。 这一点很重要,当你做这样的东西:1 << 401LL << 40
只用文字1
,(假设int
为32位,你转移超出了整数类型的大小->未定义的行为)。 同1LL
,您将类型设置为long long
前手,现在将正确地返回2 ^ 40。本文标题 :什么是1LL或2LL在C和C ++?
原文地址 :CodeGo.net/575292/ (关于1LL的原文)
- Codeforces 617C Watering Flowers 【暴力 数据范围】
- codeforces 617C Watering Flowers(暴力)
- Codeforces 617 C. Watering Flowers
- Codeforces 617C:Watering Flowers
- Codeforces 617C(Watering Flowers)
- CodeForces 617C Watering Flowers
- Coderforces 617C Watering Flowers 【暴力】
- Codeforces Round #340 -C - Watering Flowers-暴力+set
- Codeforces Round #340 (Div. 2)C. Watering Flowers(暴力)
- CodeForces 617 C. Watering Flowers(水~)
- Codeforcces 617C Watering Flowers【贪心+暴力枚举】
- Codeforces Round #340 (Div. 2) C. Watering Flowers(暴力枚举)
- 617C. Watering Flowers【几何】
- C. Watering Flowers 构造
- Codeforces 617C Watering Flowers (Round #340 (Div. 2) C题) nlogn算法
- Codeforces Round #340 (Div. 2) 617C Watering Flowers(计算几何)
- Codeforces Round #340 (Div. 2) C. Watering Flowers
- Codeforces Round #340 (Div. 2) C. Watering Flowers
- Java基础之-----集合框架
- Socket网络编程详解
- 迪杰斯特拉算法C++实现
- Python-装饰器以及对带有参数的装饰器的理解
- AFNetworking 原作者都无法解决的问题: 如何使用ip直接访问https网站?
- Codeforces 617C Watering Flowers 【暴力 数据范围】
- Java 包
- c中定义变量的内存分配顺序问题(极易错!!!)
- Codeforces 617A Elephant
- Codeforces 617B Chocolate
- Codeforces D Polyline
- C++链表
- HDOJ 5611 Baby Ming and phone number
- 咱码农为啥会(珍爱生命)远离企业应用开发