HDU 4341 - Gold miner
2016-04-26 17:01
435 查看
B - Gold miner
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU
4341
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.
Please help Homelesser get the maximum value.
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
Sample Output
题目模拟黄金矿工的游戏,给出黄金的坐标,每块黄金有自己的耗时和价值,在规定时间内获得最大的价值。因为同一条线上的黄金必须先去上层的才可以去下层的,所以题目转换成分组背包求解。
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU
4341
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.
Please help Homelesser get the maximum value.
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
题目模拟黄金矿工的游戏,给出黄金的坐标,每块黄金有自己的耗时和价值,在规定时间内获得最大的价值。因为同一条线上的黄金必须先去上层的才可以去下层的,所以题目转换成分组背包求解。
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <cstdlib> #include <ctime> #include <bitset> using namespace std; #define N 405 #define F 40005 #define INF 0x3f3f3f3f #define PB push_back struct node{ int x,y,t,v; node(){} node(int xx,int yy,int tt,int vv):x(xx),y(yy),t(tt),v(vv){} }; int n,T; int f[F]; vector<node> a ; bool cmp(node x,node y){ return x.y<y.y; } int gcd(int a,int b){ if (b==0) return a; else return gcd(b,a%b); } int main(){ int kase=0; while (scanf("%d%d",&n,&T)!=EOF){ memset(f,0,sizeof(f)); for (int i=0;i<405;i++) for (int j=0;j<205;j++) a[i][j].clear(); int x,y,t,v; for (int i=0;i<n;i++){ scanf("%d%d%d%d",&x,&y,&t,&v); int GCD=gcd(abs(x),y); int xx=x/GCD; int yy=y/GCD; xx+=200; a[xx][yy].PB(node(x,y,t,v)); } for (int i=0;i<405;i++){ for (int j=0;j<205;j++){ if (a[i][j].size()>0){ sort(a[i][j].begin(),a[i][j].end(),cmp); for (int k=1;k<a[i][j].size();k++){ a[i][j][k].t+=a[i][j][k-1].t; a[i][j][k].v+=a[i][j][k-1].v; } for (int v=T;v>=0;v--){ for (int k=0;k<a[i][j].size();k++){ if (v>=a[i][j][k].t) f[v]=max(f[v],f[v-a[i][j][k].t]+a[i][j][k].v); } } } } } printf("Case %d: %d\n",++kase,f[T]); } return 0; }
相关文章推荐
- go语言特点
- mac上安装google tesseract-ocr
- django admin ModelForm field 验证
- go 前言
- golang打印所有的runtime调用栈
- Yandex.Algorithm 2011 Round 2 D. Powerful array(莫队算法)
- 介绍 GDB 调试 Go
- Django--自定义用户认证
- go语言的GDB调试入门初级
- 用Golang写一个搜索引擎(0x07)
- IntelliJ IDEA 2016.1 使用go-lang-idea-plugin
- go的一些记录
- Golang的TLS通信,证书文件使用.
- UVA_11292_Dragon of Loowater
- mac下配置gdb调试golang
- go 类型系统(二)
- google-v8编译
- django admin site override save_model
- django modeladmin override ModelForm
- Google Heap Profiler