#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <list> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include "cielib.h" //int d_v, k_v, r_v; // //void init(void); // //int podajD(void) { // init(); // // return d_v; //} // //int podajK(void) { // init(); // // return k_v; //} // //int podajR(void) { // init(); // // return r_v; //} // //int pos[500]; // //void init(void) { // static int initialized = -1; // if (initialized != -1) { // return; // } // initialized = 1; // // printf("Podaj d: "); // scanf("%d", &d_v); // printf("Podaj k: "); // scanf("%d", &k_v); // printf("Podaj r: "); // scanf("%d", &r_v); // // printf("Podaj pozycje Krotki:\n"); // for (int i = 0; i < podajD(); ++i) { // scanf("%d", &pos[i]); // } //} // //int call = 0; // //int czyCieplo(int answer[]) { // init(); // // call += 1; // if (call > podajK()) { // printf("Przekroczono limit k = %d.", k_v); // exit(1); // } // // static int ldiff = -1; // int diff = 0; // // for (int d, i = 0; i < podajD(); ++i) { // d = pos[i] - answer[i]; // d = (d<0) ? -d : d; // // diff = (d > diff) ? d : diff; // } // // const int result = (diff < ldiff) ? 1 : 0; // ldiff = diff; // // return result; //} // //void znalazlem(int answer[]) { // init(); // // printf("Podano:\n"); // for (int i = 0; i < podajD(); ++i) { // printf("%d%c", pos[i], (i + 1 == podajD()) ? '\n' : ' '); // } // // int k = 1; // for (int i = 0; i < podajD(); ++i) { // if (answer[i] != pos[i]) { // printf("NIE %d na %d!\n", answer[i], i); // k = -1; // } // } // // if (k == 1) { // printf("OK --- %d zapytan\n", call); // } // // exit(0); //} using namespace std; #define FOR(i,n) for(int i=0;i<n;++i) #define FORB(i,b,n) for(int i=b;i<n;++i) #define REV(i,n) for(int i=n;i>=0;--i) #define FOREACH(T, it, v) for(T::iterator it = v.begin(); it !=v.end(); ++it) typedef unsigned int u32; typedef unsigned int uint; const int INF = (0u - 11) / 2; typedef long long ll; typedef set<int> SI; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef set<long long> SL; typedef map<int, int> MII; int DEBUG = 1; #define print(STRING,INT) printf("%s= %d\n", STRING, INT) #define scan(INT) scanf("%d", &INT) void log(char* S, int a) { if (DEBUG) { print(S, a); } } const int MAX_SHORT = 65536; const int MEMORY_SECTOR_SIZE = 1000012; int Win[MEMORY_SECTOR_SIZE]; int Draw[MEMORY_SECTOR_SIZE]; void zadanieKAR() { int N, M; int a, b; char c; bool win = false; scan(N); scan(M); FOR(i, N + 1) { Win[i] = 0; Draw[i] = 0; } FOR(i, M) { scanf("%d %c %d", &a, &c, &b); if (c == '>') { Win[b]++; if (Win[b] == N) { win = true; } } else { Draw[b]++; } } if (win) { printf("WYGRANA\n"); return; } FORB(i, 1, N + 1) { if (Draw[i] == 0) { printf("REMIS\n"); return; } } printf("PRZEGRANA\n"); } void zadanie2B() { int n; int tab[132]; int len = 0; scan(n); if (n == 1) { printf("1\n"); return; } while (n > 0) { tab[len++] = n & 1; n >>= 1; } string S; string for1 = "*(1+(1+1)"; string for0 = "*(1+1)"; if (tab[0] == 1) { S = "1+(1+1)"; } else { S = "(1+1)"; } int bracketToClose = 0; FORB(i, 1, len - 1) { if (tab[i] == 1) { S += for1; bracketToClose++; } else { S += for0; } } FOR(i, bracketToClose) { S += ")"; } printf("%s\n", S.c_str()); } int main1A() { //int nodes = NumberOfNodes(); int n; scan(n); FOR(i, n) { zadanieKAR(); } //printf("%d\n", out); return 0; } int main1B() { int n; int t; scan(n); n = 1 << n; scan(t); vector<int> V(n, 0); FOR(i, n) { scan(V[i]); } if (t & 0x1) { std::reverse(V.begin(), V.end()); } FOR(i, n) { printf("%d ", V[i]); } printf("\n"); return 0; } int main2B() { int n; scan(n); FOR(i, n) { zadanie2B(); } return 0; } int main2A_V1() { int n; int m; scan(n); scan(m); int a, b; char c; const int MAX_N = 5; //1002; VI followers(MAX_N, 0); VVI like(MAX_N, VI(MAX_N, 0)); VVI likeLists(MAX_N, VI()); VVI dislike(MAX_N, VI(MAX_N, 0)); VVI dislikeLists(MAX_N, VI()); FOR(i, m) { scanf("%d %d %c", &a, &b, &c); a--; b--; if (c == 'T') { like[a][b] = 1; likeLists[a].push_back(b); followers[b]++; } else { dislike[a][b] = 1; dislikeLists[a].push_back(b); } } //spread hate VI Q; int iter = 0; FOR(i, n) { if (followers[i] == 0) { Q.push_back(i); } } int source; int target; while (iter < Q.size()) { source = Q[iter]; FOREACH(VI, it, likeLists[Q[iter]]) { target = *it; FOREACH(VI, it, dislikeLists[Q[iter]]) { if (dislike[target][*it] == 0) { dislike[target][*it] = 1; dislikeLists[target].push_back(*it); } } followers[target]--; if (followers[target] == 0) { Q.push_back(target); } } iter++; } if (iter != n) { printf("NIE\n"); //pokazuja na siebie } FOR(i, n) { FOR(j, n) { if (dislike[i][j] == 1 && like[i][j] == 1) { printf("NIE\n"); } } } //printf("\n"); return 0; } int main2A() { int n; int m; scan(n); scan(m); int a, b; char c; //const int MAX_N = 5; //1002; const int MAX_N = 1002; VI boss(MAX_N, -2); VI used(MAX_N, 0); VI followers(MAX_N, 0); VI hejters(MAX_N, 0); VVI like(MAX_N, VI(MAX_N, 0)); VVI likeLists(MAX_N, VI()); VVI followedByLists(MAX_N, VI()); VVI dislike(MAX_N, VI(MAX_N, 0)); VVI dislikeLists(MAX_N, VI()); FOR(i, m) { scanf("%d %d %c", &a, &b, &c); a--; b--; if (c == 'T') { like[a][b] = 1; likeLists[a].push_back(b); followers[b]++; dislike[b][a] = 1; dislikeLists[b].push_back(a); followedByLists[b].push_back(a); hejters[a]++; // printf("Like\n"); } else { dislike[a][b] = 1; dislikeLists[a].push_back(b); hejters[b]++; // printf("Hate\n"); } } int currentBoss = -1; // printf("Find boss\n"); int assigned = 0; FOR(i, n) { if (hejters[i] == 0) { boss[i] = currentBoss; assigned++; used[i] = 1; currentBoss = i; // printf("Dodal Bossa %d pod %d\n", i, boss[i]); FOR(j, n) { if (dislike[currentBoss][j] == 1) { dislike[currentBoss][j] = 0; hejters[j]--; } } } } // printf("assigned bossow %d\n", assigned); if (assigned == 0) { printf("NIE\n"); return 0; } FOR(i, n) { if (used[i] == 0) { boss[i] = currentBoss; } } int i = 0; while (i < n) { if (used[i] == 0) { // printf("pool dla %d\n", i); currentBoss = boss[i]; VI pool(MAX_N, 0); VI poolList(1, i); pool[i] = 1; int iter = 0; while (iter < poolList.size()) { int source = poolList[iter]; //add followed FOREACH(VI, it, likeLists[source]) { int target = *it; if (used[target] == 0 && boss[target] == boss[i] && pool[target] == 0) { poolList.push_back(target); pool[target] = 1; } } //add who follow FOREACH(VI, it, followedByLists[source]) { int target = *it; if (used[target] == 0 && boss[target] == boss[i] && pool[target] == 0) { poolList.push_back(target); pool[target] = 1; } } iter++; } int poolSize = poolList.size(); //recalculate Haters rate FOR(j, poolSize) { hejters[poolList[j]] = 0; } FOR(j, poolSize) { int iter = 0; int source = poolList[j]; int size = dislikeLists[source].size(); while (iter < size) { //nie z puli, nie ma znaczenia if (pool[dislikeLists[source][iter]] == 0) { swap(dislikeLists[source][iter], dislikeLists[source][size - 1]); dislikeLists[source].pop_back(); size--; } else { hejters[dislikeLists[source][iter]]++; iter++; } } } VI Queue; iter = 0; FOR(j, poolSize) { if (hejters[poolList[j]] == 0) { Queue.push_back(poolList[j]); } } if (Queue.size() == 0) { printf("NIE\n"); return 0; } while (iter < Queue.size()) { int current = Queue[iter]; boss[current] = currentBoss; assigned++; //printf("assign %d\n", current); used[current] = 1; currentBoss = current; //FOREACH(VI, it, dislike[current]) //{ // //nie z puli, nie ma znaczenia // if (pool[dislike[j][iter]] == 0) // { // swap(dislike[j][iter], dislike[j][size - 1]); // dislike[j].pop_back(); // size--; // } // else // { // hejters[dislike[j][iter]]++; // iter++; // } //} iter++; } FOR(j, poolSize) { if (used[poolList[j]] == 0) { boss[poolList[j]] = currentBoss; } } } if (used[i] == 1) { i++; } else { // printf("tried %d\n", i); } } // printf("WHY, WTF %d %d\n", assigned, n); if (assigned != n) { // printf("WHY, WTF %d %d\n", assigned, n); // return 0; } FOR(i, n) { printf("%d\n", boss[i] + 1); } //FOR(i, n) //{ // if (used[i] == 0) // printf("nie uzyty %d\n", i); //} // printf("TAK\n"); return 0; } int main3B() { int R = podajR(); int D = podajD(); VI min(D, 0); VI max(D, R); VI found(D, 0); int toBeFound = D; int current[1000]; set<int> kolejka; FOR(i, D) { current[i] = R / 2; kolejka.insert((max[i] - min[i]) * 1000 + i); } while (!kolejka.empty()) { set<int>::reverse_iterator iter = kolejka.rbegin(); int i = (*iter) % 1000; kolejka.erase(*iter); current[i] = min[i]; czyCieplo(current); current[i] = max[i]; bool a = czyCieplo(current); current[i] = min[i]; bool b = czyCieplo(current); int range = max[i] - min[i]; int srodek = (max[i] + min[i]) / 2; if (a) { min[i] = srodek + 1; } else if (b) { max[i] = srodek; if ((range & 1) == 0) { max[i]--; } } else { if ((range & 1) == 0) { current[i] = srodek; toBeFound--; found[i] = 1; continue; } min[i] = srodek; max[i] = srodek + 2; } range = max[i] - min[i]; if (range == 0) { current[i] = min[i]; toBeFound--; found[i] = 1; continue; } if (range == 1) { if (max[i] < R) max[i]++; else min[i]--; } current[i] = (max[i] + min[i]) / 2; kolejka.insert((max[i] - min[i]) * 1000 + i); } znalazlem(current); return 0; } int main() { main3B(); 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 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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 | #include <vector> #include <list> #include <map> #include <set> #include <queue> #include <list> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include "cielib.h" //int d_v, k_v, r_v; // //void init(void); // //int podajD(void) { // init(); // // return d_v; //} // //int podajK(void) { // init(); // // return k_v; //} // //int podajR(void) { // init(); // // return r_v; //} // //int pos[500]; // //void init(void) { // static int initialized = -1; // if (initialized != -1) { // return; // } // initialized = 1; // // printf("Podaj d: "); // scanf("%d", &d_v); // printf("Podaj k: "); // scanf("%d", &k_v); // printf("Podaj r: "); // scanf("%d", &r_v); // // printf("Podaj pozycje Krotki:\n"); // for (int i = 0; i < podajD(); ++i) { // scanf("%d", &pos[i]); // } //} // //int call = 0; // //int czyCieplo(int answer[]) { // init(); // // call += 1; // if (call > podajK()) { // printf("Przekroczono limit k = %d.", k_v); // exit(1); // } // // static int ldiff = -1; // int diff = 0; // // for (int d, i = 0; i < podajD(); ++i) { // d = pos[i] - answer[i]; // d = (d<0) ? -d : d; // // diff = (d > diff) ? d : diff; // } // // const int result = (diff < ldiff) ? 1 : 0; // ldiff = diff; // // return result; //} // //void znalazlem(int answer[]) { // init(); // // printf("Podano:\n"); // for (int i = 0; i < podajD(); ++i) { // printf("%d%c", pos[i], (i + 1 == podajD()) ? '\n' : ' '); // } // // int k = 1; // for (int i = 0; i < podajD(); ++i) { // if (answer[i] != pos[i]) { // printf("NIE %d na %d!\n", answer[i], i); // k = -1; // } // } // // if (k == 1) { // printf("OK --- %d zapytan\n", call); // } // // exit(0); //} using namespace std; #define FOR(i,n) for(int i=0;i<n;++i) #define FORB(i,b,n) for(int i=b;i<n;++i) #define REV(i,n) for(int i=n;i>=0;--i) #define FOREACH(T, it, v) for(T::iterator it = v.begin(); it !=v.end(); ++it) typedef unsigned int u32; typedef unsigned int uint; const int INF = (0u - 11) / 2; typedef long long ll; typedef set<int> SI; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef set<long long> SL; typedef map<int, int> MII; int DEBUG = 1; #define print(STRING,INT) printf("%s= %d\n", STRING, INT) #define scan(INT) scanf("%d", &INT) void log(char* S, int a) { if (DEBUG) { print(S, a); } } const int MAX_SHORT = 65536; const int MEMORY_SECTOR_SIZE = 1000012; int Win[MEMORY_SECTOR_SIZE]; int Draw[MEMORY_SECTOR_SIZE]; void zadanieKAR() { int N, M; int a, b; char c; bool win = false; scan(N); scan(M); FOR(i, N + 1) { Win[i] = 0; Draw[i] = 0; } FOR(i, M) { scanf("%d %c %d", &a, &c, &b); if (c == '>') { Win[b]++; if (Win[b] == N) { win = true; } } else { Draw[b]++; } } if (win) { printf("WYGRANA\n"); return; } FORB(i, 1, N + 1) { if (Draw[i] == 0) { printf("REMIS\n"); return; } } printf("PRZEGRANA\n"); } void zadanie2B() { int n; int tab[132]; int len = 0; scan(n); if (n == 1) { printf("1\n"); return; } while (n > 0) { tab[len++] = n & 1; n >>= 1; } string S; string for1 = "*(1+(1+1)"; string for0 = "*(1+1)"; if (tab[0] == 1) { S = "1+(1+1)"; } else { S = "(1+1)"; } int bracketToClose = 0; FORB(i, 1, len - 1) { if (tab[i] == 1) { S += for1; bracketToClose++; } else { S += for0; } } FOR(i, bracketToClose) { S += ")"; } printf("%s\n", S.c_str()); } int main1A() { //int nodes = NumberOfNodes(); int n; scan(n); FOR(i, n) { zadanieKAR(); } //printf("%d\n", out); return 0; } int main1B() { int n; int t; scan(n); n = 1 << n; scan(t); vector<int> V(n, 0); FOR(i, n) { scan(V[i]); } if (t & 0x1) { std::reverse(V.begin(), V.end()); } FOR(i, n) { printf("%d ", V[i]); } printf("\n"); return 0; } int main2B() { int n; scan(n); FOR(i, n) { zadanie2B(); } return 0; } int main2A_V1() { int n; int m; scan(n); scan(m); int a, b; char c; const int MAX_N = 5; //1002; VI followers(MAX_N, 0); VVI like(MAX_N, VI(MAX_N, 0)); VVI likeLists(MAX_N, VI()); VVI dislike(MAX_N, VI(MAX_N, 0)); VVI dislikeLists(MAX_N, VI()); FOR(i, m) { scanf("%d %d %c", &a, &b, &c); a--; b--; if (c == 'T') { like[a][b] = 1; likeLists[a].push_back(b); followers[b]++; } else { dislike[a][b] = 1; dislikeLists[a].push_back(b); } } //spread hate VI Q; int iter = 0; FOR(i, n) { if (followers[i] == 0) { Q.push_back(i); } } int source; int target; while (iter < Q.size()) { source = Q[iter]; FOREACH(VI, it, likeLists[Q[iter]]) { target = *it; FOREACH(VI, it, dislikeLists[Q[iter]]) { if (dislike[target][*it] == 0) { dislike[target][*it] = 1; dislikeLists[target].push_back(*it); } } followers[target]--; if (followers[target] == 0) { Q.push_back(target); } } iter++; } if (iter != n) { printf("NIE\n"); //pokazuja na siebie } FOR(i, n) { FOR(j, n) { if (dislike[i][j] == 1 && like[i][j] == 1) { printf("NIE\n"); } } } //printf("\n"); return 0; } int main2A() { int n; int m; scan(n); scan(m); int a, b; char c; //const int MAX_N = 5; //1002; const int MAX_N = 1002; VI boss(MAX_N, -2); VI used(MAX_N, 0); VI followers(MAX_N, 0); VI hejters(MAX_N, 0); VVI like(MAX_N, VI(MAX_N, 0)); VVI likeLists(MAX_N, VI()); VVI followedByLists(MAX_N, VI()); VVI dislike(MAX_N, VI(MAX_N, 0)); VVI dislikeLists(MAX_N, VI()); FOR(i, m) { scanf("%d %d %c", &a, &b, &c); a--; b--; if (c == 'T') { like[a][b] = 1; likeLists[a].push_back(b); followers[b]++; dislike[b][a] = 1; dislikeLists[b].push_back(a); followedByLists[b].push_back(a); hejters[a]++; // printf("Like\n"); } else { dislike[a][b] = 1; dislikeLists[a].push_back(b); hejters[b]++; // printf("Hate\n"); } } int currentBoss = -1; // printf("Find boss\n"); int assigned = 0; FOR(i, n) { if (hejters[i] == 0) { boss[i] = currentBoss; assigned++; used[i] = 1; currentBoss = i; // printf("Dodal Bossa %d pod %d\n", i, boss[i]); FOR(j, n) { if (dislike[currentBoss][j] == 1) { dislike[currentBoss][j] = 0; hejters[j]--; } } } } // printf("assigned bossow %d\n", assigned); if (assigned == 0) { printf("NIE\n"); return 0; } FOR(i, n) { if (used[i] == 0) { boss[i] = currentBoss; } } int i = 0; while (i < n) { if (used[i] == 0) { // printf("pool dla %d\n", i); currentBoss = boss[i]; VI pool(MAX_N, 0); VI poolList(1, i); pool[i] = 1; int iter = 0; while (iter < poolList.size()) { int source = poolList[iter]; //add followed FOREACH(VI, it, likeLists[source]) { int target = *it; if (used[target] == 0 && boss[target] == boss[i] && pool[target] == 0) { poolList.push_back(target); pool[target] = 1; } } //add who follow FOREACH(VI, it, followedByLists[source]) { int target = *it; if (used[target] == 0 && boss[target] == boss[i] && pool[target] == 0) { poolList.push_back(target); pool[target] = 1; } } iter++; } int poolSize = poolList.size(); //recalculate Haters rate FOR(j, poolSize) { hejters[poolList[j]] = 0; } FOR(j, poolSize) { int iter = 0; int source = poolList[j]; int size = dislikeLists[source].size(); while (iter < size) { //nie z puli, nie ma znaczenia if (pool[dislikeLists[source][iter]] == 0) { swap(dislikeLists[source][iter], dislikeLists[source][size - 1]); dislikeLists[source].pop_back(); size--; } else { hejters[dislikeLists[source][iter]]++; iter++; } } } VI Queue; iter = 0; FOR(j, poolSize) { if (hejters[poolList[j]] == 0) { Queue.push_back(poolList[j]); } } if (Queue.size() == 0) { printf("NIE\n"); return 0; } while (iter < Queue.size()) { int current = Queue[iter]; boss[current] = currentBoss; assigned++; //printf("assign %d\n", current); used[current] = 1; currentBoss = current; //FOREACH(VI, it, dislike[current]) //{ // //nie z puli, nie ma znaczenia // if (pool[dislike[j][iter]] == 0) // { // swap(dislike[j][iter], dislike[j][size - 1]); // dislike[j].pop_back(); // size--; // } // else // { // hejters[dislike[j][iter]]++; // iter++; // } //} iter++; } FOR(j, poolSize) { if (used[poolList[j]] == 0) { boss[poolList[j]] = currentBoss; } } } if (used[i] == 1) { i++; } else { // printf("tried %d\n", i); } } // printf("WHY, WTF %d %d\n", assigned, n); if (assigned != n) { // printf("WHY, WTF %d %d\n", assigned, n); // return 0; } FOR(i, n) { printf("%d\n", boss[i] + 1); } //FOR(i, n) //{ // if (used[i] == 0) // printf("nie uzyty %d\n", i); //} // printf("TAK\n"); return 0; } int main3B() { int R = podajR(); int D = podajD(); VI min(D, 0); VI max(D, R); VI found(D, 0); int toBeFound = D; int current[1000]; set<int> kolejka; FOR(i, D) { current[i] = R / 2; kolejka.insert((max[i] - min[i]) * 1000 + i); } while (!kolejka.empty()) { set<int>::reverse_iterator iter = kolejka.rbegin(); int i = (*iter) % 1000; kolejka.erase(*iter); current[i] = min[i]; czyCieplo(current); current[i] = max[i]; bool a = czyCieplo(current); current[i] = min[i]; bool b = czyCieplo(current); int range = max[i] - min[i]; int srodek = (max[i] + min[i]) / 2; if (a) { min[i] = srodek + 1; } else if (b) { max[i] = srodek; if ((range & 1) == 0) { max[i]--; } } else { if ((range & 1) == 0) { current[i] = srodek; toBeFound--; found[i] = 1; continue; } min[i] = srodek; max[i] = srodek + 2; } range = max[i] - min[i]; if (range == 0) { current[i] = min[i]; toBeFound--; found[i] = 1; continue; } if (range == 1) { if (max[i] < R) max[i]++; else min[i]--; } current[i] = (max[i] + min[i]) / 2; kolejka.insert((max[i] - min[i]) * 1000 + i); } znalazlem(current); return 0; } int main() { main3B(); return 0; } |