链接:

https://vjudge.net/problem/CodeForces-437C

题意:

On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.

The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.

Help the child to find out, what is the minimum total energy he should spend to remove all n parts.

思路:

优先选值较大的点去拿,这样值较大的点就被累加的次数小.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL; const int MAXN = 1e3+10;
struct Node
{
int v;
int pos;
bool operator < (const Node& that) const
{
return this->v > that.v;
}
}node[MAXN];
int Map[MAXN][MAXN];
int Val[MAXN];
int n, m; int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= n;i++)
{
cin >> node[i].v;
Val[i] = node[i].v;
node[i].pos = i;
}
int u, v;
for (int i = 1;i <= m;i++)
{
cin >> u >> v;
Map[u][v] = 1;
Map[v][u] = 1;
}
sort(node+1, node+1+n);
int res = 0;
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= n;j++)
{
if (Map[node[i].pos][j])
{
res += Val[j];
Map[node[i].pos][j] = Map[j][node[i].pos] = 0;
}
}
}
cout << res << endl; return 0;
}

CodeForces-437C(贪心)的更多相关文章

  1. Codeforces 437C The Child and Toy(贪心)

    题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...

  2. CodeForces - 893D 贪心

    http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  4. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

  5. CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  6. C - Ordering Pizza CodeForces - 867C 贪心 经典

    C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...

  7. Codeforces 570C 贪心

    题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...

  8. Codeforces 732e [贪心][stl乱搞]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...

  9. Codeforces 721D [贪心]

    /* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一列数a,可以进行k次操作,每次操作可以选取任意一个数加x或者减x,x是固定的数.求如何才能使得这个数列所有数乘积最小. 思路: 贪心...讨 ...

  10. CodeForces - 424B (贪心算法)

    Megacity Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

随机推荐

  1. 关机报 at-spi-bus-launcher

    查看是否有autostart文件夹,有则不建立 mkdir -v ~/.config/autostart 可直接修改/etc/xdg/autostart/at-spi-dbus-bus.desktop ...

  2. 剑指OFFER数据结构与算法分类

    目录 数据结构 算法 数据结构 数组 有序二维数组查找 数组相对位置排序 数组顺时针输出 把数组排成最小的数 数组中的逆序对 扑克牌顺子 数组中重复的数字 构建乘积数组 链表 链表反向插入ArrayL ...

  3. MySQL各种函数/语法

    @limit pos,len select * from table limit 5,10 只显示查出结果的6-15行 ---------------------------------------- ...

  4. 前端,后端,UI,UE,UX,区别到底在哪里?

    前端后端,到低区别在哪里? 其实后端是负责更为复杂的数据逻辑,表处理结构,如何实现一连串的数据提交,包括,数据验证,数据影响,数据计算,数据提取,,,等等. 那么前端负责的是什么呢?数据展示,数据验证 ...

  5. flask 必知必会

    在局域网中让其它电脑访问我的网站 from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): re ...

  6. 线程间通信共享变量和queue

    在多线程中,数据是共享,如何在多线程安全的通信,是首先要可虑的问题的 #线程间的通信 import timeimport threadingfrom threading import RLock de ...

  7. excel常用快捷键和技巧

    1. Ctrl+方向键,对单元格光标快速移动,移动到数据边缘(空格位置). 2. Ctrl+方向键,对单元格光标快速移动,移动到数据边缘(空格位置). 3. Ctrl+A,选择整张表. 4. Ctrl ...

  8. setter 和 getter 高级 以及内存管理初级

    setter 和 getter 的演变,紧接setter 和 getter 初级 1.@property 和  @synthesize 这两个关键字的出现,就是为了剔除代码中的setter方法和get ...

  9. springBoot2.0使用@slf4j注解记录日志

    1. idea上安装Lombok插件 File --> setting --> Plugins 安装完后重启idea 2. 在springboot项目中修改pom.xml,添加如下配置引入 ...

  10. keil格式化项目代码

    有时候需要用到一个功能,就先会在网上找到对应的程序,但是百度直接拿来的程序通常不是很规范.想着keil5要是有一个自动格式化代码的功能就好啦,上网一查还真有!需要一些设置如下(keil4与keil5都 ...