1 #define _for(i,a,b) for(int i = (a);i < (b);i ++) 2 #define pb push_back 3 4 class Solution 5 { 6 public: 7 vector<int> prisonAfterNDays(vector<int>& cells, int N) 8 { 9 vector<vector<int>> pput; 10 vector<int> rnt = {0}; 11 vector<int> prev = cells; 12 while(1) 13 { 14 vector<int> tmp = prev; 15 tmp[0] = tmp[7] = 0; 16 _for(i,1,7) 17 { 18 if(prev[i-1]==prev[i+1]) 19 tmp[i] = 1; 20 else 21 tmp[i] = 0; 22 } 23 if(N==pput.size()+1) 24 return tmp; 25 prev = tmp; 26 if(!pput.empty()) 27 { 28 if(prev == pput[0]) 29 break; 30 } 31 pput.pb(prev); 32 } 33 N%=pput.size(); 34 if(N==0) 35 return pput[pput.size()-1]; 36 return pput[N-1]; 37 } 38 };
随便写写