• 【AtCoder】ARC082


    C - Together

    用一个数组记一下一个数给它本身,左右贡献都是1,看看哪个数的总贡献最大

    #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('
    ')
    #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();
    }
    

    D - Derangement

    就是从前往后,如果遇见一个(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('
    ')
    #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();
    }
    

    E - ConvexScore

    转化一下问题可以发现,就是给定一个点集,如果这个点集可以构成一个凸包包括所有点(就是所有点不共线),那么就有1的贡献
    初始方案数是(2^{N}),去掉只有一个点的,和一个点都不选的
    然后枚举点对来枚举直线,然后算在这条线上的有几个点,需要选至少两个点,然后从总的方案数减掉,注意去重

    #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('
    ')
    #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();
    }
    

    F - Sandglass

    这个维护的话,初始是从A有0克和A有X克开始算
    如果到一个端点,我们可以算出来到这里的最小值是需要初始值小于等于MinX得到的,同理,也可以算出最大值是需要初始值大于等于MaxX得到
    如果在MinX和MaxX之间,就是以每克+1

    #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('
    ')
    #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();
    }
    
  • 相关阅读:
    Spring攻略学习笔记(3.00)AOP核心概念和术语
    zoj 3494
    第43周星期五
    findBugs学习小结
    第42周星期日
    Cookie知识小结
    第42周星期三
    第42周星期六
    第43周星期四小结
    第43周星期二
  • 原文地址:https://www.cnblogs.com/ivorysi/p/10397643.html
Copyright © 2020-2023  润新知