wenbao与极角排序
atan2 (-180----180]
http://acm.hdu.edu.cn/showproblem.php?pid=6127
1 #include <iostream> 2 #include <cmath> 3 #include <algorithm> 4 using namespace std; 5 #define ll long long 6 const int maxn = 5e4+10; 7 #define PI acos(-1.0) 8 int t, n, w; 9 ll sum; 10 double x, y; 11 struct Node{ 12 ll w; 13 double c; 14 }T[maxn]; 15 bool cmp(Node a, Node b){ 16 return a.c > b.c; 17 } 18 int main(){ 19 scanf("%d", &t); 20 while(t--){ 21 sum = 0; 22 scanf("%d", &n); 23 for(int i = 0; i < n; ++i){ 24 scanf("%lf%lf%lld", &x, &y, &T[i].w), T[i].c = atan2(y, x), sum += T[i].w; 25 } 26 sort(T, T+n, cmp); 27 int xx = 0; 28 ll sum2 = 0; 29 while(T[xx].c >= 0 && xx < n) sum2 += T[xx].w, xx++; 30 ll ma = 0; 31 int i = 0; 32 while(T[i].c >= 0){ 33 if(PI - T[i].c > -T[xx].c && xx < n){ 34 sum2 += T[xx].w, xx++; 35 ma = max(ma, sum2*(sum-sum2)); 36 }else{ 37 sum2 -= T[i].w, i++; 38 ma = max(ma, sum2*(sum-sum2)); 39 } 40 } 41 printf("%lld\n", ma); 42 } 43 return 0; 44 }
只有不断学习才能进步!