#include #include using namespace std; ifstream in("danger.in"); struct InvalidInfo { int teiler; int startpos; }; void MoveToNextValidPos(int &pos, int count, InvalidInfo* k, int icount) { if (count > 10) { while(true) { bool b= true; int killlevel=0; for (int i = 0; i < icount; i++) { if (((pos-k[i].startpos) % k[i].teiler) == 0) { b = false; killlevel = i; break; } } if (b) { return; } if (killlevel != 0) { pos +=2; //// cout << "n"; } else { pos += 1; } if (pos >= count) { // cout <<"error"<<"\n"; return; } } } else { while(true) { bool b= true; for (int i = 0; i < icount; i++) { if (((pos-k[i].startpos) % k[i].teiler) == 0) { b = false; break; } } if (b) { return; } pos++; if (pos >= count) { // cout <<"error"<<"\n"; return; } } } } int killthem(int count) { if (count == 1) return 1; if (count == 2) return 1; int start = 2; int pos = start; int inccount = 2; InvalidInfo k[400]; int icount = 0; for (int i = 0; i < count-1; i++) { // cout << pos << " "; if (pos + inccount*3 > count) { pos += inccount; } else { int n = (count-pos) / inccount-1; pos += inccount*n; i += n-1; } if (pos > count) { pos-=count; k[icount].startpos = start; k[icount].teiler = inccount; // cout << "Add(startpos: " << start << " teiler:" << inccount << "\n"; icount++; if (i == count-2) { // cout << "\nIm Letzten Statement" << "\n"; pos = 1; //if (pos == 0) pos = 1; } MoveToNextValidPos(pos, count, k, icount); inccount*= 2; start = pos; //cout << "newpos: " << pos << "\n"; } } return pos; } int main() { char c[200]; cout << "Ich hatte jetzt mehrmals Time-Limit Exceeded.\n"; cout << "Bitte gebt dem Programm etwas Zeit\n"; cout << "Es ist in keiner Endlosschleife\n"; while (in.eof() == 0) { in.getline(c, 199); if (strcmp(c, "00e0")==0) break; int n = ((c[0]-'0')*10+(c[1]-'0')*1); int p = (c[3]-'0'); for (int i = 0; i < p; i++) { n *= 10; } // cout << n << ": "; int res = killthem(n); //return 0; cout << res << "\n"; } return 0; }