CF(437C)The Child and Toy(贪心)
2014-06-02 00:23
387 查看
题意:给出一个无向图,每个点有点权,操作是一个一个将所有点揪走直至剩下一个点,揪走一个点的代价是剩下点中与其连边的点的点权和。求完成操作所需花费的最小代价。
解法:贪心的思想,每次将剩余点中点权最大的点揪出,这样可以保证每条边都是会选择相对小的点权被消耗掉。所以直接输出所有边的边权和即可。
代码:
解法:贪心的思想,每次将剩余点中点权最大的点揪出,这样可以保证每条边都是会选择相对小的点权被消耗掉。所以直接输出所有边的边权和即可。
代码:
/****************************************************** * author:xiefubao *******************************************************/ #pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <queue> #include <vector> #include <algorithm> #include <cmath> #include <map> #include <set> #include <stack> #include <string.h> //freopen ("in.txt" , "r" , stdin); using namespace std; #define eps 1e-8 const double pi=acos(-1.0); typedef long long LL; const int Max=10100; const int INF=1000000007; int num[Max]; int n,m; int main() { cout<<390/21.0<<endl; while(scanf("%d%d",&n,&m)==2) { for(int i=1;i<=n;i++) scanf("%d",num+i); int ans=0; for(int i=0;i<m;i++) { int a,b;scanf("%d%d",&a,&b); ans+=min(num[a],num[b]); } cout<<ans<<endl; } return 0; }
相关文章推荐
- CF(437C)The Child and Toy(馋)
- codeforces-437C-The Child and Toy
- Codeforces Round #250 (Div. 2)C. The Child and Toy(贪心)
- Codeforces-437C-The Child and Toy
- Codeforces Round #250 (Div. 2)C. The Child and Toy(贪心)
- H - The Child and Toy-CodeForces 437C-水题
- CF 250 C. The Child and Toy
- Codeforces Round #250 (Div. 1) A. The Child and Toy 水题
- [CF#250 Div.2 D]The Child and Zoo(并查集)
- Codeforces Round #250 (Div. 1) A. The Child and Toy
- CF(438D) The Child and Sequence(线段树)
- Codeforces Round #250 (Div. 2) -C. The Child and Toy
- CF438D(The Child and Sequence-线段树mod x)
- Codeforces #250 (Div. 2) C.The Child and Toy
- Codeforces Round #250 (Div. 2) C、The Child and Toy
- Codeforces Round #250 Div. 2(C.The Child and Toy)
- Codeforces Round #250 (Div. 2) C. The Child and Toy 详解
- The Child and Toy
- CF(438D) The Child and Sequence(线段树)
- CF437 B. The Child and Set(贪心)