Educational Codeforces Round 41 (Rated for Div. 2)
=====》【補題:F G 】【學習:平衡樹】《=====
A. Tetris
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define fre(i,t,n) for(int i =(t);i<=(n);++i) 4 #define fer(i,n,t) for(int i =(n);i>=(t);--i) 5 #define mp make_pair 6 #define pb push_back 7 typedef long long ll; 8 void smain(); 9 intView Codemain(){ 10 ios::sync_with_stdio(false); 11 smain(); 12 return 0; 13 } 14 const int MAXN = 1000+10; 15 int X[MAXN]; 16 void smain(){ 17 int n,m; 18 cin>>n>>m; 19 fre(i,1,m) 20 { 21 int d; 22 cin>>d; 23 X[d]++; 24 } 25 int g=X[1];26 fre(i,1,n) 27 { 28 g=min(X[i],g); 29 } 30 cout<<g<<endl; 31 }
B. Lecture Sleep
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define fre(i,t,n) for(int i =(t);i<=(n);++i) 4 #define fer(i,n,t) for(int i =(n);i>=(t);--i) 5 #defineView Codemp make_pair 6 #define pb push_back 7 typedef long long ll; 8 void smain(); 9 int main(){ 10 ios::sync_with_stdio(false); 11 smain(); 12 return 0; 13 } 14 const int MAXN = 1e5+10; 15 ll A[MAXN],B[MAXN],C[MAXN]; 16 void smain(){ 17 int n,k; 18 cin>>n>>k; 19 fre(i,1,n) 20 { 21 cin>>A[i]; 22 } 23 ll sum=0; 24 fre(i,1,n) 25 { 26 int d; 27 cin>>d; 28 if(d) sum+=A[i],A[i]=0; 29 } 30 fre(i,1,n) 31 { 32 A[i]+=A[i-1]; 33 } 34 ll Max=0; 35 fre(i,k,n) 36 { 37 Max=max(A[i]-A[i-k],Max); 38 } 39 cout<<sum+Max<<endl; 40 }
C. Chessboard
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define fre(i,t,n) for(int i =(t);i<=(n);++i) 4 #define fer(i,n,t) for(int i =(n);i>=(t);--i) 5 #define mp make_pair 6 #define pb push_back 7 typedef long long ll; 8 void smain(); 9 int main(){ 10 ios::sync_with_stdio(false); 11 smain(); 12 return 0; 13 } 14 int S[]{0,0,1,1}; 15 const int MAXN = 100+3; 16 char A[MAXN][MAXN]; 17 int n; 18 void GetAns(int &a,int &b) 19 { 20 fre(i,0,n-1) 21 { 22 cin>>A[i]; 23 } 24 a=0,b=0; 25 fre(i,0,n-1) 26 { 27 fre(j,0,n-1) 28 { 29 a+=(A[i][j]!=(‘0‘+(i+j)%2)); 30 b+=(A[i][j]!=(‘1‘-(i+j)%2)); 31 } 32 } 33 } 34 int B[4][2]; 35 void smain(){ 36 cin>>n; 37 fre(i,0,3) 38 { 39 GetAns(B[i][0],B[i][1]); 40 } 41 int ans=n*n*4-1; 42 do{ 43 int sum=0; 44 fre(i,0,3) 45 { 46 sum+=B[i][S[i]]; 47 } 48 ans=min(ans,sum); 49 }while(next_permutation(S,S+4)); 50 cout<<ans<<endl; 51 }View Code
D. Pair Of Lines
這題想法是這樣的:
首先,只有4個點的話XJB隨便畫都可以
對於點數>4:選點1,2,3作討論:
1)1,2在同一條線上:那就判斷剩下哪些點也在這條線上,再判斷不屬於這條線的點是否構成一條直線
2)1,2不在同一條線上,那麽3要麽最後跟1在一塊,要麽最後跟2在一塊,處理同1)
P.S.:對於斜率,為了避免精度,特意用了互質的兩個數表示分數,負數永遠屬於分子。不過一開始沒註意處理(3,0) (5,0) 和(0,3) (0,-5) 這種情況WA了幾發=-=最後處理是把(x,0)->(1,0),(0,x)->(0,1)醬紫
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define fre(i,t,n) for(int i =(t);i<=(n);++i) 4 #define fer(i,n,t) for(int i =(n);i>=(t);--i) 5 #define mp make_pair 6 #define pb push_back 7 typedef long long ll; 8 void smain(); 9 int main(){ 10 ios::sync_with_stdio(false); 11 smain(); 12 return 0; 13 } 14 const int MAXN = 1e5+100; 15 int X[MAXN],Y[MAXN]; 16 bool flag[MAXN]; 17 typedef pair<ll,ll> Pii; 18 Pii Get(int i,int j) 19 { 20 ll x=X[i]-X[j],y=Y[i]-Y[j]; 21 ll f=1; 22 if(x<0) f=-f,x=-x; 23 if(y<0) f=-f,y=-y; 24 if(x==0) return mp(0,1); 25 if(y==0) return mp(1,0); 26 ll g=__gcd(x,y); 27 return mp(x/g*f,y/g); 28 } 29 int n; 30 int step1(int st,Pii T,int &t1,int &t2,int x) 31 { 32 int noin=0; 33 memset(flag,0,sizeof flag); 34 fre(i,st,n) 35 { 36 if(Get(x,i)==T) 37 flag[i]=true; 38 else{ 39 noin++; 40 if(noin==1) t1=i; 41 if(noin==2) t2=i; 42 } 43 } 44 return noin; 45 } 46 bool step2(int st,Pii tmp,int t1) 47 { 48 fre(i,st,n) 49 { 50 if(!flag[i]) 51 { 52 if(i==t1) continue; 53 if(tmp!=Get(t1,i)) return false; 54 } 55 } 56 return true; 57 } 58 void smain(){ 59 cin>>n; 60 fre(i,1,n) 61 { 62 cin>>X[i]>>Y[i]; 63 } 64 if(n<=4) 65 { 66 cout<<"YES"<<endl; 67 return; 68 } 69 /*in one*/ 70 Pii T=Get(1,2); 71 int t1,t2; 72 int noin=step1(3,T,t1,t2,1); 73 flag[1]=flag[2]=true; 74 if(noin<=2) 75 { 76 cout<<"YES"<<endl; 77 return; 78 } 79 Pii tmp=Get(t1,t2); 80 if(step2(3,tmp,t1)) 81 { 82 cout<<"YES"<<endl; 83 return; 84 } 85 86 /* 1-3 */ 87 T=Get(1,3); 88 noin=step1(3,T,t1,t2,1); 89 if(noin<=1) 90 { 91 cout<<"YES"<<endl; 92 return; 93 } 94 95 tmp=Get(2,t1); 96 if(step2(3,tmp,2)) 97 { 98 cout<<"YES"<<endl; 99 return; 100 } 101 102 /* 2-3 */ 103 T=Get(2,3); 104 noin=step1(3,T,t1,t2,2); 105 if(noin<=1) 106 { 107 cout<<"YES"<<endl; 108 return; 109 } 110 111 tmp=Get(1,t1); 112 if(step2(3,tmp,1)) 113 { 114 cout<<"YES"<<endl; 115 return; 116 } 117 cout<<"NO"<<endl; 118 }View Code
E. Tufurama
敲喜歡這道題的=-=
其實題意無非就是對1<=i<=N,問 j=[1, Ai ] 中有多少個Aj>=i。
考慮轉換一下問題,就是:對1<=i<=N,有多少個 Aj>=i 使得 j=[1, Ai]。
對轉換後的問題,把(Ai,i) 對從大到小排列,倒序處理i,對每個i,首先把所有 Ax>=i 的 (Ax,x)出列,把x扔到線段樹(或者平衡樹裏面),然後線段樹裏詢問 [1, Ai] 中有多少個數就好了
自己推的就是爽=-=我都好佩服我寄己
下來有空要看一下平衡樹
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define fre(i,t,N) for(int i =(t);i<=(N);++i) 4 #define fer(i,N,t) for(int i =(N);i>=(t);--i) 5 #define mp make_pair 6 #define pb push_back 7 typedef long long ll; 8 void smain(); 9 int main(){ 10 ios::sync_with_stdio(false); 11 smain(); 12 return 0; 13 } 14 #define lson l,m,rt<<1 15 #define rson m+1,r,rt<<1|1 16 typedef pair<ll,int> Pii; 17 priority_queue<Pii> qu; 18 const int MAXN = 2e5+10; 19 ll Tree[MAXN<<2]; 20 int n; 21 void Update(int pos,int l=1,int r=n,int rt=1) 22 { 23 if(l==r) 24 { 25 Tree[rt]=1; 26 return; 27 } 28 int m=(l+r)>>1; 29 if(pos<=m) Update(pos,lson); 30 else Update(pos,rson); 31 Tree[rt]++; 32 } 33 ll Query(int L,int R,int l=1,int r=n,int rt=1) 34 { 35 if(L<=l&&r<=R) 36 return Tree[rt]; 37 int m=(l+r)>>1; 38 ll ans=0; 39 if(L<=m) ans+=Query(L,R,lson); 40 if(R>m) ans+=Query(L,R,rson); 41 return ans; 42 } 43 ll A[MAXN]; 44 void smain(){ 45 cin>>n; 46 ll gg=0; 47 fre(i,1,n) 48 { 49 cin>>A[i]; 50 gg+=(A[i]>=i); 51 qu.push(mp(A[i],i)); 52 } 53 ll ans=0; 54 fer(i,n,1) 55 { 56 while(!qu.empty()&&qu.top().first>=i) 57 { 58 Update(qu.top().second); 59 qu.pop(); 60 } 61 ans+=Query(1,A[i]); 62 } 63 cout<<(ans-gg)/2<<endl; 64 }View Code
F. k-substrings
G. Partitions
鹹魚已經懶得寫題解了 = - = 有不懂的可以評論或者私下聯系
版權所有:scidylanpno
原文鏈接:http://www.cnblogs.com/scidylanpno/p/8745965.html
Educational Codeforces Round 41 (Rated for Div. 2)