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)的更多相关文章

  1. zoj 3706 Break Standard Weight(dp)

    Break Standard Weight Time Limit: 2 Seconds                                     Memory Limit: 65536 ...

  2. ZOJ 3791 An Easy Game(DP)

    题目链接 题意 : 给你两个长度为N的字符串,将第一个字符串每次只能变化M个,问变换K次之后变成第二个字符串一共有几种方法. 思路 : DP.dp[i][j]表示变了 i 次之后有j个不一样的字母的方 ...

  3. ZOJ 1642 Match for Bonus (DP)

    题目链接 题意 : 给你两个字符串,两个字符串都有共同的字母,给你每个字母的值,规则是,找出两个字符串中的共同的一个字母,然后这个字母的值就可以加到自己的分数上,但是这步操作之后,这两个字母及其之前的 ...

  4. ZOJ 3605 Find the Marble(dp)

    Find the Marble Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice and Bob are playing a game. ...

  5. ZOJ 1093 Monkey and Banana (LIS)解题报告

    ZOJ  1093   Monkey and Banana  (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  6. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  7. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  8. ZOJ Problem Set - 3829Known Notation(贪心)

    ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达 ...

  9. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

随机推荐

  1. 【XSY2190】Alice and Bob VI 树形DP 树剖

    题目描述 Alice和Bob正在一棵树上玩游戏.这棵树有\(n\)个结点,编号由\(1\)到\(n\).他们一共玩\(q\)盘游戏. 在第\(i\)局游戏中,Alice从结点\(a_i\)出发,Bob ...

  2. C#常用的命名规则汇总

    C#常用的命名规则汇总 来源 https://www.cnblogs.com/pengyouqiang88/p/5021128.html 本文转载自脚本之家 本文详细汇总了C#常用的命名规则.分享给大 ...

  3. Mac 部分软件介绍

    1.Pickle可帮你轻松的安装 PHP 扩展,支持所有平台.基于 Composer(PHP的依赖管理器)开发.-----------扩展安装 2.composer parallel install ...

  4. Hdoj 1785.You Are All Excellent 题解

    Problem Description 本次集训队共有30多人参加,毫无疑问,你们都是很优秀的,但是由于参赛名额有限,只能选拔部分队员参加省赛.从学校的角度,总是希望选拔出最优秀的18人组成6支队伍来 ...

  5. 【LOJ6036】编码(2-sat)

    [LOJ6036]编码(2-sat) 题面 LOJ 题解 很显然的一个暴力: 枚举每个串中的?是什么,然后把和它有前缀关系的串全部给找出来,不合法的连边处理一下,那么直接跑\(2-sat\)就做完了. ...

  6. Think Python 2E中译本 _site

    http://codingpy.com/books/thinkpython2/index.html

  7. poj1664放苹果(递归)

    题目链接:http://poj.org/problem?id=1664 放苹果 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: ...

  8. Hello Object Oriented!

    继计组之后,北航计算机学院又一大神课! 希望能以此为契机,和更多热爱技术的朋友们交流.让我们一起,共同进步~ [2019.4.27更新] 建立博客园的最初目的,是为了北航计算机学院OO课程设计的需要. ...

  9. java 数组转字符串 字符串转数组

    字符串转数组 使用Java split() 方法 split() 方法根据匹配给定的正则表达式来拆分字符串. 注意: . . | 和 * 等转义字符,必须得加 \\.多个分隔符,可以用 | 作为连字符 ...

  10. Vue -- 双向过滤器去除html标签

    <div id="box"> <input type="text" v-model="msg | filterHtml"& ...