The Child and Toy
2014-08-01 16:23
155 查看
Codeforces Round #250 (Div. 2) C:http://codeforces.com/problemset/problem/437/C
题意:给以一个无向图,每个点都有一点的权值,然后如果要删除一个点的话,会有一定的费用,这个费用是与这个点的相邻的,并且是没有删除的点权值之和。
题解:很简单的,肯定是贪心,因为为了避免权值最大的点对其他点造成影响,所以首先删除的应该是权值最大值。
View Code
题意:给以一个无向图,每个点都有一点的权值,然后如果要删除一个点的话,会有一定的费用,这个费用是与这个点的相邻的,并且是没有删除的点权值之和。
题解:很简单的,肯定是贪心,因为为了避免权值最大的点对其他点造成影响,所以首先删除的应该是权值最大值。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=1002; int n,m,ans; bool mp ; int a ,t1,t2; struct Node{ int val; int id; bool operator<(const Node a)const{ return val>a.val; } }num ; int main(){ scanf("%d%d",&n,&m); memset(mp,0,sizeof(mp)); ans=0; for(int i=1;i<=n;i++){ scanf("%d",&num[i].val); num[i].id=i; a[i]=num[i].val; } for(int i=1;i<=m;i++){ scanf("%d%d",&t1,&t2); mp[t1][t2]=mp[t2][t1]=1; } sort(num+1,num+n+1); for(int i=1;i<=n;i++){ int temp=num[i].id; for(int i=1;i<=n;i++){ if(mp[temp][i]){ ans+=a[i]; mp[temp][i]=mp[i][temp]=0; } } } printf("%d\n",ans); }
View Code
相关文章推荐
- CF(437C)The Child and Toy(馋)
- codeforces-437C-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
- CF(437C)The Child and Toy(贪心)
- Codeforces #250 (Div. 2) C.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(贪心)
- Codeforces Round #250 (Div. 2)C. The Child and Toy(贪心)
- H - The Child and Toy-CodeForces 437C-水题
- Codeforces Round #250 (Div. 2) C. The Child and Toy 详解
- Codeforces Round #250 (Div. 1) A. The Child and Toy 水题
- Codeforces Round #250 (Div. 1) A. The Child and Toy
- Codeforces #250 (Div. 2) C.The Child and Toy
- CF 250 C. The Child and Toy
- 438D - The Child and Sequence
- 250 B. The Child and Set
- CF #250 The Child and Homework