标签:main pop 还需 sizeof div pair BMI col sele
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 24840 Accepted Submission(s): 9666
#include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; struct sta { int ar[3]; sta(){} sta(int a,int b,int c) { ar[0] = a; ar[1] = b; ar[2] = c; } }; typedef pair<sta,int> pa; int ar[3]; int order[6][3] = {0,1,2,0,2,1,1,0,2,1,2,0,2,0,1,2,1,0}; bool vis[1000001]; bool check(const sta &temp) { int d = temp.ar[0] * 10000 + temp.ar[1] * 100 + temp.ar[2]; bool e = vis[d]; vis[d] = true; return e; } sta change(const sta &temp,int a,int b,int c) { sta temp1; if(temp.ar[a] > ar[b] - temp.ar[b]) { temp1.ar[a] = temp.ar[a] - ar[b] + temp.ar[b]; temp1.ar[b] = ar[b]; } else { temp1.ar[a] = 0; temp1.ar[b] = temp.ar[b] + temp.ar[a]; } temp1.ar[c] = temp.ar[c]; return temp1; } int bfs() { if(ar[0] % 2) return 0; queue<pa> q; q.push(pa(sta(ar[0],0,0),0)); check(sta(ar[0],0,0)); while(!q.empty()) { sta temp = q.front().first,temp1; int times = q.front().second; q.pop(); for(int i = 0;i < 6;i ++) { temp1 = change(temp,order[i][0],order[i][1],order[i][2]); if(temp1.ar[0] == ar[0] / 2 || temp1.ar[1] == ar[0] / 2 || temp1.ar[2] == ar[0] / 2) return times + 1 + (temp1.ar[0] && temp1.ar[1] && temp1.ar[2]); if(!check(temp1)) q.push(pa(temp1,times + 1)); } } return 0; } int main() { while(scanf("%d%d%d",&ar[0],&ar[1],&ar[2]) && ar[0] && ar[1] && ar[2]) { memset(vis,false,sizeof(vis)); int ans = bfs(); if(ans)printf("%d\n",ans); else printf("NO\n"); } }
标签:main pop 还需 sizeof div pair BMI col sele
原文地址:https://www.cnblogs.com/8023spz/p/9733663.html