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 ...
随机推荐
- 【XSY2733】Disembrangle DP
题目描述 有一个\(3\times n\)的网格,一些格子里已经有棋子了,一些格子里还没有. 每次你可以选择往一个没有棋子的格子里放一个棋子,但要满足这个格子上下两个格子都有棋子或左右两个格子都有棋子 ...
- 直接使用security.basic.path无效|——springboot2.0以上的security的配置
问题 springcloud 版本 为 Finchley.RELEASEspringboot 版本为 2.0.3.RELEASE 现在有需求,/swagger-ui.html 页面需要添加登录认证,但 ...
- 【HDU4947】GCD Array (莫比乌斯反演+树状数组)
BUPT2017 wintertraining(15) #5H HDU- 4947 题意 有一个长度为l的数组,现在有m个操作,第1种为1 n d v,给下标x 满足gcd(x,n)=d的\(a_x\ ...
- 「ZJOI2016」旅行者 解题报告
「ZJOI2016」旅行者 对网格图进行分治. 每次从中间选一列,然后枚举每个这一列的格子作为起点跑最短路,进入子矩形时把询问划分一下,有点类似整体二分 至于复杂度么,我不会阿 Code: #incl ...
- 「TJOI2015」组合数学 解题报告
「TJOI2015」组合数学 这不是个贪心吗? 怎么都最小链覆盖=最大点独立集去了 注意到一个点出度最多只有2,可以贪心一下出度的去向 按读入顺序处理就可以,维护一个\(res_i\)数组,表示上一行 ...
- day20
20.01 IO流(IO流概述及分类) 1.IO流用来处理设备之间的数据传输 Java对数据的操作是通过流的方式 Java用于操作流的类都在IO包中 字节流:字节流可以操作任何数据,计算机中任何数据都 ...
- kafka命令行脚本使用
zookeeper集群部署:http://www.cnblogs.com/ding2016/p/8280696.html kafka集群部署:http://www.cnblogs.com/ding20 ...
- QML-关于Qt.rgba()颜色无法正常显示问题
GitHub:八至 作者:狐狸家的鱼 本文链接:关于Qt.rgba()颜色的正确写法 当在正常给color属性写颜色的时候,用十六进制能正常显示,但是用Qt.rgba()时,颜色无法正常显示出来. 按 ...
- sh: /etc/init.d/sshd: not found Docker中的Alpine镜像安装sshd无法启动
问题描述 在Alpine镜像中安装了openssh-server和openssh之后,无法执行ssh localhost.发现未启动服务,开启服务时报以下错误 / # ls /etc/init.d/s ...
- 登录rabbitmq报错User can only log in via localhost
在访问管理界面使用guest用户登录时出现login failed错误. 到服务器上查询日志显示出现错误的原因是:HTTP access denied: user ‘guest’ - User can ...