//Tadrion #include <cstdio> #include <vector> #include <iostream> #include <deque> #include <map> #include <set> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <queue> #include <stack> #include <algorithm> #include <utility> #include "cielib.h" using namespace std; #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define ABSS(a) (MAX(a,-a)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define CLEAR(x) (memset(x,0,sizeof(x))) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define VAR(v, n) __typeof(n) v = (n) #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i) #define DBG(v) cout<<#v<<" = "<<v<<endl; #define IN(x,y) ((y).find(x)!=(y).end()) #define ST first #define ND second #define PB push_back #define PF push_front #define MP make_pair typedef long long int LL; typedef pair<int,int> PII; typedef vector<int> VI; int d,k,r; int fi[510],la[510],nextt[510],cur[510],best[510]; int bestest[510]; int minusCnt=0,zw=1; int lenDiag; int ile; int main() { d = podajD(); k = podajK(); r = podajR(); REP(i,d) la[i]=r; ile = r; zw=1; FOR(ccc,1,d) { //printf("superdupa\n"); while(1) { ile = la[d-1]-fi[d-1]; if(ile == 1) break; REP(i,d) if(i < minusCnt) nextt[i] = ((fi[i]) + (-1)*((ile+1) / 2)); else nextt[i] = ((fi[i]) + ((ile+1) / 2)); czyCieplo(fi); if(czyCieplo(la)) { //REP(i,d) la[i] = nextt[i]; REP(i,d) fi[i] = nextt[i]; } else { REP(i,d) la[i] = nextt[i]; } } czyCieplo(fi); if(czyCieplo(la)) { memcpy(best,la,sizeof(int)*d); } else memcpy(best,fi,sizeof(int)*d); if(ccc < d) { minusCnt++; ile = 1000000001; REP(i,d) { if(i < minusCnt) ile = MIN(ile, best[i]); else ile = MIN(ile, r-best[i]); } if(ile==0) break; REP(i,d) { if(i < minusCnt) { fi[i] = best[i]+ile; la[i] = best[i]-ile; } else { fi[i] = best[i]-ile; la[i] = best[i]+ile; } } ile*=2; //memcpy(tmp,cur,sizeof(int)*d); //memcpy(cur,best,sizeof(int)*d); //memcpy(best,tmp,sizeof(int)*d); zw=1; //printf("Przekatna\n"); czyCieplo(fi); czyCieplo(la); } } //znalazlem(best); //printf("popr"); for(int z = -1; z <= 1; z+=2){ REP(kt,d) { //printf("wejscie %d\n",kt); memcpy(cur,best,sizeof(int)*d); if(best[kt]+z > r || best[kt]+z < 0) continue; else cur[kt]+=z; czyCieplo(best); if(czyCieplo(cur)) { memcpy(best,cur,sizeof(int)*d); } } } znalazlem(best); }
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 | //Tadrion #include <cstdio> #include <vector> #include <iostream> #include <deque> #include <map> #include <set> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <queue> #include <stack> #include <algorithm> #include <utility> #include "cielib.h" using namespace std; #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define ABSS(a) (MAX(a,-a)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define CLEAR(x) (memset(x,0,sizeof(x))) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define VAR(v, n) __typeof(n) v = (n) #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i) #define DBG(v) cout<<#v<<" = "<<v<<endl; #define IN(x,y) ((y).find(x)!=(y).end()) #define ST first #define ND second #define PB push_back #define PF push_front #define MP make_pair typedef long long int LL; typedef pair<int,int> PII; typedef vector<int> VI; int d,k,r; int fi[510],la[510],nextt[510],cur[510],best[510]; int bestest[510]; int minusCnt=0,zw=1; int lenDiag; int ile; int main() { d = podajD(); k = podajK(); r = podajR(); REP(i,d) la[i]=r; ile = r; zw=1; FOR(ccc,1,d) { //printf("superdupa\n"); while(1) { ile = la[d-1]-fi[d-1]; if(ile == 1) break; REP(i,d) if(i < minusCnt) nextt[i] = ((fi[i]) + (-1)*((ile+1) / 2)); else nextt[i] = ((fi[i]) + ((ile+1) / 2)); czyCieplo(fi); if(czyCieplo(la)) { //REP(i,d) la[i] = nextt[i]; REP(i,d) fi[i] = nextt[i]; } else { REP(i,d) la[i] = nextt[i]; } } czyCieplo(fi); if(czyCieplo(la)) { memcpy(best,la,sizeof(int)*d); } else memcpy(best,fi,sizeof(int)*d); if(ccc < d) { minusCnt++; ile = 1000000001; REP(i,d) { if(i < minusCnt) ile = MIN(ile, best[i]); else ile = MIN(ile, r-best[i]); } if(ile==0) break; REP(i,d) { if(i < minusCnt) { fi[i] = best[i]+ile; la[i] = best[i]-ile; } else { fi[i] = best[i]-ile; la[i] = best[i]+ile; } } ile*=2; //memcpy(tmp,cur,sizeof(int)*d); //memcpy(cur,best,sizeof(int)*d); //memcpy(best,tmp,sizeof(int)*d); zw=1; //printf("Przekatna\n"); czyCieplo(fi); czyCieplo(la); } } //znalazlem(best); //printf("popr"); for(int z = -1; z <= 1; z+=2){ REP(kt,d) { //printf("wejscie %d\n",kt); memcpy(cur,best,sizeof(int)*d); if(best[kt]+z > r || best[kt]+z < 0) continue; else cur[kt]+=z; czyCieplo(best); if(czyCieplo(cur)) { memcpy(best,cur,sizeof(int)*d); } } } znalazlem(best); } |