1.24
CF 617 C Watering Flowers
sbsbsbsbsbsb
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 typedef long long LL; 6 LL x[2222], y[2222], d1[2222], d2[2222]; 7 int n; 8 9 LL cal(LL x) 10 { 11 LL ret = 0LL; 12 for(int i = 0; i < n; i++) 13 { 14 if(d1[i] <= x) continue; 15 ret = max(ret, d2[i]); 16 } 17 return ret; 18 } 19 20 int main(void) 21 { 22 LL x1, y1, x2, y2; 23 scanf("%d %I64d %I64d %I64d %I64d", &n, &x1, &y1, &x2, &y2); 24 for(int i = 0; i < n; i++) scanf("%I64d %I64d", x + i, y + i); 25 for(int i = 0; i < n; i++) 26 { 27 LL xx = x1 - x[i], yy = y1 - y[i]; 28 d1[i] = xx * xx + yy * yy; 29 xx = x2 - x[i], yy = y2 - y[i]; 30 d2[i] = xx * xx + yy * yy; 31 } 32 LL ans = cal(0); 33 for(int i = 0; i < n; i++) 34 ans = min(ans, d1[i] + cal(d1[i])); 35 printf("%I64d\n", ans); 36 return 0; 37 }
原文:http://www.cnblogs.com/Aguin/p/5154866.html