Idea: Determine if the sandbags are in the rectangle.
#include <cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;Const intMAXN =30001;intB[MAXN];structnode{intx, y;} K[MAXN]; structnode2{intx1, x2, y1, y2;} K2[MAXN];BOOLcmpintAintb) { returnA >b;}intMainvoid){ intN, M; while(Cin >> N >>m) { for(inti =0; I < n; i + +) {cin>> k[i].x >>k[i].y; } for(inti =0; I < m; i + +) {cin>> k2[i].x1 >> k2[i].y1 >> k2[i].x2 >>K2[i].y2; } memset (b,0,sizeof(b)); for(inti =0; I < n; i + +) { for(intj =0; J < M; J + +) { if(k[i].x >= k2[j].x1 && k[i].x <= k2[j].x2 && k[i].y >= k2[j].y1 && k[i].y <=k2[j].y2) {B[i]+=2* (ABS (K2[J].X1-K2[J].X2) + ABS (K2[j].y1-k2[j].y2)); Break; }}} sort (b, B+N, CMP); for(inti =0; I < n; i + +) cout<< B[i] <<Endl; }}
HDU2555 Everyone can participate in the 30th Annual school Athletics Games