#include<iostream> #include "message.h" #include "krazki.h" using namespace std; long long MY_INF = 2500000000000000000LL; int pocz, kon, mid; //long long? long long max_krazkow; int max_krazkow_index; int min_ind; long long x; int ind_x,ost_res,poz; bool zle; char odp; int main(){ //1. wyznacz max z wszystkich krazkow: long long max_krazkow = -1; if(MyNodeId() > 0){ //PutLL(0,max_krazkow); PutInt(0,1); Send(0); } else{ for(int i = 1; i < NumberOfNodes(); i++){ Receive(i); ind_x = GetInt(i); } } //2. wyzbacz najwyzszy taki, ze max sie nie zmiesci: /* long long min_index = MY_INF; for(int i = (MyNodeId() + 1); i <= PipeHeight(); i += NumberOfNodes()){ x = HoleDiameter(i); if(x < max_krazkow){ min_index = i; break; } } if(MyNodeId() > 0){ PutInt(0,min_index); Send(0); } else{ for(int i = 1; i < NumberOfNodes(); i++){ Receive(i); ind_x = GetInt(i); min_index = min(min_index, (long long)ind_x); } } if(MyNodeId() == 0){ kon = min((min_ind - 1), PipeHeight() - NumberOfDiscs() + 1); if(NumberOfDiscs() > PipeHeight()){ kon = 0; } if((min_ind - 1) < max_krazkow_index){ kon = 0; } pocz = 1; ost_res = 0; while(pocz <= kon){ mid = (pocz + kon) / 2; for(int i = 1; i < NumberOfNodes(); i++){ PutInt(i,mid); Send(i); } zle = 'N'; for(int i = 1; i < NumberOfNodes(); i++){ Receive(i); odp = GetChar(i); if(odp == 'T'){ zle = 'T'; } } if(zle == 'T'){ kon = (mid - 1); } else{ ost_res = mid; pocz = (mid + 1); } } cout << ost_res << endl; for(int i = 1; i < NumberOfNodes(); i++){ PutInt(i,(-1)); Send(i); } } else{ int ins = Receive(-1); poz = GetInt(ins); if(poz == (-1))return EXIT_SUCCESS; zle = 'N'; for(int i = MyNodeId(); i <= NumberOfDiscs(); i+= (NumberOfNodes() - 1)){ if(DiscDiameter(i) > HoleDiameter(i + poz)){ zle = 'T'; } } PutChar(0,zle); Send(0); }*/ return EXIT_SUCCESS; }
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 | #include<iostream> #include "message.h" #include "krazki.h" using namespace std; long long MY_INF = 2500000000000000000LL; int pocz, kon, mid; //long long? long long max_krazkow; int max_krazkow_index; int min_ind; long long x; int ind_x,ost_res,poz; bool zle; char odp; int main(){ //1. wyznacz max z wszystkich krazkow: long long max_krazkow = -1; if(MyNodeId() > 0){ //PutLL(0,max_krazkow); PutInt(0,1); Send(0); } else{ for(int i = 1; i < NumberOfNodes(); i++){ Receive(i); ind_x = GetInt(i); } } //2. wyzbacz najwyzszy taki, ze max sie nie zmiesci: /* long long min_index = MY_INF; for(int i = (MyNodeId() + 1); i <= PipeHeight(); i += NumberOfNodes()){ x = HoleDiameter(i); if(x < max_krazkow){ min_index = i; break; } } if(MyNodeId() > 0){ PutInt(0,min_index); Send(0); } else{ for(int i = 1; i < NumberOfNodes(); i++){ Receive(i); ind_x = GetInt(i); min_index = min(min_index, (long long)ind_x); } } if(MyNodeId() == 0){ kon = min((min_ind - 1), PipeHeight() - NumberOfDiscs() + 1); if(NumberOfDiscs() > PipeHeight()){ kon = 0; } if((min_ind - 1) < max_krazkow_index){ kon = 0; } pocz = 1; ost_res = 0; while(pocz <= kon){ mid = (pocz + kon) / 2; for(int i = 1; i < NumberOfNodes(); i++){ PutInt(i,mid); Send(i); } zle = 'N'; for(int i = 1; i < NumberOfNodes(); i++){ Receive(i); odp = GetChar(i); if(odp == 'T'){ zle = 'T'; } } if(zle == 'T'){ kon = (mid - 1); } else{ ost_res = mid; pocz = (mid + 1); } } cout << ost_res << endl; for(int i = 1; i < NumberOfNodes(); i++){ PutInt(i,(-1)); Send(i); } } else{ int ins = Receive(-1); poz = GetInt(ins); if(poz == (-1))return EXIT_SUCCESS; zle = 'N'; for(int i = MyNodeId(); i <= NumberOfDiscs(); i+= (NumberOfNodes() - 1)){ if(DiscDiameter(i) > HoleDiameter(i + poz)){ zle = 'T'; } } PutChar(0,zle); Send(0); }*/ return EXIT_SUCCESS; } |