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. uvalive 2326 - Moving Tables(区间覆盖问题)

    题目连接:2326 - Moving Tables 题目大意:在一个走廊上有400个教室, 先在有一些桌子要移动, 每次移动需要十分钟, 但是不同房间的桌子可以在同一个十分钟内移动,只要走廊没有被占用 ...

  2. MyBatis Tutorial – CRUD Operations and Mapping Relationships – Part 1---- reference

    http://www.javacodegeeks.com/2012/11/mybatis-tutorial-crud-operations-and-mapping-relationships-part ...

  3. IOS-NSDateFormatter使用介绍

    IOS-NSDateFormatter使用介绍 NSDateFormatter的使用: NSDate *nowDate = [[NSDate alloc] init]; NSDateFormatter ...

  4. Java基础知识强化之集合框架笔记18:List集合特有的ListIterator迭代器

    1. ListIterator(列表迭代器): ListIterator listIterator():List集合特有的迭代器 2. 代码示例: package cn.itcast_04; impo ...

  5. PHP中的循环while、do...while、for、foreach四种循环。

    php中的while循环,循环执行代码块制定的次数,或者当指定的条件为真时循环执行代码块. 在我们编写代码是时候,我们经常需要一块代码块重复执行多次.我们就可以使用while循环语句来完成这个任务. ...

  6. Unity3D 创建一个简单的2D游戏

    开始研究Unity3d 中的2D游戏. 首先创建出一个项目: 然后创建出一个场景: 然后添加一个背景: 然后创建一个主人公对象: 可以是自己做的素材,也可以是用unity裁剪的素材, 下面贴出裁剪素材 ...

  7. WisDom.Net 框架设计(三) 数据缓存

    WisDom.Net  --数据缓存 1.几种缓存方式       1.静态全局变量 C#静态变量使用 static 修饰符进行声明,在类被实例化时创建,通过类进行访问不带有 static 修饰符声明 ...

  8. 在vSphere5.0虚拟机里的Ubuntu Server 32位安装JDK

    本机操作系统Win7 服务器用vSphere 5.0 虚拟机  在虚拟机安装了Ubuntu Server 12.04 1.首先到Oracle官网上下载jdk-7u51-linux-i586.tar.g ...

  9. oracle中用comment on的用法

    oracle中用comment on命令给表或字段加以说明,语法如下:COMMENT ON  { TABLE [ schema. ]    { table | view }  | COLUMN [ s ...

  10. 异常练习一 throw

    package 异常练习;class OutageroudleException extends RuntimeException{ OutageroudleException(){ } Outage ...