直接認爲一個數是正的,或者第一個數是負的,每次將不合法的負數前綴和改爲+1正數前綴和改爲-1c++
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N; int64 a[MAXN],s[MAXN]; void Solve() { read(N); for(int i = 1 ; i <= N ; ++i) read(a[i]); int64 tmp = 0,ans = 1e18; for(int i = 1 ; i <= N ; ++i) { s[i] = s[i - 1] + a[i]; if(i & 1) { if(s[i] >= 0) {tmp += s[i] + 1;s[i] = -1;} } else { if(s[i] <= 0) {tmp += 1 - s[i];s[i] = 1;} } } ans = min(ans,tmp); tmp = 0; for(int i = 1 ; i <= N ; ++i) { s[i] = s[i - 1] + a[i]; if(i & 1) { if(s[i] <= 0) {tmp += 1 - s[i];s[i] = 1;} } else { if(s[i] >= 0) {tmp += s[i] + 1;s[i] = -1;} } } ans = min(ans,tmp); out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
作atc的博弈論就像挖金子,你挖到了以後才知道它埋得有多淺,而你挖到以前,都刨過好幾個天坑了= =spa
必敗策略就是\(X\)和\(Y\)相差不超過1!!!code
其他都必勝隊列
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int64 X,Y; void Solve() { read(X);read(Y); if(abs(X - Y) <= 1) { puts("Brown"); } else { puts("Alice"); } } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
咱們按照序列遞推一遍,獲得每一個初始指令進行後這個位置的值,詢問一個p,設某個位置的值是\(f[p]\),咱們就找一個小於等於\(f[p - 1]\)的值,使得\(p + 1,N\)裏剩下的數沒法使這個數到達終點get
反着遞推就很簡單了,設\(b[i]\)爲後i個位置保證\(1 - b[i]\)能夠達到的最大\(b[i]\),那麼新加一個數\(a[i - 1]\),咱們獲得\([a[i - 1] - b[i],a[i - 1] + b[i] ]\)都是能夠到達的,咱們只要知足\(b[i] + 1 >= a[i - 1] - b[i]\),咱們就能夠用\(a[i - 1] + b[i]\)來更新\(b[i - 1]\)了it
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 500005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N,D,Q; int a[MAXN],b[MAXN],f[MAXN]; void Solve() { read(N);read(D); for(int i = 1 ; i <= N ; ++i) read(a[i]); for(int i = N ; i >= 1 ; --i) { if(a[i] - b[i + 1] <= b[i + 1] + 1) b[i] = a[i] + b[i + 1]; else b[i] = b[i + 1]; } f[0] = D; for(int i = 1 ; i <= N ; ++i) { f[i] = min(abs(f[i - 1] - a[i]),f[i - 1]); } read(Q); int p; for(int i = 1 ; i <= Q ; ++i) { read(p); if(f[p - 1] > b[p + 1]) puts("YES"); else puts("NO"); } } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
把一個點轉化爲一個向量\((v_i,t_i \times v_i)\)class
而後就變成了每次在隊列後加一個向量,不斷刪前面的序列使得向量的終點的x = Lim
而後重新加的點開始兩兩合併向量直到造成一個凸包db
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 500005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } struct Point { double x,y; Point(double _x = 0,double _y = 0) { x = _x;y = _y; } friend Point operator + (const Point &a,const Point &b) { return Point(a.x + b.x,a.y + b.y); } friend Point operator - (const Point &a,const Point &b) { return Point(a.x - b.x,a.y - b.y); } friend double operator * (const Point &a,const Point &b) { return a.x * b.y - a.y * b.x; } }que[MAXN]; int N,ql,qr; double L,sum; void Solve() { read(N);scanf("%lf",&L); double t,v; for(int i = 1 ; i <= N ; ++i) { scanf("%lf%lf",&t,&v); que[++qr] = Point(v,t * v); sum += t * v; double dec = 0; if(i != 1) { while(1) { if(dec >= v) break; if(que[ql].x <= v - dec) { dec += que[ql].x; sum -= que[ql].y; ++ql; } else { sum -= que[ql].y; que[ql].y -= que[ql].y / que[ql].x * (v - dec); que[ql].x -= v - dec; sum += que[ql].y; break; } } } printf("%.7lf\n",sum / L); while(ql <= qr - 1) { if(que[qr] * que[qr - 1] >= -1e-8) { que[qr - 1] = que[qr] + que[qr - 1]; --qr; } else break; } } } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }