#include "cielib.h"
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
int n, r; //liczba k jest nam calkowicie niepotrzebna do rozwiazania zadania
int tab[500];
int szukane[500], start[500], srodek;
inline bool check() {
return czyCieplo(tab);
}
inline int suf(int x) {
return (x + 1) / 2;
}
inline void findCoordinates(int x) { //jestesmy w x-owym wymiarze i szukamy
tab[x] = 0;
if (check() == false) {
tab[x] = r;
if (check()) tab[x] = 0;
else tab[x] = r;
}
else tab[x] = r;
check();
start[x] = tab[x];
if (n == 1) {
szukane[0] = srodek; //moze byc gdziekolwiek
return;
}
if (start[x] == 0)
{
int bx = 0, by = srodek;
while (bx < by) {
int sr = (bx + by) / 2;
tab[x] = sr;
check();
tab[x] = sr + 1;
if (check()) bx = ++sr;
else by = sr;
}
tab[x] = bx;
}
else
{
int bx = srodek, by = r;
while (bx < by) {
int sr = ((bx + by) / 2) + 1;
tab[x] = sr;
check();
tab[x] = sr - 1;
if (check()) by = --sr;
else bx = sr;
}
tab[x] = bx;
}
szukane[x] = tab[x];
//zawsze na koncu wracamy do startowej pozycji
FOR(i, 0, n-1) tab[i] = srodek;
check();
}
int main() {
n=podajD();
r=podajR();
srodek = r / 2;
FOR(i, 0, n-1) tab[i] = srodek;
check();
//czas na pierwsza faze, po niej wszystkie liczby beda mialy taka sama odleglosc od wyjsciowej krotki
FOR(i, 0, n-1) findCoordinates(i);
//czas na druga faze
FOR(i, 0, n-1) tab[i] = szukane[i];
int dx = 0, dy = srodek;
while (dx < dy) {
//cout << dx << ' ' << dy << endl;
int sr = (dx + dy) / 2;
FOR(i, 0, n-1)
if (start[i] == 0) tab[i] = szukane[i] + sr;
else tab[i] = szukane[i] - sr;
check();
FOR(i, 0, n-1)
if (start[i] == 0) tab[i] = szukane[i] + (sr + 1);
else tab[i] = szukane[i] - (sr + 1);
if (check()) dx = ++sr;
else dy = sr;
}
FOR(i, 0, n-1)
if (start[i] == 0) tab[i] = szukane[i] + dx;
else tab[i] = szukane[i] - dx;
/*cout << "SZUKANE\n";
FOR(i, 0, n-1) cout << szukane[i] << ' ';
cout << endl << "ZNALEZIONE: " << endl;
FOR(i, 0, n-1) cout << tab[i] << ' ';*/
znalazlem(tab);
}
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 | #include "cielib.h" #include <bits/stdc++.h> using namespace std; #define e1 first #define e2 second #define x first #define y second #define pb push_back #define mp make_pair #define boost ios_base::sync_with_stdio(false) #define eb emplace_back #define OUT(x) {cout << x; exit(0); } #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define scanf(...) scanf(__VA_ARGS__)?:0 typedef int ll; typedef unsigned long long ull; typedef pair <int, int> PII; typedef pair <ll, ll> PLL; typedef pair <PLL, int> PLLI; typedef pair <PLL, PLL> PP; typedef pair <PII, int> PPI; typedef pair <ll, int> PLI; typedef unsigned int ui; const int inf = 1e9+9; const ll MOD = 1e9+696969; const long long INF = 1e18+3; int n, r; //liczba k jest nam calkowicie niepotrzebna do rozwiazania zadania int tab[500]; int szukane[500], start[500], srodek; inline bool check() { return czyCieplo(tab); } inline int suf(int x) { return (x + 1) / 2; } inline void findCoordinates(int x) { //jestesmy w x-owym wymiarze i szukamy tab[x] = 0; if (check() == false) { tab[x] = r; if (check()) tab[x] = 0; else tab[x] = r; } else tab[x] = r; check(); start[x] = tab[x]; if (n == 1) { szukane[0] = srodek; //moze byc gdziekolwiek return; } if (start[x] == 0) { int bx = 0, by = srodek; while (bx < by) { int sr = (bx + by) / 2; tab[x] = sr; check(); tab[x] = sr + 1; if (check()) bx = ++sr; else by = sr; } tab[x] = bx; } else { int bx = srodek, by = r; while (bx < by) { int sr = ((bx + by) / 2) + 1; tab[x] = sr; check(); tab[x] = sr - 1; if (check()) by = --sr; else bx = sr; } tab[x] = bx; } szukane[x] = tab[x]; //zawsze na koncu wracamy do startowej pozycji FOR(i, 0, n-1) tab[i] = srodek; check(); } int main() { n=podajD(); r=podajR(); srodek = r / 2; FOR(i, 0, n-1) tab[i] = srodek; check(); //czas na pierwsza faze, po niej wszystkie liczby beda mialy taka sama odleglosc od wyjsciowej krotki FOR(i, 0, n-1) findCoordinates(i); //czas na druga faze FOR(i, 0, n-1) tab[i] = szukane[i]; int dx = 0, dy = srodek; while (dx < dy) { //cout << dx << ' ' << dy << endl; int sr = (dx + dy) / 2; FOR(i, 0, n-1) if (start[i] == 0) tab[i] = szukane[i] + sr; else tab[i] = szukane[i] - sr; check(); FOR(i, 0, n-1) if (start[i] == 0) tab[i] = szukane[i] + (sr + 1); else tab[i] = szukane[i] - (sr + 1); if (check()) dx = ++sr; else dy = sr; } FOR(i, 0, n-1) if (start[i] == 0) tab[i] = szukane[i] + dx; else tab[i] = szukane[i] - dx; /*cout << "SZUKANE\n"; FOR(i, 0, n-1) cout << szukane[i] << ' '; cout << endl << "ZNALEZIONE: " << endl; FOR(i, 0, n-1) cout << tab[i] << ' ';*/ znalazlem(tab); } |
English