题目连接: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. Oracle select into from 和 insert into select

    select into from SQLSERVER  创建表: select * into aaa from bbb Oracle 创建表: create table aaa as select * ...

  2. BZOJ 1724: [Usaco2006 Nov]Fence Repair 切割木板

    题目 1724: [Usaco2006 Nov]Fence Repair 切割木板 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer ...

  3. Cocos2d-x 3.0 使用TinyXml 解析XML文件

    在cocos2d-x 3.0中Xml解析已经不用自己找库了,已经为我们集成好了. text.xml <!--?xml version ="1.0" encoding =&qu ...

  4. Jsp中使用EL表达式对字符串进行操作

    用fn函数:<%@ taglib prefix="fn" uri="http://Java.sun.com/jsp/jstl/functions" %&g ...

  5. Java跨域以及实现原理

    最近研究了一下跨域,没接触之前我的印象就是配合单点登录的一种方式,后来在网上看到资料才知道不仅仅是这一种,用法很多,具体的可以去网上搜索. 一个众所周知的问题,Ajax直接请求普通文件存在跨域无权限访 ...

  6. Dojo实现Tabs页报错(三)

    用Dojo实现tab页的过程中,没有引用“on.js”,但是firebug调试时一直提示如下错误: on.js源码如下: define(["./has!dom-addeventlistene ...

  7. Python网络编程——处理套接字错误

    在网络应用中,经常会遇到这种情况:一方尝试连接,但另一方由于网络媒介失效或者其他原因无法响应. Python的Socket库提供了一个方法,能通过socket.error异常优雅地处理套接字错误. 1 ...

  8. Python之路:Python 函数

    一.函数式编程:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装 二. 函数的定义和使用 def 函数名(参数): ... 函数体 ... 函数的定义主要有 ...

  9. django 基础入门(一)

    1. django 基本命令 新建project django-admin.py startproject project-name 新建app python manage.py startapp a ...

  10. Qt之OpenSSL(有pro文件的路径格式)

    简述 OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法.常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用. 简述 下载安装 使用 更多参考 下载安装 ...