题目连接:Codeforces 437C  The Child and Toy

贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std; const int MAX_N = 1000 + 10;
int G[MAX_N][MAX_N]; struct Value
{
int val;
int i;
};
int cmp(Value a, Value b)
{
return a.val > b.val;
}
Value value[MAX_N];
int value1[MAX_N]; int main()
{
memset(G, 0, sizeof(G));
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1;i <= n; i++)
{
scanf("%d", &value[i].val);
value1[i] = value[i].val;
value[i].i = i;
}
int u, v;
for(int i = 0; i < m; i++)
{
scanf("%d%d", &u, &v);
G[u][v] = G[v][u] = 1;
}
sort(value + 1, value + n + 1, cmp);
int sum = 0;
int b;
for(int i = 1; i <= n; i++)
{
b = value[i].i;
for(int j = 1; j <= n; j++)
{
if(G[b][j])
{
sum += value1[j];
G[b][j] = G[j][b] = 0;
}
}
}
printf("%d\n", sum);
return 0;
}

Codeforces 437C The Child and Toy(贪心)的更多相关文章

  1. codeforces 437C The Child and Toy

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

  2. Codeforces 437D The Child and Zoo(贪心+并查集)

    题目链接:Codeforces 437D The Child and Zoo 题目大意:小孩子去參观动物园,动物园分非常多个区,每一个区有若干种动物,拥有的动物种数作为该区的权值.然后有m条路,每条路 ...

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

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

  4. 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/ ...

  5. 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 ...

  6. 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 ...

  7. Codeforces 437B The Child and Set

    题目链接:Codeforces 437B The Child and Set 開始是想到了这样的情况,比方lowbit之后从大到小排序后有这么几个数,200.100,60.50.S = 210.那先选 ...

  8. cf437C The Child and Toy

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

  9. Codeforces 437E The Child and Polygon(间隔DP)

    题目链接:Codeforces 437E The Child and Polygon 题目大意:给出一个多边形,问说有多少种切割方法.将多边形切割为多个三角形. 解题思路:首先要理解向量叉积的性质,一 ...

随机推荐

  1. Node.mongoose

    简介 mongodb是一款面向文档的数据库,不是关系型数据库,新手熟悉mysql.sqlserver等数据库的人可能入手稍微困难些,需要转换一下思想,可以不需要有固定的存储模式,以文档模型为存储内容相 ...

  2. csv批量导入mysql命令

    今天把从Kaggle上下载下来的csv数据导入mysql,想做个统计分析,怎奈csv文件有些大.所以仅仅能用mysql 命令导入,现mark下,以备以后不时之需: 1. 导入: 基本的语法: load ...

  3. android api 中文 (75)—— AdapterView.OnItemClickListener

    前言 本章内容是android.widget.AdapterView.OnItemClickListener,版本为Android 2.3 r1,翻译来自"麦子",欢迎大家与他交流 ...

  4. fopen()函数

    1.2 文件的输入输出函数 键盘.显示器.打印机.磁盘驱动器等逻辑设备, 其输入输出都能够通过文件管理的方法来完毕.而在编程时使用最多的要算是磁盘文件, 因此本节主要以磁盘文件为主, 具体介绍Turb ...

  5. [翻译]Orchard-修改首页布局

    前言 Orchard在你的站点应用的默认主题叫做”Theme Machine”.该主题包括CSS样式和一个布局框架. Orchard 允许你选择或排除显示在你站点每个页面的布局. 默认情况下下图中蓝色 ...

  6. E - Catch That Cow

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...

  7. UIAlertView笔记

    链接地址:http://www.cnblogs.com/scandy-yuan/archive/2013/03/11/2954194.html 1. 最简单的用法 UIAlertView*alert ...

  8. 字节流复制mp3文件(带缓冲区)

    //自定义的缓冲区 import java.io.*; class  MyBufferedInputStream{    private byte[] buf = new byte[1024]; pr ...

  9. javascript学习(9)——[设计模式]单例

    单例模式,相信大家对此都不陌生,我们主要讲下javascript中几个比较常见的设计模式: (1).普通的单体 (2).具有局部变量的强大单体 (3).惰性单体 (4).分支单体 下面我们就一一进行介 ...

  10. 织梦dedecms|图片模型内容页标签

    图片列表开始:{dede:productimagelist}图片列表结束:{/dede:productimagelist}图片显示:     [field:imgsrc/]图集缩略图:  {dede: ...