Codeforces 437C The Child and Toy(贪心)
题目连接: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(贪心)的更多相关文章
- codeforces 437C The Child and Toy
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Codeforces 437D The Child and Zoo(贪心+并查集)
题目链接:Codeforces 437D The Child and Zoo 题目大意:小孩子去參观动物园,动物园分非常多个区,每一个区有若干种动物,拥有的动物种数作为该区的权值.然后有m条路,每条路 ...
- CF(437C)The Child and Toy(馋)
意甲冠军:给定一个无向图,每个小点右键.操作被拉动所有点逐一将去,直到一个点的其余部分,在连边和点拉远了点,在该点右点的其余的费用.寻找所需要的最低成本的运营完全成本. 解法:贪心的思想,每次将剩余点 ...
- 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/ ...
- 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 ...
- 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 ...
- Codeforces 437B The Child and Set
题目链接:Codeforces 437B The Child and Set 開始是想到了这样的情况,比方lowbit之后从大到小排序后有这么几个数,200.100,60.50.S = 210.那先选 ...
- cf437C The Child and Toy
C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 437E The Child and Polygon(间隔DP)
题目链接:Codeforces 437E The Child and Polygon 题目大意:给出一个多边形,问说有多少种切割方法.将多边形切割为多个三角形. 解题思路:首先要理解向量叉积的性质,一 ...
随机推荐
- php定界符 <<< 的作用及使用注意事项
按照原样输出,包括换行符.特殊字符等 任何特殊字符都不需要转义,比如双引号.单引号,它会按照原样输出 像在双引号字符串中一样使用php的变量输出 定界符<<<,当需要输出大段文本时, ...
- HDU 3415 Max Sum of Max-K-sub-sequence
题目大意:找长度不超过k的最大字段和. 题解:单调队列维护之前k的最小值,思想是对于每一个入队的新元素,如果队尾元素比其大则一直删减,然后插入新元素,对于队首的元素若与当前枚举两相差超过k则直接删去. ...
- c++ cout 保留小数点位
需要头文件 <iomanip> 输出时需要用 fixed 和 setprecision() fixed代表输出浮点数,setprecision()设置精度. #include <io ...
- View中的onTouchEvent()与setOnTouchListener()中的ontouch()方法的事件处理先后顺序
Touch事件的两种情况 1.覆写View.class中定义的onTouchEvent-->基于事件回调监听方式 @Override public boolean onTouchEvent(Mo ...
- [译]Stairway to Integration Services Level 4 - 增量更新数据
在本文中, 我们说下增量更新数据:即将数据源中更新了的数据替换掉目标表中对应的数据. 更新代码 操作之前我们先把目标表e (dbo.Contact). 的数据改掉 Use AdventureWorks ...
- c#程序添加其他网站的webservice引用。
前言: 有A网站,B网站两个网站独立运行.某一天,需要两个网站进行合作来完成一件事,比如用A网站接收一些数据进行处理,存入中转数据库,B网站定时去取数据进入自己的系统进行处理. 可能我们会先想到在B网 ...
- java覆写hashcode方法
覆写hashcode 1. 把某个非零常数值,例如17,保存在int变量result中: 2. 对于对象中每一个关键域f(指equals方法中考虑的每一个域): 3, boolean型,计算(f? 0 ...
- 基于Win7 Python2.7的Numpy安装包分享
Numpy-1.9.2安装包: http://pan.baidu.com/s/1i3WZRoT 下载后双击安装即可! 另外分享一个安装教程,mark一下慢慢看: http://blog.csdn.ne ...
- Java多线程实现......(1,继承Thread类)
MyThread.java 中的代码: public class MyThread extends Thread{ private int startPrint,printCount; private ...
- python urllib和urllib2 区别
python有一个基础的库叫httplib.httplib实现了HTTP和HTTPS的客户端协议,一般不直接使用,在python更高层的封装模块中(urllib,urllib2)使用了它的http实现 ...