XTUOJ 1252 Defense Tower 贪心
题目链接: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 贪心的更多相关文章
- XTU 1252 Defense Tower
$2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$J$题 贪心. 优先删除$power$大的点. #pragma comment(linker, "/STACK:1024000000, ...
- BZOJ1233 [Usaco2009Open]干草堆tower[贪心+单调队列优化]
地址 注意思路!多看几遍! 很巧妙的一道题.不再是决策点以dp值中一部分含j项为维护对象,而是通过维护条件来获取决策. 首先有个贪心策略,让底层的宽度尽可能小,才能让高度尽可能高.所以应该倒着dp,表 ...
- [ZOJ 3623] Battle Ships
Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a new game which is s ...
- ZOJ3623:Battle Ships(全然背包)
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...
- ZOJ 3623 Battle Ships DP
B - Battle Ships Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
- Battle Ships(复习泛化物品**)
传送门Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a new game which i ...
- zoj3623 Battle Ships
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...
- dp --- hdu 4939 : Stupid Tower Defense
Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- hdu4939 Stupid Tower Defense (DP)
2014多校7 第二水的题 4939 Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131 ...
随机推荐
- POJ 2948 Martian Mining(DP)
题目链接 题意 : n×m的矩阵,每个格子中有两种矿石,第一种矿石的的收集站在最北,第二种矿石的收集站在最西,需要在格子上安装南向北的或东向西的传送带,但是每个格子中只能装一种传送带,求最多能采多少矿 ...
- Lambda Action Func练习
namespace lambda { delegate void TestDelegate(string s); class Program { static void Main(string[] a ...
- JS操作Radio与Select
//radio的chang事件,以及获取选中的radio的值 $("input[name=radioName]").on("change", function( ...
- A. Sorting Railway Cars
A. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 【Linux高频命令专题(17)】head
概述 head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 命令格式 hea ...
- (转)MyEclipse +Servlet
来自:http://www.cnblogs.com/sunada2005/p/3520788.html 在Win7系统下运行自己的第一个Servlet程序,因为有时候配置不当或系统原因可能会运行不成功 ...
- 【c】time.h
表示时间的三种类型 日历时间:从一个时间点到现在的秒数,用time_t表示 始终滴答时间:从进程启动到现在时钟的滴答数(每秒一般包含1000个).用clock_t表示 分解时间:分解的数据结构如下.用 ...
- ProgressBar 示例及自定义样式
在layout中使用ProgerssBar,其中使用了自定义的样式 <ProgressBar android:id="@+id/footer_refresh_prgs" st ...
- NFC(1)NFC简介,3种模式
简介 NFC(Near Field Communication,近场通信),是一种数据传输技术.但与Wi-Fi.蓝牙.红外线等数据传输技术的一个主要差异就 是有效距离一般不能超过4厘米. NFC支持如 ...
- SJ9012: IE6 IE7 不支持 JSON 对象
标准参考 JSON 是一种数据交换格式,RFC 4627 对 JSON 进行了详细描述. 根据 ECMA-262(ECMAScript)第 5 版中描述,JSON 是一个包含了函数 parse 和 s ...