Codeforces Round #250 (Div. 2) C:http://codeforces.com/problemset/problem/437/C

题意:给以一个无向图,每个点都有一点的权值,然后如果要删除一个点的话,会有一定的费用,这个费用是与这个点的相邻的,并且是没有删除的点权值之和。

题解:很简单的,肯定是贪心,因为为了避免权值最大的点对其他点造成影响,所以首先删除的应该是权值最大值。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int n,m,ans;
bool mp[N][N];
int a[N],t1,t2;
struct Node{
int val;
int id;
bool operator<(const Node a)const{
return val>a.val;
}
}num[N];
int main(){
scanf("%d%d",&n,&m);
memset(mp,,sizeof(mp));
ans=;
for(int i=;i<=n;i++){
scanf("%d",&num[i].val);
num[i].id=i;
a[i]=num[i].val;
}
for(int i=;i<=m;i++){
scanf("%d%d",&t1,&t2);
mp[t1][t2]=mp[t2][t1]=;
}
sort(num+,num+n+);
for(int i=;i<=n;i++){
int temp=num[i].id;
for(int i=;i<=n;i++){
if(mp[temp][i]){
ans+=a[i];
mp[temp][i]=mp[i][temp]=;
}
}
}
printf("%d\n",ans); }

The Child and Toy的更多相关文章

  1. Codeforces Round #250 (Div. 1) A. The Child and Toy 水题

    A. The Child and Toy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...

  2. cf437C The Child and Toy

    C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces 437C The Child and Toy(贪心)

    题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...

  4. Codeforces Round #250 Div. 2(C.The Child and Toy)

    题目例如以下: C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input ...

  5. Codeforces The Child and Toy

    The Child and Toy time limit per test1 second On Children's Day, the child got a toy from Delayyy as ...

  6. codeforces 437C The Child and Toy

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  7. Codeforces Round #250 (Div. 2) C、The Child and Toy

    注意此题,每一个部分都有一个能量值v[i],他移除第i部分所需的能量是v[f[1]]+v[f[2]]+...+v[f[k]],其中f[1],f[2],...,f[k]是与i直接相连(且还未被移除)的部 ...

  8. Codeforces #250 (Div. 2) C.The Child and Toy

    之前一直想着建图...遍历 可是推例子都不正确 后来看数据好像看出了点规律 就抱着试一试的心态水了一下 就....过了..... 后来想想我的思路还是对的 先抽象当前仅仅有两个点相连 想要拆分耗费最小 ...

  9. CF(437C)The Child and Toy(馋)

    意甲冠军:给定一个无向图,每个小点右键.操作被拉动所有点逐一将去,直到一个点的其余部分,在连边和点拉远了点,在该点右点的其余的费用.寻找所需要的最低成本的运营完全成本. 解法:贪心的思想,每次将剩余点 ...

随机推荐

  1. JBoss 系列十一:JBoss Cluster Framework Demo 介绍

    内容概要 JBoss Cluster Framework Demo包括JGruops.JBossCache.Infinispan,我们在随后的系列中会使用和运行这些示例来说明JGroups.JBoss ...

  2. Delphi ListView基本用法大全

    //增加项或列(字段) ListView1.Clear; ListView1.Columns.Clear; ListView1.Columns.Add; ListView1.Columns.Add; ...

  3. UVA10972 - RevolC FaeLoN(双连通分量)

    题目链接 题意: 给定一个无向图,问最少加入多少条边,使得这个图成为连通图 思路:首先注意题目给出的无向图可能是非连通的,即存在孤立点.处理孤立点之后.其它就能够当作连通块来处理.事实上跟POJ335 ...

  4. Android性能优化典范 - 第5季

    这是Android性能优化典范第5季的课程学习笔记,拖拖拉拉很久,记录分享给大家,请多多包涵担待指正!文章共10个段落,涉及的内容有:多线程并发的性能问题,介绍了AsyncTask,HandlerTh ...

  5. javascript新的原生态API

    以下是最新的w3c标准的javascript,目前支持运行在firefox, chrome,IE9以上版本的浏览器 参考资料:https://developer.mozilla.org/ru/docs ...

  6. 10.5 noip模拟试题

    2bc*cosA=b^2+c^2-a^2 数学题QAQ 开始π精度不够40分 怪我喽~ #include<iostream> #include<cstdio> #include ...

  7. JavaScript Math对象

    Math对象是JavaScript的一个固有对象,其作用是执行常见的算数任务.该对象的使用并不是像Date,Array对象使用 new关键字来得到对象,而是直接 Math.[{property|met ...

  8. Git CMD - pull: Fetch from and integrate with another repository or a local branch

    命令格式 git pull [options] [<repository> [<refspec>…​]] 命令参数 -q, --quiet 安静模式. -v, --verbos ...

  9. windows sever 2008 r2 - 限制ip访问

    和win 7 旗舰版不同,该操作系统在安装IIS后,非本机的并不能直接访问主机.需要设置主机上的本机的IIS中的IP地址和域限制. 由于我是想在同一个局域网(路由器)中,通过Android操作系统访问 ...

  10. PropertyPlaceholderConfigurer的用法(使用spring提供的类读取数据库配置信息.properties)

    http://www.cnblogs.com/wanggd/archive/2013/07/04/3172042.html(写的很好)