B题:Crazy Binary String
To 0 as -1, and the prefix, pos [0 + n] = 0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5+3; int a[maxn]; int pos[maxn<<1]; string s; int main(){ ios::sync_with_stdio(false); int n; cin>>n>>s; for(int i=0; i<n; i++){ if(s[i]=='0') a[i] = a[i-1] -1; elseA [I] = A [I- . 1 ] + . 1 ; } for ( int I = 0 ; I <= 2 * n-; I ++ ) { POS [I] = - . 1 ; } POS [ 0 + n-] = 0 ; // Note that this is not a simple but 0 + n-0 int ANS = 0 ; for ( int I = 0 ; I <n-; I ++ ) { IF (! POS [n-+ a [I]] = - . 1 ) ANS = max (ANS, I-POS [n-+ A [I]]); the else { pos[ n+a[i] ] = i; } } cout<<ans<<" "; int zero=0; for(int i=0; i<n; i++){ zero += s[i]=='0'; } cout<<( min(zero,n-zero)<<1 )<<endl; }
H题: Magic Line
Sorting, find n / 2 points and the n / 2 + 1 point
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; const int maxn=20000; const int M=900000009; struct Point{ int x,y; }po[maxn]; bool cmp(Point a,Point b){ if(a.x!=b.x) return a.x<b.x; else return a.y<b.y; } int main(){ int T,n; scanf("%d",&T); while(T--){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d",&po[i].x,&po[i].y); } sort(po+1,po+1+n,cmp); if(po[n/2].x!=po[n/2+1].x) printf("%d %d %d %d\n",po[n/2].x,M,po[n/2+1],-M); else printf("%d %d %d %d\n",po[n/2].x-1,po[n/2+1].y+M,po[n/2].x+1,po[n/2].y-M); } }