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. 【XSY1552】自动机 构造

    题目大意 给你一个自动机,包含\(n\)个状态,指令集为前\(m\)个小写字母,对于每个状态\(s\)和每个指令\(i\),自动机均有后继\(T(s,i)\).请你求出一个长度不超过\(2^{20}\ ...

  2. SSL加速卡调研的原因及背景

    SSL加速卡调研的原因及背景 SSL加速卡调研的原因及背景 网络信息安全已经成为电子商务和网络信息业发展的一个瓶颈,安全套接层(SSL)协议能较好地解决安全处理问题,而SSL加速器有效地提高了网络安全 ...

  3. WINDOWS 包管理器 Chocolatey

    https://chocolatey.org/ - 官网 安装: @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe& ...

  4. Web页面执行shell命令

    本文以apache为web服务器为例 安装apache服务yum -y install httpd 启动apachesystemctl restart httpd 创建shell脚本cd /var/w ...

  5. [POI2012]STU-Well(二分答案+神仙操作)

    给定一个非负整数序列A,每次操作可以选择一个数然后减掉1,要求进行不超过m次操作使得存在一个Ak=0且max{|Ai−Ai+1|}最小,输出这个最小lk以及最小值. Solution 最大值最小,显然 ...

  6. 【Linux】linux中文本操作利器grep,awk,sed

    grep命令 grep(global search regular expression)是一种强大的文本搜索工具,它可以使用正则表达式搜索文本,并把匹配的行打印出来.平时搜索文本中内容的时候是非常方 ...

  7. jsp model1

    一.model1(纯jsp技术): 1.dao:data access object,数据访问对象,即专门对数据库进行操作的类,一般说dao不含业务逻辑. 2.当进行跳转时候,需要用servlet来实 ...

  8. Transactional ejb 事务陷阱

    对应ejb,默认是对整个类使用事务.所以所有方法都开启事务. 而对于用TransactionAttribute注释来引用容器管理的事务,只能在第一级的方法中使用.对应类中的方法再调用其它类中方法,注释 ...

  9. 【SDOI2008】仪仗队

    //裸的欧拉函数//y=kx//求不同的k有多少#include<bits/stdc++.h> #define ll long long #define N 40010 using nam ...

  10. SRM 605 div 2 T3

    #include <bits/stdc++.h> #define Mo 1000000007 #define MAXN 50 #define MAXK 10 using namespace ...