题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1252

思路:考虑每条边对玩家的伤害

假设连接的节点是u,v,破坏力是p[u]和p[v]

假设p[u]>p[v]

现在考虑u,v的删除顺序,如果先删u,这条边对玩家的伤害,是p[v],先删v,伤害是p[u]

所以显然对于每条边,我们都要先删权值大的,才能最好

怎么样才能对于每条边先删最大的呢,那就按照权值递减删就好了

所以 ret=Σ(min(p[u],p[v]))

复杂度O(n)

#include <cstdio>
using namespace std;
const int N=1e5+;
int p[N];
int main(){
int n;
while(~scanf("%d",&n)){
for(int i=;i<=n;++i)
scanf("%d",&p[i]);
int ret=;
for(int i=;i<n;++i){
int u,v;
scanf("%d%d",&u,&v);
ret+=min(p[u],p[v]);
}
printf("%d\n",ret);
}
return ;
}

XTUOJ 1252 Defense Tower 贪心的更多相关文章

  1. XTU 1252 Defense Tower

    $2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$J$题 贪心. 优先删除$power$大的点. #pragma comment(linker, "/STACK:1024000000, ...

  2. BZOJ1233 [Usaco2009Open]干草堆tower[贪心+单调队列优化]

    地址 注意思路!多看几遍! 很巧妙的一道题.不再是决策点以dp值中一部分含j项为维护对象,而是通过维护条件来获取决策. 首先有个贪心策略,让底层的宽度尽可能小,才能让高度尽可能高.所以应该倒着dp,表 ...

  3. [ZOJ 3623] Battle Ships

    Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which is s ...

  4. ZOJ3623:Battle Ships(全然背包)

    Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...

  5. ZOJ 3623 Battle Ships DP

    B - Battle Ships Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

  6. Battle Ships(复习泛化物品**)

    传送门Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which i ...

  7. zoj3623 Battle Ships

    Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...

  8. dp --- hdu 4939 : Stupid Tower Defense

    Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  9. hdu4939 Stupid Tower Defense (DP)

    2014多校7 第二水的题 4939 Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131 ...

随机推荐

  1. MySQL 建表字段长度的限制

    脑补,varchar(N),N指的是最大字符数,不是字节数. 先上测试说明:   在MySQL建表时,遇到一个奇怪的现象: root@localhost : test 10:30:54>CREA ...

  2. Csharp日常笔记

    1. 1.退出程序                   this.Close();             //方法退关闭当前窗口. Application.Exit();       //方法退出整 ...

  3. [iOS]iPhone进行真机测试(基础版)

    买完688个人开发者账号之后,如何进行真机测试呢??看下面 1.打开https://developer.apple.com 然后,输入我们买过688点那个App ID帐号和密码哦!!一定是要支付过的! ...

  4. tomcat中如何运行war包呢

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPQAAADRCAIAAAB0LAgsAAAQtklEQVR4nO2d7W/bxh3H9ZfZbRrFOj

  5. iOS:自定义工具栏、导航栏、标签栏

    工具栏为UIToolBar,导航栏UINavigationBar,标签栏UITabBar.它们的样式基本上时差不多的,唯一的一点区别就是,工具栏一般需要自己去创建,然后添加到视图中,而导航栏和标签栏不 ...

  6. PCL—低层次视觉—点云分割(超体聚类)

    1.超体聚类——一种来自图像的分割方法 超体(supervoxel)是一种集合,集合的元素是“体”.与体素滤波器中的体类似,其本质是一个个的小方块.与之前提到的所有分割手段不同,超体聚类的目的并不是分 ...

  7. vs2012 arcgis engine 10 丢失arcgis模板

    1.Visual Studio 2012环境下安装ArcGIS Engine 10 Visual Studio 2012环境下安装ArcObject SDK for the Microsoft .Ne ...

  8. navigationbar的一些设置记录

    1.设置navigationbar背景颜色 [[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]]; PS:如果颜色不对 ...

  9. option配置

    wildignore:用来设置忽略的文件匹配模式,shell模式

  10. apk反编译(4)Smali代码注入

    转自 : http://blog.sina.com.cn/s/blog_5674d18801019i89.html 应用场景 Smali代码注入只能应对函数级别的移植,对于类级别的移植是无能为力的.具 ...