标签:
Time Limit: 20 Sec
Memory Limit: 256 MB
http://hihocoder.com/problemset/problem/1179
Input
Output
如果Rowdark能玩超过100000轮,输出“INF”(不带引号),否则输出最多步数。
Sample Input
3 3
1 2 1
0 1
1 2
2 0
Sample Output
INF
题意
题解:
每次我们都暴力选择剩下权值最多的点就好了,如果所有点的权值都小于这个点的度数的话,那么我们就输出-1
代码:
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 100001 #define mod 10007 #define eps 1e-9 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } //************************************************************************************** vector<int> g[210]; long long a[210]; int deg[210]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); } for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); g[u].push_back(v); g[v].push_back(u); deg[u]++; deg[v]++; } for (int i = 0; i <= 100000; i++) { int id = -1; for (int i = 0; i < n; i++) { if (a[i] >= deg[i]) { if (id == -1 || (a[i] - deg[i]) > (a[id] - deg[id])) { id = i; } } } if (id == -1) { printf("%d\n", i); return 0; } else { for (int i = 0; i < g[id].size(); i++) { a[id]--; int v = g[id][i]; a[v]++; } } } puts("INF"); return 0; }
标签:
原文地址:http://www.cnblogs.com/qscqesze/p/4576956.html