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. 【XSY1162】鬼计之夜 最短路

    题目描述 给你一个\(n\)个点\(m\)条边的有向图,有\(k\)个关键点.求一条最短的从一个关键点到另一个关键点的路径. \(n,m,k\leq 100000\) 题解 跑\(k^2\)次最短路显 ...

  2. bzoj 3631 松鼠的新家 (树链剖分)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3631 思路: 直接用树链剖分求每一次运动,因为这道题只需要区间增添,单点求值,没必要用线段 ...

  3. THUSC2017 Day1题解

    THUSC2017 Day1题解 巧克力 题目描述 "人生就像一盒巧克力,你永远不知道吃到的下一块是什么味道." 明明收到了一大块巧克力,里面有若干小块,排成n行m列.每一小块都有 ...

  4. Codeforces Round #517 Div. 2/Div. 1

    \(n\)天没更博了,因为被膜你赛的毒瘤题虐哭了... 既然打了这次CF还是纪念一下. 看看NOIP之前,接下来几场的时间都不好.这应该是最后一场CF了,差\(4\)分上紫也是一个遗憾吧. A 给一个 ...

  5. Codeforces Round #432 (Div. 1, based on IndiaHacks Final Round 2017) D. Tournament Construction(dp + 构造)

    题意 一个竞赛图的度数集合是由该竞赛图中每个点的出度所构成的集合. 现给定一个 \(m\) 个元素的集合,第 \(i\) 个元素是 \(a_i\) .(此处集合已经去重) 判断其是否是一个竞赛图的度数 ...

  6. luogu5007 DDOSvoid 的疑惑 (树形dp)

    我们来算每个点出现在的集合的个数 设f[i]为i出现的集合个数,g[i]是只选子树i 可以有多少种选法 那就有$g[i]=1+\prod\limits_{j是i的孩子}{g[j]} , f[i]=f[ ...

  7. Testlink解决大用例导入问题

    最近公司同事需要将别的testlink的用例迁移过来,由于现在新的服务器也在使用,不能使用数据库导入的办法,只能用xml文件进行导入,不过在导入的时候出现了个没遇到的问题,报错文件太大,无法上传. 解 ...

  8. NOIp2018爆零记

    Day-2~Day0 考前抱佛脚,赶紧刷刷各种模板 Day 1 在开考之前打好了拍子模板,然后试题密码就发下来了(这是我前面的神仙打了\(100\)多行\(emacs\)的配置\(QAQ\)). 先按 ...

  9. Python3 与 C# 面向对象之~封装

      在线编程:https://mybinder.org/v2/gh/lotapp/BaseCode/master在线预览:http://github.lesschina.com/python/base ...

  10. QML学习笔记(三)-引入Font-awesome

    作者: 狐狸家的鱼 Github: 八至 1.首先得在qml文件夹下建立字体文件,将font-awesome放入进去 2.然后在main.cpp中注册字体 引入中一定要写上 引用字体 引用字体得路径一 ...