标签:style blog http color io os ar for div
这个题目,分割,还没有找到更好的方法。但也过了:
/* ID: qq104801 LANG: C++ TASK: race3 */ #include <iostream> #include <fstream> #include <cstring> #include <vector> #include <queue> #include <stack> #include <algorithm> using namespace std; const int inf=1<<30; const int nmax=52; int a[nmax][nmax]; bool v[nmax]; int ans[nmax],ans1[nmax]; int u=-1,temp=0; void debug_dummpy() { return; } bool bfs(void){ int d[100]={0},head=1,tail=1; bool h[51]={1,0}; while(head<=tail){ int now=d[head++]; for(int i=1;i<=a[now][0];i++) { int& t=a[now][i]; if(!h[t]&&!v[t]) h[d[++tail]=t]=true; } } return !h[temp]; } bool bfs2(void){ int d[100]={0},tail=1,head=1; int level[100]={0}; level[0]=1;int k=0; while(head<=tail){ int now=d[head++]; if(v[now]){k=now;continue;} for(int i=1;i<=a[now][0];i++) { int& t=a[now][i]; if(!level[t]) level[d[++tail]=t]=1; } } level[k]=2; memset(d,0,sizeof d);head=1;tail=1;d[1]=k; while(head<=tail){ int now=d[head++]; for(int i=1;i<=a[now][0];i++) { int& t=a[now][i]; if(level[t]==1)return false; if(!level[t]) level[d[++tail]=t]=2; } } return true; } void test() { freopen("race3.in","r",stdin); freopen("race3.out","w",stdout); cin>>u; while(u!=-1) { while(u!=-2) { a[temp][++a[temp][0]]=u; cin>>u; } cin>>u; temp++; } temp--; for(int i=1;i<temp;i++) { v[i]=true; if(bfs())ans[++ans[0]]=i; if(bfs2())ans1[++ans1[0]]=i; v[i]=false; } for(int i=0;i<ans[0];i++)cout<<ans[i]<<" "; cout<<ans[ans[0]]<<endl; for(int i=0;i<ans1[0];i++)cout<<ans1[i]<<" "; cout<<ans1[ans1[0]]<<endl; } int main () { test(); return 0; }
test data:
USACO Training Grader Results 8 users online CHN/3 EGY/1 IND/1 IRN/1 NED/1 USA/1 USER: cn tom [qq104801] TASK: race3 LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.005 secs, 3384 KB] Test 2: TEST OK [0.003 secs, 3384 KB] Test 3: TEST OK [0.003 secs, 3384 KB] Test 4: TEST OK [0.003 secs, 3384 KB] Test 5: TEST OK [0.003 secs, 3384 KB] Test 6: TEST OK [0.003 secs, 3384 KB] Test 7: TEST OK [0.003 secs, 3384 KB] Test 8: TEST OK [0.003 secs, 3384 KB] Test 9: TEST OK [0.003 secs, 3384 KB] Test 10: TEST OK [0.003 secs, 3384 KB] Test 11: TEST OK [0.003 secs, 3384 KB] All tests OK. YOUR PROGRAM (‘race3‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations. Here are the test data inputs: ------- test 1 ---- 1 -2 -2 -1 ------- test 2 ---- 1 2 -2 3 -2 3 -2 5 4 -2 6 4 -2 6 -2 7 8 -2 9 -2 5 9 -2 -2 -1 ------- test 3 ---- 1 2 -2 3 -2 3 -2 4 5 -2 6 -2 6 -2 7 8 -2 9 -2 9 5 -2 -2 -1 ------- test 4 ---- 1 -2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 -2 3 -2 48 49 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 3 -2 -2 -1 ------- test 5 ---- 1 -2 2 -2 3 -2 4 -2 5 -2 6 -2 7 -2 8 -2 9 -2 10 -2 11 -2 12 -2 13 -2 14 -2 15 -2 16 -2 17 -2 18 -2 19 -2 20 -2 21 -2 22 -2 23 -2 24 -2 25 -2 26 -2 27 -2 28 -2 29 -2 30 -2 31 -2 32 -2 33 -2 34 -2 35 -2 36 -2 37 -2 38 -2 39 -2 40 -2 41 -2 42 -2 43 -2 44 -2 45 -2 46 -2 47 4 -2 48 -2 49 -2 -2 -1 ------- test 6 ---- 1 -2 2 1 -2 3 0 -2 3 4 -2 5 0 -2 7 6 -2 7 -2 8 -2 -2 -1 ------- test 7 ---- 1 -2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 -2 3 48 -2 49 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 -2 2 3 -2 -2 -1 ------- test 8 ---- 1 -2 2 -2 3 -2 4 -2 5 -2 6 -2 7 -2 8 -2 9 -2 10 -2 11 -2 12 -2 13 -2 14 -2 15 -2 16 -2 17 -2 18 -2 19 -2 20 -2 21 -2 22 -2 23 -2 24 -2 25 -2 26 -2 27 -2 28 -2 29 -2 30 -2 31 -2 32 -2 33 -2 34 -2 35 -2 36 -2 37 -2 38 -2 39 -2 40 -2 41 -2 42 -2 43 -2 44 -2 45 -2 46 -2 47 -2 48 -2 49 -2 -2 -1 ------- test 9 ---- 1 -2 2 1 -2 3 0 -2 3 4 -2 5 0 -2 5 7 6 -2 7 -2 8 -2 -2 -1 ------- test 10 ---- 1 2 -2 2 3 -2 3 4 -2 4 5 -2 5 6 -2 6 7 -2 7 8 -2 8 9 -2 9 10 -2 10 11 -2 11 12 -2 12 13 -2 13 14 -2 14 15 -2 15 16 -2 16 17 -2 17 18 -2 18 19 -2 19 20 -2 20 21 -2 21 22 -2 22 23 -2 23 24 -2 24 25 -2 25 26 -2 26 27 -2 27 28 -2 28 29 -2 29 30 -2 30 31 -2 31 32 -2 32 33 -2 33 34 -2 34 35 -2 35 36 -2 36 37 -2 37 38 -2 38 39 -2 39 40 -2 40 41 -2 41 42 -2 42 43 -2 43 44 -2 44 45 -2 45 46 -2 46 47 -2 47 48 -2 48 49 -2 49 -2 -2 -1 ------- test 11 ---- 1 -2 2 0 -2 3 1 -2 4 2 -2 5 3 -2 6 4 -2 7 5 -2 8 6 -2 9 7 -2 10 8 -2 11 9 -2 12 10 -2 13 11 -2 14 12 -2 15 13 -2 16 14 -2 17 15 -2 18 16 -2 19 17 -2 20 18 -2 21 19 -2 22 20 -2 23 21 -2 24 22 -2 25 23 -2 26 24 -2 27 25 -2 28 26 -2 29 27 -2 30 28 -2 31 29 -2 32 30 -2 33 31 -2 34 32 -2 35 33 -2 36 34 -2 37 35 -2 38 36 -2 39 37 -2 40 38 -2 41 39 -2 42 40 -2 43 41 -2 44 42 -2 45 43 -2 46 44 -2 47 45 -2 48 46 -2 49 47 -2 -2 -1 Keep up the good work! Thanks for your submission!
标签:style blog http color io os ar for div
原文地址:http://www.cnblogs.com/dpblue/p/3979667.html