Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
终于过了,一个破最大流的题搞了这么久,先是死循环TLE,然后数组越界RE,最后输出全大写WA!晕了!#include <iostream> #include <stdio.h> #include <queue> using namespace std; const int gs = 100; const int weeks = 500; const int S = 2147483647, T = -10000000; int graph[gs][weeks] = {0}; int main() { int cases; scanf("%d", &cases); for(int ii = 0; ii < cases; ii++){ int N; scanf("%d", &N); int canDays[gs][7]; int D[gs], W[gs]; int maxW = 0; for(int i = 0; i < N; i++){ for(int k = 0; k < 7; k++) scanf("%d", &canDays[i][k]); scanf("%d%d", &D[i], &W[i]); if(maxW < W[i]) maxW = W[i]; } int M = 7 * maxW; for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) graph[i][j] = 0; bool avl[weeks]; for(int i = 0; i < M; i++) avl[i] = 1; for(int i = 0; i < N; i++){ for(int k = 0; k < 7; k++){ if(canDays[i][k] == 0) continue; for(int j = 0; j < W[i]; j++){ graph[i][7*j+k] = 1; } } } //int flow = 0; while(1){ //cout << 1 << endl; queue<int> bfs; bool sVisited[gs] = {0}, tVisited[weeks] = {0}; int sPrev[gs], tPrev[weeks]; for(int i = 0; i < N; i++){ if(D[i] > 0){ bfs.push(i); sVisited[i] = 1; sPrev[i] = S; } } int zhyg = T; while(!bfs.empty()){ int no = bfs.front(); bfs.pop(); if(no < gs){ for(int i = 0; i < M; i++){ if(graph[no][i] == 1 && !tVisited[i]){ tVisited[i] = 1; tPrev[i] = no; if(avl[i]){ zhyg = i; goto findOne; } bfs.push(i+gs); } } } else{ for(int i = 0; i < N; i++){ if(graph[i][no-gs] == -1 && !sVisited[i]){ sVisited[i] = 1; sPrev[i] = no; bfs.push(i); } } } } findOne: if(zhyg == T){ break; } //flow ++; avl[zhyg] = 0; int cur = tPrev[zhyg]; int suc = zhyg + gs; //int cnt = 0; while(cur < S/2){ //cout << 1 << endl; if(cur < gs){ graph[cur][suc - gs] = -1; suc = cur; cur = sPrev[cur]; } else{ graph[suc][cur - gs] = 1; suc = cur; cur = tPrev[cur - gs]; } } D[suc] --; } bool manle = 1; for(int i = 0; i < N; i++){ if(D[i] > 0){ manle = 0; break; } } if(manle) printf("Yes\n"); else printf("No\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator