$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的更多相关文章

  1. XTUOJ 1252 Defense Tower 贪心

    题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1252 思路:考虑每条边对玩家的伤害 假设连接的节点是u,v,破坏 ...

  2. [ZOJ 3623] Battle Ships

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

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

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

  4. ZOJ 3623 Battle Ships DP

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

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

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

  6. zoj3623 Battle Ships

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

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

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

  8. hdu4939 Stupid Tower Defense (DP)

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

  9. Stupid Tower Defense

    Problem Description FSF is addicted to a stupid tower defense game. The goal of tower defense games ...

随机推荐

  1. c#计算2个字符串的相似度

    直接来代码 public static float levenshtein(string str1, string str2) { //计算两个字符串的长度. int len1 = str1.Leng ...

  2. copy指定目录下包括子目录中所有的文件

    #include <windows.h> #include <iostream> #include <string> using namespace std; DW ...

  3. Bootstrap3.0(进度条、媒体对象、列表组、面板)

    Bootstrap3.0学习第十六轮(进度条.媒体对象.列表组.面板) 前言 阅读之前您也可以到Bootstrap3.0入门学习系列导航中进行查看http://www.cnblogs.com/aehy ...

  4. Quartz表达式生成器

    Java版的Quartz表达式生成器,同时适用于Quartz.net(免费下载) Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,它可以与J2EE与J2 ...

  5. 反向代理-- WEB服务的加速器[转]

    昨天j.L问我http cache怎么设置,当时脑子有点糊涂,一时没想到其实他问的就是反向代理如何设置. 首发:PHP CUP xiaobao 什么是反向代理?反 向代理就是代理服务器(如ISA.Sq ...

  6. IOS学习之路(二十五)UIView动画,弹出后移动然后消失

    首先在viewdidload中添加UIlable并且把其设为隐藏 然后在点击按钮后,让其弹出移动后消失 //点击按钮后: #pragma mark 点击关注按钮 - (IBAction)guanzhu ...

  7. hone hone clock人体时钟

    hone hone clock是个十分有趣的人体时钟,这个时钟代码分两种一种是背景透明的,一种 是白色背景的,把你喜欢的代码添加到你的网页中适当位置即可.两种代码如下: <script char ...

  8. iOS多线程的初步研究

    iOS多线程的初步研究(四) 理解run loop后,才能彻底理解NSTimer的实现原理,也就是说NSTimer实际上依赖run loop实现的. 先看看NSTimer的两个常用方法: + (NST ...

  9. EM算法详解

    EM算法详解 1 极大似然估计 假设有如图1的X所示的抽取的n个学生某门课程的成绩,又知学生的成绩符合高斯分布f(x|μ,σ2),求学生的成绩最符合哪种高斯分布,即μ和σ2最优值是什么? 图1 学生成 ...

  10. asp.net通用查询模块设计

    asp.net通用查询模块设计 前言 自从上次狂喷了devexpress for asp.net面向互联网的app的各种不合理,好像骂的dev无处容身了,不过说实话,dev在做互联网的app时,生成的 ...