题目连接: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. HDU 3802 Ipad,IPhone

    http://wutyyzchangde.blog.163.com/blog/static/172226566201132311311374/ #include <cstdio> type ...

  2. vs2013搭建团队版本控制 TFS、SVN

    项目使用vs2013开发,之前使用过svn进行版本控制,由于长时间未使用,记录备用. 一.TFS Team Foundation Server(TFS) 是微软提供的一个团队协同办公的管理工具,项目总 ...

  3. [置顶] JDK-CountDownLatch-实例、源码和模拟实现

    Conception A synchronization aid that allows one or more threads to wait until a set of operations b ...

  4. Java输入输出流(1)

    1.什么是IO Java中I/O操作主要是指使用Java进行输入,输出操作. Java全部的I/O机制都是基于数据流进行输入输出,这些数据流表示了字符或者字节数据的流动序列.Java的I/O流提供了读 ...

  5. Ext JS学习第九天 Ext基础之 扩展原生的javascript对象

    此文来记录学习笔记: •Ext对于原生的javascript对象进行了一系列的扩展,我们把他们掌握好,更能深刻的体会Ext的架构,从而对我们的web开发更好的服务, 源码位置,我们可以从开发包的这个位 ...

  6. UltraEdit中java代码换行问题

    在很多开发中始用的文本编辑器中UltraEdit是非常主流的种了,但是,随着版本的更新,最近几版中出现了以下问题 问题描述:当用UltraEd(14.0版本)编写Java代码时,当遇到{}换行时,希望 ...

  7. Chrome Firefox 自定义背景色

    Chrome有个自定义背景色的文件  Custom.css 默认里面什么字都没写 html, body {background-color: #e0dcc0!important;}      这个颜色 ...

  8. C# Base64解码 二进制输出

    具体的:Base64编码解码还需要学习 /// <summary> /// base64 解码Excel下载 /// </summary> /// <param name ...

  9. QT学习 之 文本文件读写

    上一章我们介绍了有关二进制文件的读写.二进制文件比较小巧,却不是人可读的格式.而文本文件是一种人可读的文件.为了操作这种文件,我们需要使用QTextStream类.QTextStream和QDataS ...

  10. jquery-1.10.2.min.js之Multiple markers at this line

    1.windows-preferences  输入validation 2. 点击进入  3. 将JavaScript validator for js files 的两个对勾去了就OK!     4 ...