ZOJ - 3450 Doraemon's Railgun (dp)
https://vjudge.net/problem/ZOJ-3450
题意
一座位落(X0,Y0)的城市将遭受n个敌人的摧残。现在我们手上有某科学的超电磁炮,每次攻击都是一条射线,对于共线的敌人,必须先打倒离得近的。打倒每个敌人需花费Ti时间,并歼灭Wi个小兵。如今只剩下T0时间了!问怎么射击才可杀最多?
分析
把位于同一个射线的敌人分为一组,处于后面的敌人的时间和价值是叠加的。这样进行背包dp。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
#define pi acos(-1.0)
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+;
const int maxm = 1e5+;
const ll mod = 1e9+; struct ND{
ll x,y,t,w;
ND(){}
ND(int _x,int _y,int _t,int _w){ x=_x,y=_y,t=_t,w=_w; }
bool operator <(const ND &a)const{
return x*x+y*y<a.x*a.x+a.y*a.y;
}
}p[];
bool aLine(ND a,ND b){
if(a.x*b.y==a.y*b.x) return a.x*b.x>=&&a.y*b.y>=;
return false;
}
vector<ND> group[];
bool vis[];
ll dp[];
int main(){
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int x0,y0,t,n;
while(~scanf("%d%d%d%d",&x0,&y0,&n,&t)){
for(int i=;i<n;i++){
scanf("%lld%lld%lld%lld",&p[i].x,&p[i].y,&p[i].t,&p[i].w);
group[i].clear();
p[i].x-=x0;
p[i].y-=y0;
}
// if(aLine(p[0],p[1])) puts("YED");
sort(p,p+n);//按距城市的距离排序 memset(vis,false,sizeof(vis));
int cnt=;
for(int i=;i<n;i++){//分组
if(!vis[i]){
group[cnt].push_back(p[i]);
vis[i]=true;
for(int j=i+;j<n;j++){
if(aLine(p[i],p[j])){
vis[j]=true;
if(p[j].t==){
group[cnt][group[cnt].size()-].w+=p[j].w;
continue;
}
group[cnt].push_back(p[j]);
group[cnt][group[cnt].size()-].w+=group[cnt][group[cnt].size()-].w;
group[cnt][group[cnt].size()-].t+=group[cnt][group[cnt].size()-].t;
}
}
cnt++;
}
}
// for(int i=0;i<cnt;i++){
// for(int j=0;j<group[i].size();j++){
// cout<<'('<<group[i][j].x<<','<<group[i][j].y<<')'<<' ';
// }cout<<endl;
// }
memset(dp,,sizeof(dp));
for(int i=;i<cnt;i++){
for(int j=t;j>=;--j){
for(int k=;k<group[i].size()&&group[i][k].t<=j;k++){
dp[j]=max(dp[j],dp[j-group[i][k].t]+group[i][k].w);
}
}
}
cout<<dp[t]<<endl;
} return ;
}
ZOJ - 3450 Doraemon's Railgun (dp)的更多相关文章
- zoj 3706 Break Standard Weight(dp)
Break Standard Weight Time Limit: 2 Seconds Memory Limit: 65536 ...
- ZOJ 3791 An Easy Game(DP)
题目链接 题意 : 给你两个长度为N的字符串,将第一个字符串每次只能变化M个,问变换K次之后变成第二个字符串一共有几种方法. 思路 : DP.dp[i][j]表示变了 i 次之后有j个不一样的字母的方 ...
- ZOJ 1642 Match for Bonus (DP)
题目链接 题意 : 给你两个字符串,两个字符串都有共同的字母,给你每个字母的值,规则是,找出两个字符串中的共同的一个字母,然后这个字母的值就可以加到自己的分数上,但是这步操作之后,这两个字母及其之前的 ...
- ZOJ 3605 Find the Marble(dp)
Find the Marble Time Limit: 2 Seconds Memory Limit: 65536 KB Alice and Bob are playing a game. ...
- ZOJ 1093 Monkey and Banana (LIS)解题报告
ZOJ 1093 Monkey and Banana (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- ZOJ Problem Set - 3829Known Notation(贪心)
ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达 ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
随机推荐
- 解决Altera家的ROM仿真数据一直为0
BUG现象 各种配置都正确,但ROM就是不出数据,输出一直为零. 解决方式 对于rom的仿真,要更改生成的rom文件的一个地方,主要是由于相对路径与绝对路径的问题. 所以最简单的解决方法是把mif文件 ...
- hihocoder#1333 : 平衡树·Splay2 (区间操作)
题面: #1333 : 平衡树·Splay2 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:好麻烦啊~~~~~ 小Hi:小Ho你在干嘛呢? 小Ho:我在干活啊! ...
- 搭建gogs常见问题
1.无法连接ssh,显示connection refuse. 原因是“custom/conf/app.ini”没有开启ssh功能,改为以下配置就行了 START_SSH_SERVER = true ...
- 【LOJ#2542】[PKUWC2018]随机游走(min-max容斥,动态规划)
[LOJ#2542][PKUWC2018]随机游走(min-max容斥,动态规划) 题面 LOJ 题解 很明显,要求的东西可以很容易的进行\(min-max\)容斥,那么转为求集合的\(min\). ...
- 【BZOJ4832】抵制克苏恩(矩阵快速幂,动态规划)
[BZOJ4832]抵制克苏恩(矩阵快速幂,动态规划) 题面 BZOJ 题解 一模一样 #include<iostream> #include<cstdio> using na ...
- CSS 隐藏页面元素的 几 种方法总结
用 CSS 隐藏页面元素有许多种方法.你可以将 opacity 设为 0.将 visibility 设为 hidden.将 display 设为 none 或者将 position 设为 absolu ...
- luogu5007 DDOSvoid 的疑惑 (树形dp)
我们来算每个点出现在的集合的个数 设f[i]为i出现的集合个数,g[i]是只选子树i 可以有多少种选法 那就有$g[i]=1+\prod\limits_{j是i的孩子}{g[j]} , f[i]=f[ ...
- Java复习总结——数据类型
包装类型 八个基本类型: Boolean/boolean/1 Byte/byte/8 Character/char/16 Short/short/16 Integer/int/32 Float/flo ...
- 逗号分隔的字符串与List互转
将逗号分隔的字符串转换为List // 将逗号分隔的字符串转换为List String str = "a,b,c"; // 1.使用JDK,逗号分隔的字符串-->数组--&g ...
- yd的汇总
因为是我这只蒟蒻个人的汇总嘛,可能有些奇♂怪的东西或者不规范的语言出现啦,见谅见谅 搬了一些到知识汇总里,删了一些过时和无用的,少了好多=.= 1.STL_queue 经实践验证,!qs.empty( ...