#include "sonlib.h" #include <vector> #include <stack> #include <iostream> #include <algorithm> #define cerr if(false)cerr using namespace std; void eraseValue(vector<int>&Vec, int val){ for(int i=0;i<(int)Vec.size();i++) if(Vec[i]==val){ Vec.erase(Vec.begin()+i); return; } } void subtask1(){ int n = GetN(); vector<int>UnknownVertices,HalfA,HalfB; for(int i=2;i<=n;i++) UnknownVertices.push_back(i); HalfA.push_back(1); //FAZA I = podziel na A i B (1 jest w A) bool reversed=false; while(true){ int backAdr=-1; for(int uv : UnknownVertices) if(MoveProbe(uv)){ backAdr=uv; break; } if(backAdr==-1){ MoveProbe(1); if(!reversed){ reverse(UnknownVertices.begin(), UnknownVertices.end()); reversed=true; } else break; } else{ eraseValue(UnknownVertices, backAdr); HalfA.push_back(backAdr); } } HalfB = UnknownVertices; //FAZA II = odwiedź wszystkich for(int i=0;i<(int)HalfA.size();i++){ MoveProbe(HalfB[0]); MoveProbe(HalfA[i]); Examine(); } for(int i=0;i<(int)HalfB.size();i++){ MoveProbe(HalfB[i]); Examine(); MoveProbe(HalfA[0]); } } void subtask2(){ int n = GetN(); vector<int>PartiallyDiscovered({1,2,3}); vector<bool>NotDiscovered(n+1, true); vector<int>Parent(n+1); vector<bool>Parity(n+1); NotDiscovered[1]=NotDiscovered[2]=NotDiscovered[3]=false; Parity[1]=true; Parity[2]=Parity[3]=false; Parent[2]=1; Parent[3]=1; while(!PartiallyDiscovered.empty()){ //INIT STATE: you are in 1 in unsure mode int v = PartiallyDiscovered.back(); PartiallyDiscovered.pop_back(); cerr << "Next target: " << v << endl; //make a circle to align parity mode if(Parity[v]){ cerr << " ...making cicrcle" << endl; MoveProbe(2); MoveProbe(3); MoveProbe(1); } //go to target if(v!=1){ stack<int>Path; Path.push(v); while(Parent[Path.top()]!=1) Path.push(Parent[Path.top()]); while(!Path.empty()){ cerr << " ...moving to " << Path.top() << endl; MoveProbe(Path.top()); Path.pop(); } } cerr << "I am in place" << endl; //examine in that point Examine(); //scan for potential new vertices for(int nei=4;nei<=n;nei++) if(NotDiscovered[nei] && MoveProbe(nei)){ cerr << " ...found new vertex " << nei << endl; Parent[nei]=v; Parity[nei]=!Parity[v]; NotDiscovered[nei]=false; PartiallyDiscovered.push_back(nei); MoveProbe(v); } //return to 1 int vv=v; while(vv!=1){ cerr << " ...moving to " << Parent[vv] << endl; MoveProbe(Parent[vv]); vv=Parent[vv]; } //make a circle to align parity mode if(Parity[v]){ cerr << " ...making circle" << endl; MoveProbe(2); MoveProbe(3); MoveProbe(1); } } } int main(){ int s = GetSubtask(); if(s==1) subtask1(); else if(s==2) subtask2(); else MoveProbe(1); //zabij się return 0; } #undef cerr
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | #include "sonlib.h" #include <vector> #include <stack> #include <iostream> #include <algorithm> #define cerr if(false)cerr using namespace std; void eraseValue(vector<int>&Vec, int val){ for(int i=0;i<(int)Vec.size();i++) if(Vec[i]==val){ Vec.erase(Vec.begin()+i); return; } } void subtask1(){ int n = GetN(); vector<int>UnknownVertices,HalfA,HalfB; for(int i=2;i<=n;i++) UnknownVertices.push_back(i); HalfA.push_back(1); //FAZA I = podziel na A i B (1 jest w A) bool reversed=false; while(true){ int backAdr=-1; for(int uv : UnknownVertices) if(MoveProbe(uv)){ backAdr=uv; break; } if(backAdr==-1){ MoveProbe(1); if(!reversed){ reverse(UnknownVertices.begin(), UnknownVertices.end()); reversed=true; } else break; } else{ eraseValue(UnknownVertices, backAdr); HalfA.push_back(backAdr); } } HalfB = UnknownVertices; //FAZA II = odwiedź wszystkich for(int i=0;i<(int)HalfA.size();i++){ MoveProbe(HalfB[0]); MoveProbe(HalfA[i]); Examine(); } for(int i=0;i<(int)HalfB.size();i++){ MoveProbe(HalfB[i]); Examine(); MoveProbe(HalfA[0]); } } void subtask2(){ int n = GetN(); vector<int>PartiallyDiscovered({1,2,3}); vector<bool>NotDiscovered(n+1, true); vector<int>Parent(n+1); vector<bool>Parity(n+1); NotDiscovered[1]=NotDiscovered[2]=NotDiscovered[3]=false; Parity[1]=true; Parity[2]=Parity[3]=false; Parent[2]=1; Parent[3]=1; while(!PartiallyDiscovered.empty()){ //INIT STATE: you are in 1 in unsure mode int v = PartiallyDiscovered.back(); PartiallyDiscovered.pop_back(); cerr << "Next target: " << v << endl; //make a circle to align parity mode if(Parity[v]){ cerr << " ...making cicrcle" << endl; MoveProbe(2); MoveProbe(3); MoveProbe(1); } //go to target if(v!=1){ stack<int>Path; Path.push(v); while(Parent[Path.top()]!=1) Path.push(Parent[Path.top()]); while(!Path.empty()){ cerr << " ...moving to " << Path.top() << endl; MoveProbe(Path.top()); Path.pop(); } } cerr << "I am in place" << endl; //examine in that point Examine(); //scan for potential new vertices for(int nei=4;nei<=n;nei++) if(NotDiscovered[nei] && MoveProbe(nei)){ cerr << " ...found new vertex " << nei << endl; Parent[nei]=v; Parity[nei]=!Parity[v]; NotDiscovered[nei]=false; PartiallyDiscovered.push_back(nei); MoveProbe(v); } //return to 1 int vv=v; while(vv!=1){ cerr << " ...moving to " << Parent[vv] << endl; MoveProbe(Parent[vv]); vv=Parent[vv]; } //make a circle to align parity mode if(Parity[v]){ cerr << " ...making circle" << endl; MoveProbe(2); MoveProbe(3); MoveProbe(1); } } } int main(){ int s = GetSubtask(); if(s==1) subtask1(); else if(s==2) subtask2(); else MoveProbe(1); //zabij się return 0; } #undef cerr |