【CERC2014】【BZOJ3928】【BZOJ4048】Outer space invaders
2016-02-03 09:08
537 查看
Description
The aliens from outer space have (finally!) invaded Earth. Defend yourself, or be disintegrated!
Or assimilated. Or eaten. We are not yet sure.
The aliens follow a known attack pattern. There are ‘n attackers, the i-th one appears at time
ai, at distance di from you. He must be destroyed no later than at time bi, or else he will fire his
weapon, which will definitely end the fight.
Your weapon is an area-blaster, which can be set to any given power. If fired with power R,
it momentarily destroys all aliens at distance R or smaller. It also consumes R fuel cells.
Determine the minimal cost (measured in fuel cells) of destroying all the aliens, without being
killed.
有N个外星人,第i个外星人会在ai时间出现,离你距离di,并且必须在bi之前被消灭。你有一把很NB的武器,攻击范围是个半径为R的圆,R可以任意调整,不过你以R的范围每攻击一次就要消耗R单位能量。外星人被攻击一次就会死掉。求需要消灭所有外星人的最小消耗能量。
N<=300, ai,bi,di<=10000
Input
The first line of input contains the number of test cases T. The descriptions of the test cases
follow:
Each test case starts with a line containing the number of aliens n (1《 n≤ 300). Of the next
n lines, the i-th one contains three integers ai, bi, di, (1 < ai < bi≤ 10 000; I < di≤ 10 000).
The i-th alien appears at time ai, is idle until bi, and his distance from vou is di.
Output
For each test case, output one line containing the mimmum number of cells needed to destrov
all the aliens.
Sample Input
1
3
1 4 4
4 7 5
3 4 7
Sample Output
7
HINT
Source
双倍经验大法好
可以把外星人看成有权值的线段
然后区间DP
The aliens from outer space have (finally!) invaded Earth. Defend yourself, or be disintegrated!
Or assimilated. Or eaten. We are not yet sure.
The aliens follow a known attack pattern. There are ‘n attackers, the i-th one appears at time
ai, at distance di from you. He must be destroyed no later than at time bi, or else he will fire his
weapon, which will definitely end the fight.
Your weapon is an area-blaster, which can be set to any given power. If fired with power R,
it momentarily destroys all aliens at distance R or smaller. It also consumes R fuel cells.
Determine the minimal cost (measured in fuel cells) of destroying all the aliens, without being
killed.
有N个外星人,第i个外星人会在ai时间出现,离你距离di,并且必须在bi之前被消灭。你有一把很NB的武器,攻击范围是个半径为R的圆,R可以任意调整,不过你以R的范围每攻击一次就要消耗R单位能量。外星人被攻击一次就会死掉。求需要消灭所有外星人的最小消耗能量。
N<=300, ai,bi,di<=10000
Input
The first line of input contains the number of test cases T. The descriptions of the test cases
follow:
Each test case starts with a line containing the number of aliens n (1《 n≤ 300). Of the next
n lines, the i-th one contains three integers ai, bi, di, (1 < ai < bi≤ 10 000; I < di≤ 10 000).
The i-th alien appears at time ai, is idle until bi, and his distance from vou is di.
Output
For each test case, output one line containing the mimmum number of cells needed to destrov
all the aliens.
Sample Input
1
3
1 4 4
4 7 5
3 4 7
Sample Output
7
HINT
Source
双倍经验大法好
可以把外星人看成有权值的线段
然后区间DP
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define GET (ch>='0'&&ch<='9') #define MAXN 310 using namespace std; int T,n; int sta[MAXN<<1],top,cnt; int a[MAXN],b[MAXN],d[MAXN]; int f[MAXN<<1][MAXN<<1]; void in(int &x) { char ch=getchar();x=0; while (!GET) ch=getchar(); while (GET) x=x*10+ch-'0',ch=getchar(); } int main() { in(T); while (T--) { in(n);top=0;cnt=0; for (int i=1;i<=n;i++) in(a[i]),in(b[i]),in(d[i]),sta[++top]=a[i],sta[++top]=b[i]; sort(sta+1,sta+top+1); for (int i=1;i<=top;i++) if (i==1||sta[i]!=sta[i-1]) sta[++cnt]=sta[i]; for (int i=1;i<=n;i++) a[i]=lower_bound(sta+1,sta+cnt+1,a[i])-sta,b[i]=lower_bound(sta+1,sta+cnt+1,b[i])-sta; cnt++; for (int l=0;l<=cnt;l++) for (int i=0;i<=cnt-l;i++) { int j=i+l,x=0; for (int k=1;k<=n;k++) if (i<a[k]&&b[k]<j&&d[x]<d[k]) x=k; if (x==0) f[i][j]=0; else { f[i][j]=0x3f3f3f3f; for (int k=a[x];k<=b[x];k++) f[i][j]=min(f[i][j],d[x]+f[i][k]+f[k][j]); } } printf("%d\n",f[0][cnt]); } }
相关文章推荐
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- LFC1.0.0 版本发布
- Android px、dp、sp之间相互转换
- HP data protector软件学习1--基本角色与基本工作流程
- HP data protector软件学习2--软件组成与界面介绍
- android中像素单位dp、px、pt、sp的比较
- Android对px和dip进行尺寸转换的方法
- Android根据分辨率进行单位转换-(dp,sp转像素px)
- android 尺寸 dp,sp,px,dip,pt详解
- DP问题各种模型的状态转移方程
- POJ-1695-Magazine Delivery-dp
- nyoj-1216-整理图书-dp
- TYVJ1193 括号序列解题报告
- 对DP的一点感想
- TYVJ上一些DP的解题报告
- soj1005. Roll Playing Games
- 01背包问题
- LeetCode之Maximum Product Subarray
- DP Flow