题目链接: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. Android AlarmManager的取消

    取消alarm使用AlarmManager.cancel()函数,传入参数是个PendingIntent实例. 该函数会将所有跟这个PendingIntent相同的Alarm全部取消,怎么判断两者是否 ...

  2. 典型重构3 (Try/Catch)

    Try/Catch 块过多 public Customer GetCustomer(string customerId) { try { var command = new SqlCommand(); ...

  3. Windows7查看本地Java安装是否成功和路径的方法

    1. 在电脑开始出,点击运行,输入:CMD.右击图标以管理员身份运行.

  4. Project Euler 85 :Counting rectangles 数长方形

    Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...

  5. lintcode 中等题:N Queens N皇后问题

    题目: N皇后问题 n皇后问题是将n个皇后放置在n*n的棋盘上,皇后彼此之间不能相互攻击.<不同行,不同列,不同对角线> 给定一个整数n,返回所有不同的n皇后问题的解决方案. 每个解决方案 ...

  6. [hackerrank]John and GCD list

    https://www.hackerrank.com/contests/w8/challenges/john-and-gcd-list 简单题,GCD和LCM. #include <vector ...

  7. 在C#中实现Python的分片技术

    在C#中实现Python的分片技术 前言 之前在学习Python的时候发现Python中的分片技术超好玩的,本人也是正则表达式热爱狂,平时用C#比较多,所以决定把Python中的分片技术在C#中实现, ...

  8. P25、面试题1:赋值运算符函数

    题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString { public: CMyString(char* pData = NULL); CMyStr ...

  9. cas单点登出

    由于项目需求要实现单点登出需要在网上找了N久终于实现单点登出. 使用cas-server-core-3.3.3.jar(CAS Server 3.3.3) 使用cas-client-core-3.1. ...

  10. C++ STL之deque的基本操作

    前两篇博文中已经介绍了vector和list的两种容器,我们发现他们各有各的优缺点,vector在内存中连续存储,支持随机访问,但是查找和删除的效率比较低,而list在内存中是链式存储的查找和删除的效 ...