用一个数组记一下一个数给它自己,左右贡献都是1,看看哪一个数的总贡献最大c++
#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 MAXN 100005 #define eps 1e-12 //#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; int A[MAXN]; int cnt[MAXN]; void Solve() { read(N); for(int i = 1 ; i <= N ; ++i) read(A[i]); for(int i = 1 ; i <= N ; ++i) { if(A[i]) cnt[A[i] - 1]++; cnt[A[i]]++; cnt[A[i] + 1]++; } int res = 0; for(int i = 0 ; i <= 100001 ; ++i) res = max(cnt[i],res); out(res);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
就是从前日后,若是碰见一个\(A[i] = i\)和前或后换一下数组
#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 MAXN 100005 #define eps 1e-12 //#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,A[MAXN]; void Solve() { read(N); for(int i = 1 ; i <= N ; ++i) read(A[i]); int cnt = 0; for(int i = 1 ; i <= N ; ++i) { if(A[i] == i) { if(i == N) swap(A[i],A[i - 1]); else swap(A[i],A[i + 1]); ++cnt; } } out(cnt);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
转化一下问题能够发现,就是给定一个点集,若是这个点集能够构成一个凸包包括全部点(就是全部点不共线),那么就有1的贡献
初始方案数是\(2^{N}\),去掉只有一个点的,和一个点都不选的
而后枚举点对来枚举直线,而后算在这条线上的有几个点,须要选至少两个点,而后从总的方案数减掉,注意去重spa
#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 MAXN 100005 #define eps 1e-12 //#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); } const int MOD = 998244353; int N,ans; struct Point { int x,y; Point(int _x = 0,int _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 int operator * (const Point &a,const Point &b) { return a.x * b.y - a.y * b.x; } friend int dot(const Point &a,const Point &b) { return a.x * b.x + a.y * b.y; } }P[205]; int inc(int a,int b) { return a + b >= MOD ? a + b - MOD : a + b; } int mul(int a,int b) { return 1LL * a * b % MOD; } int fpow(int x,int c) { int res = 1,t = x; while(c) { if(c & 1) res = mul(res,t); t = mul(t,t); c >>= 1; } return res; } void Solve() { read(N); ans = fpow(2,N);ans = inc(ans,MOD - N - 1); for(int i = 1 ; i <= N ; ++i) { read(P[i].x);read(P[i].y); } for(int i = 1 ; i <= N ; ++i) { for(int j = 1 ; j <= N ; ++j) { if(i == j || P[i].x > P[j].x || (P[i].x == P[j].x && P[i].y > P[j].y)) continue; int cnt = 2; for(int k = 1 ; k <= N ; ++k) { if(k == i || k == j) continue; if((P[k] - P[i]) * (P[k] - P[j]) == 0) { if(P[k].x < P[j].x || (P[k].x == P[j].x && P[k].y < P[j].y)) goto fail; ++cnt; } } ans = inc(ans,MOD - inc(fpow(2,cnt),MOD - cnt - 1)); fail:; } } out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
这个维护的话,初始是从A有0克和A有X克开始算
若是到一个端点,咱们能够算出来到这里的最小值是须要初始值小于等于MinX获得的,同理,也能够算出最大值是须要初始值大于等于MaxX获得
若是在MinX和MaxX之间,就是以每克+1code
#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 MAXN 100005 #define eps 1e-12 //#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 K,Q; int64 X; vector<pair<int64,int64> > v; void Solve() { read(X);read(K); int64 r; for(int i = 1 ; i <= K ; ++i) { read(r); v.pb(mp(r,-1)); } int64 a,b; read(Q); for(int i = 1 ; i <= Q ; ++i) { read(a);read(b); v.pb(mp(a,b)); } sort(v.begin(),v.end()); int64 MinX = 0,MinY = 0,MaxX = X,MaxY = X; int64 pre = 0,k = -1; for(auto t : v) { MinY = MinY + (t.fi - pre) * k; if(MinY < 0) { MinX -= MinY; MinY = 0; } if(MinY > X) MinY = X; MaxY = MaxY + (t.fi - pre) * k; if(MaxY > X) { MaxX -= (MaxY - X); MaxY = X; } if(MaxY < 0) MaxY = 0; if(t.se == -1) k *= -1; else { if(t.se <= MinX) {out(MinY);enter;} else if(t.se >= MaxX) {out(MaxY);enter;} else {out(MinY + t.se - MinX);enter;} } pre = t.fi; } } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }