# Gold miner

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 705    Accepted Submission(s): 300

Problem Description
Homelesser likes playing Gold miners in class. He has to pay much attention to the teacher to avoid being noticed. So he always lose the game. After losing many times, he wants your help.

To make it easy, the gold becomes a point (with the area of 0). You are given each gold's position, the time spent to get this gold, and the value of this gold. Maybe some pieces of gold are co-line, you can only get these pieces in order. You can assume it can turn to any direction immediately.

Input
There are multiple cases.
In each case, the first line contains two integers N (the number of pieces of gold), T (the total time). (0＜N≤200, 0≤T≤40000)
In each of the next N lines, there four integers x, y (the position of the gold), t (the time to get this gold), v (the value of this gold). (0≤|x|≤200, 0＜y≤200,0＜t≤200, 0≤v≤200)

Output
Print the case number and the maximum value for each test case.

Sample Input
3 10 1 1 1 1 2 2 2 2 1 3 15 9 3 10 1 1 13 1 2 2 2 2 1 3 4 7

Sample Output
Case 1: 3 Case 2: 7

Source

Recommend
zhuyuanchen520

1斜率小，2，3斜率相同，4，5，6斜率相同。那分三组(1),(2,3),(4,5,6)

#include <stdio.h>
#include <algorithm>
#include<math.h>
#include <string.h>
using namespace std;
struct st
{
int x;
int y;
int v;
int w;
}no[300],u[300][300];
int   cmp(const void *a,const void *b)
{
double k1,k2;
k1=(double)(*(struct st *)a).x/(*(struct st *)a).y;
k2=(double)(*(struct st *)b).x/(*(struct st *)b).y;
if(fabs(k1-k2)>0.000001) return k1>k2?1:-1;//先把斜率 按从小到大排列
//    if(k1==k2) return k1>k2?1:-1;//先把斜率 按从小到大排列 注意对于浮点型的二级排序要特别注意 千万不要直接比较是否相等
else return (*(struct st *)a).y>(*(struct st *)b).y?1:-1;//从小到大
}

int shu[300];
int dp[50009];
int mm=1;
int main()
{
int i,j,m,n;
while(scanf("%d%d",&m,&n)!=EOF)
{
for(i=0;i<m;i++)
{
scanf("%d%d%d%d",&no[i].x,&no[i].y,&no[i].w,&no[i].v);
}
//sort(no,no+m,cmp);
qsort(no,m,sizeof(no[0]),cmp);
int cos=0;
memset(shu,0,sizeof(shu));

for(i=0;i<m;i++)
{
u[cos][shu[cos]].x=no[i].x;
u[cos][shu[cos]].y=no[i].y;
u[cos][shu[cos]].w=no[i].w;
u[cos][shu[cos]].v=no[i].v;
shu[cos]++;
if(i!=m-1)
{
while(i!=m-1&&(double)no[i+1].x/no[i+1].y==(double)no[i].x/no[i].y)
{
u[cos][shu[cos]].x=no[i+1].x;
u[cos][shu[cos]].y=no[i+1].y;
u[cos][shu[cos]].w=u[cos][shu[cos]-1].w+no[i+1].w;
u[cos][shu[cos]].v=u[cos][shu[cos]-1].v+no[i+1].v;
shu[cos]++;
i++;
}
cos++;
}
}

int k;
memset(dp,0,sizeof(dp));
for(i=0;i<=cos;i++)
{
for(j=n;j>=0;j--)
{
for(k=0;k<shu[i];k++)
{
//    if(j-u[i][k].w>=0&&dp[j]<dp[j-u[i][k].w]+u[i][k].v)
if(j-u[i][k].w>=0)
dp[j]=dp[j]>dp[j-u[i][k].w]+u[i][k].v?dp[j]:dp[j-u[i][k].w]+u[i][k].v;
}
}
}
printf("Case %d: ",mm++);
printf("%d\n",dp[n]);
}
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：hdu 4341 Gold miner 需要处理的分组背包 蛮有意义的题目 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)