XTU 1252 Defense Tower
$2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$J$题
贪心。
优先删除$power$大的点。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-; const int maxn=;
int p[maxn],n;
vector<int>g[maxn];
struct X { int h,p; }s[maxn];
bool f[maxn]; bool cmp(X a,X b) {return a.p>b.p;}
int main()
{
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
{
scanf("%d",&s[i].p), s[i].h=i;
p[i]=s[i].p;
}
sort(s+,s++n,cmp); memset(f,,sizeof f);
for(int i=;i<=n;i++) g[i].clear();
for(int i=;i<=n-;i++)
{
int a,b; scanf("%d%d",&a,&b);
g[a].push_back(b); g[b].push_back(a);
} LL ans=;
for(int i=;i<=n;i++)
{
for(int j=;j<g[s[i].h].size();j++)
{
int to=g[s[i].h][j];
if(f[to]) continue;
ans=ans+(LL)p[to];
}
f[s[i].h]=;
}
cout<<ans<<endl;
}
return ;
}
XTU 1252 Defense Tower的更多相关文章
- XTUOJ 1252 Defense Tower 贪心
题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1252 思路:考虑每条边对玩家的伤害 假设连接的节点是u,v,破坏 ...
- [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 ...
- Stupid Tower Defense
Problem Description FSF is addicted to a stupid tower defense game. The goal of tower defense games ...
随机推荐
- 【转】在iOS开发中使用FMDB
本文转载自:唐巧的博客 在iOS开发中使用FMDB APR 22ND, 2012 前言 SQLite (http://www.sqlite.org/docs.html) 是一个轻量级的关系数据库.iO ...
- facebook api介绍
转自(http://sls.weco.net/node/10773) 一.Facebook API 基礎概念 Facebook API 概論 : API 最大的好處在於可以讓程式開發人員只需要根據 A ...
- 回调函数 use
$info["fulltext"] = preg_replace_callback( $search2, function($matches) use ($search, $uni ...
- CSS属性合写
animation:[[ animation-name ] || [ animation-duration ] || [ animation-timing-function ] || [ animat ...
- IOS7学习之路十(百度地图API环境搭建)
百度地图官网的API开发教程链接:点击打开链接 我按照他的教程做的总出现"Apple Mach-O linker command failed with exit code 1"的 ...
- 给Amazon ec2 增加卷(Volume)并挂载到系统
给Amazon ec2 增加卷(Volume)并挂载到系统 前言 导师让师弟把实验的网站挂到亚马逊的EC2云服务器上.师弟对linux不太熟悉.就跑过来问我.于是花了一个小时搞定.问题主要是将EC2的 ...
- JavaScript中变量声明有var和没var的区别
JavaScript中变量声明有var和没var的区别 JavaScript中有var和没var的区别 Js中的变量声明的作用域是以函数为单位,所以我们经常见到避免全局变量污染的方法是 (functi ...
- axis1,xfire,jUnit 测试案列+开Web Service开发指南+axis1.jar下载 代码
axis1,xfire,jUnit 测试案列+Web Service开发指南(中).pdf+axis1.jar下载 代码 项目和资源文档+jar 下载:http://download.csdn. ...
- javascript ajax 脚本跨域调用全解析
javascript ajax 脚本跨域调用全解析 今天终于有点时间研究了一下javsscript ajax 脚本跨域调用的问题,先在网上随便搜了一下找到一些解决的办法,但是都比较复杂.由是转到jqu ...
- [转]Python tips: 什么是*args和**kwargs?
Python tips: 什么是*args和**kwargs? 原文地址:http://www.cnblogs.com/fengmk2/archive/2008/04/21/1163766.html ...