zoj 3450Doraemon's Railgun
2015-07-29 09:16
405 查看
Doraemon's Railgun Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescription Doraemon's city is being attacked again. This time Doraemon has built a powerful railgun in the city. So he will use it to attack enemy outside the city. There are N groups of enemy. Now each group is staying outside of the city. Group i is located at different (Xi, Yi) and contains Wisoldiers. After T0 days, all the enemy will begin to attack the city. Before it, the railgun can fire artillery shells to them. The railgun is located at (X0, Y0), which can fire one group at one time, The artillery shell will fly straightly to the enemy. But in case there are several groups in a straight line, the railgun can only eliminate the nearest one first if Doraemon wants to attack further one. It took Ti days to eliminate group i. Now please calculate the maximum number of soldiers it can eliminate. InputThere are multiple cases. At the first line of each case, there will be four integers, X0, Y0, N, T0 (-1000000000 ≤ X0, Y0 ≤ 1000000000; 1 ≤ N ≤ 500; 1 ≤ T0 ≤ 10000). Next N lines follow, each line contains four integers, Xi, Yi, Ti, Wi (-1000000000 ≤ Xi, Yi ≤ 1000000000; 0 ≤Ti, Wi ≤ 10000). OutputFor each case, output one integer, which is the maximum number of soldiers the railgun can eliminate. Sample Input0 0 5 10 0 5 2 3 0 10 2 8 3 2 4 6 6 7 3 9 4 4 10 2Sample Output
20
//分组dp
#include <cstdio>#include <cstring>#include <algorithm>#include<vector>#include<cmath>using namespace std;long long xx,yy,n,tkk;long long cnt,t;struct data{long long x,y;long long t,w;};double eps =1e-8;data zb[5007];long long dp[100009];bool cmp(data a,data b){return ((a.x-xx)*(a.x-xx)+(a.y-yy)*(a.y-yy))<((b.x-xx)*(b.x-xx)+(b.y-yy)*(b.y-yy));}long long gcd(long long a,long long b){return b==0?a:gcd(b,a%b);}int ok(data &a,data &b){if(((a.x-xx)*(b.y-yy))==((a.y-yy)*(b.x-xx))){if(((a.x-xx)*(b.x-xx)>=0)&&((a.y-yy)*(b.y-yy)>=0))return 1;return 0;}return 0;}int main(){while(scanf("%lld%lld%lld%lld",&xx,&yy,&n,&tkk)!=EOF){vector<data >a[50007];long long nn=0;;for(long long i=0;i<n;i++){long long tx,ty,tt,ww;scanf("%lld%lld%lld%lld",&tx,&ty,&tt,&ww);zb[nn].x=tx;zb[nn].y=ty;zb[nn].t=tt;zb[nn].w=ww;nn++;}n=nn;cnt=0;sort(zb,zb+n,cmp);a[cnt++].push_back(zb[0]);for(int i=1;i<n;i++){int flag=1;for(int j=0;j<cnt;j++){if(ok(a[j][0],zb[i])){long long len=a[j].size();if(zb[i].t==0){a[j][len-1].w+=zb[i].w;a[j][len-1].t+=zb[i].t;flag=0;break;}data temp;temp.w=a[j][len-1].w+zb[i].w;temp.t=a[j][len-1].t+zb[i].t;temp.x=zb[i].x;temp.y=zb[i].y;a[j].push_back(temp);flag=0;break;}}if(flag)a[cnt++].push_back(zb[i]);}memset(dp,0,sizeof dp);for(long long i=0;i<cnt;i++){for(long long j=tkk;j>=0;j--){for(long long k=0;k<a[i].size();k++){if(j-a[i][k].t>=0)dp[j]=max(dp[j],dp[j-a[i][k].t]+a[i][k].w);//printf("dp[%d]=%d\n",j,dp[j]);}}}printf("%lld\n",dp[tkk]);}return 0;}
相关文章推荐
- HDU 5326 Work 并查集 (2015 Multi-University Training Contest 3 2015多校联合)
- HDU 5319 Painter (2015 Multi-University Training Contest 3 2015多校联合)
- STL中的模板类pair 和map http://blog.csdn.net/calvin_zcx/article/details/6072286
- hdu 5317 RGCDQ 2015 Multi-University Training Contest 3
- 线程安全C/C++ http://blog.csdn.net/huangxy10/article/details/8068653
- mysql_num_rows()的作用的功能!!! http://zhidao.baidu.com/link?url=E-LmBdz-E5ff5PKfiXucFY-wWBLV4_vt6Cmg2i4k
- 模拟+思维 HDOJ 5319 Painter
- 多校3 1004 Painter
- Train Problem I
- HDU 5319 Painter(模拟)
- EAIPChina航图查看器项目手记
- Design Pattern Explained 读书笔记三——Adapter
- RAID简介
- 20150728多校第三场1004 - Painter
- 2015 Multi-University Training Contest 3 1011
- Leetcode: Contains Duplicate III
- HDU 5316 Magician(2015 Multi-University Training Contest 3 1001)
- 第十六章、Raid及mdadm命令
- ubuntu 安装rails
- HDU 5323 2015 Multi-University Training Contest 3 1008 Solve this interesting problem