#include <bits/stdc++.h> using namespace std; int ile = 1; int m = 4; int n; int maxx; int zaraz; int zaszcz; pair<int, int> pik; string s = "0000"; vector <int> v; vector <bool> vv; bool t; int main() { //cout<<"hej"; //cin >> ile; for(int i = 0; i < ile; i++){ //cin >> m; //cout<<"hej"; v.resize(m + 1); vv.resize(m + 1); //cin >> s; for(int j = 0; j < m; j++){ v[j] = static_cast <int> (s[j] - 48); if(s[j] == '1') zaraz++; } t = 1; while(zaraz + zaszcz < m){ if( t || vv[pik.second - 1]){ t = 0; for(int j = 0; j < m - 1; j++){ if(v[j] == 0 && v[j+1] == 0) n++; else n=1; if(maxx<n){ maxx=n; pik.first = j - maxx + 2; pik.second = j + 1; } } } cout<<pik.first << " p " << pik.second << " k "<<endl; if(!vv[pik.first]) vv[pik.first] = 1; else vv[pik.second - 1] = 1; zaszcz++; t = 0; for(int j=0; j < m; j++){ if(v[j] == 0 && (v[j - 1] == 1 || v[j + 1] == 1) && !vv[j]){ v[j] = 1; zaraz++; t = 1; } } if(!t)break; t = 0; } cout<<zaraz; } return 0; }
1 2 3 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include <bits/stdc++.h> using namespace std; int ile = 1; int m = 4; int n; int maxx; int zaraz; int zaszcz; pair<int, int> pik; string s = "0000"; vector <int> v; vector <bool> vv; bool t; int main() { //cout<<"hej"; //cin >> ile; for(int i = 0; i < ile; i++){ //cin >> m; //cout<<"hej"; v.resize(m + 1); vv.resize(m + 1); //cin >> s; for(int j = 0; j < m; j++){ v[j] = static_cast <int> (s[j] - 48); if(s[j] == '1') zaraz++; } t = 1; while(zaraz + zaszcz < m){ if( t || vv[pik.second - 1]){ t = 0; for(int j = 0; j < m - 1; j++){ if(v[j] == 0 && v[j+1] == 0) n++; else n=1; if(maxx<n){ maxx=n; pik.first = j - maxx + 2; pik.second = j + 1; } } } cout<<pik.first << " p " << pik.second << " k "<<endl; if(!vv[pik.first]) vv[pik.first] = 1; else vv[pik.second - 1] = 1; zaszcz++; t = 0; for(int j=0; j < m; j++){ if(v[j] == 0 && (v[j - 1] == 1 || v[j + 1] == 1) && !vv[j]){ v[j] = 1; zaraz++; t = 1; } } if(!t)break; t = 0; } cout<<zaraz; } return 0; } |