#include <stdio.h> #include "krazki.h" #include "message.h" #include <vector> std::vector<long long int> pipeDef; long long int min(long long int a, long long int b){ return a < b ? a : b;} int main(){ if (MyNodeId() != 0) { return 0; } int discs = NumberOfDiscs(); int pipe = PipeHeight(); if (discs > pipe) {printf("0\n"); return 0;} pipeDef.push_back(HoleDiameter(1)); for(int p = 2; p <= pipe; p++) pipeDef.push_back(min(HoleDiameter(p),pipeDef.back())); int lastPos = (int)pipeDef.size(); long long int disc; for(int d = 1; d <= discs && lastPos >= 0; d++){ lastPos--;//miejsce wstawienia obecnego dysku disc = DiscDiameter(d); while(lastPos >= 0 && disc > pipeDef[lastPos]) lastPos--; //if (lastPos > 0) lastPos--; } printf("%d\n",lastPos+1); 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 | #include <stdio.h> #include "krazki.h" #include "message.h" #include <vector> std::vector<long long int> pipeDef; long long int min(long long int a, long long int b){ return a < b ? a : b;} int main(){ if (MyNodeId() != 0) { return 0; } int discs = NumberOfDiscs(); int pipe = PipeHeight(); if (discs > pipe) {printf("0\n"); return 0;} pipeDef.push_back(HoleDiameter(1)); for(int p = 2; p <= pipe; p++) pipeDef.push_back(min(HoleDiameter(p),pipeDef.back())); int lastPos = (int)pipeDef.size(); long long int disc; for(int d = 1; d <= discs && lastPos >= 0; d++){ lastPos--;//miejsce wstawienia obecnego dysku disc = DiscDiameter(d); while(lastPos >= 0 && disc > pipeDef[lastPos]) lastPos--; //if (lastPos > 0) lastPos--; } printf("%d\n",lastPos+1); return 0; } |