标签:scan for vector i++ view pre ble cat hash
1 #include <iostream> 2 #include<bits/stdc++.h> 3 #include <stack> 4 #include <queue> 5 #include <map> 6 #include <set> 7 #include <cstdio> 8 #include <cstring> 9 #include <algorithm> 10 #include <math.h> 11 using namespace std; 12 typedef long long ll; 13 typedef unsigned long long ull; 14 int n,x; 15 int main() 16 { 17 scanf("%d %d",&n,&x); 18 n%=6; 19 if(x==0) 20 { 21 if(n==0||n==5) 22 { 23 printf("0\n"); 24 return 0; 25 } 26 else if(n==1||n==2) 27 { 28 printf("1\n");return 0; 29 } 30 else 31 {printf("2\n");return 0;} 32 33 } 34 else if(x==1) 35 { 36 if(n==0||n==3) 37 { 38 printf("1\n");return 0; 39 } 40 else if(n==1||n==4) 41 { 42 printf("0\n");return 0; 43 } 44 else if(n==2||n==5) 45 { 46 printf("2\n"); 47 return 0; 48 } 49 } 50 else if(x==2) 51 { 52 if(n==0||n==1) 53 { 54 printf("2\n");return 0; 55 } 56 else if(n==2||n==3) 57 { 58 printf("0\n");return 0; 59 } 60 else 61 { 62 printf("1\n");return 0; 63 } 64 } 65 }
1 #include <iostream> 2 #include<bits/stdc++.h> 3 #include <stack> 4 #include <queue> 5 #include <map> 6 #include <set> 7 #include <cstdio> 8 #include <cstring> 9 #include <algorithm> 10 #include <math.h> 11 using namespace std; 12 typedef long long ll; 13 typedef unsigned long long ull; 14 char x[1005],y[1005]; 15 int a[15],b[15]; 16 int n; 17 int main() 18 { 19 scanf("%d",&n); 20 scanf("%s",x); 21 scanf("%s",y); 22 int i; 23 for(i=0;i<n;i++) 24 { 25 a[x[i]-‘0‘]++; 26 b[y[i]-‘0‘]++; 27 } 28 int cnt1=0,cnt2=0; 29 int he=0; 30 for(i=9;i>=0;i--) 31 { 32 he+=b[i]; 33 he-=a[i]; 34 if(he<0) 35 { 36 cnt1+=abs(he); 37 he=0; 38 } 39 } 40 he=0; 41 for(i=0;i<=8;i++) 42 { 43 he+=a[i]; 44 // if(i>0) 45 // { 46 cnt2+=min(he,b[i+1]); 47 he-=min(he,b[i+1]); 48 // } 49 } 50 printf("%d\n%d\n",cnt1,cnt2); 51 }
1 #include <iostream> 2 #include<bits/stdc++.h> 3 #include <stack> 4 #include <queue> 5 #include <map> 6 #include <set> 7 #include <cstdio> 8 #include <cstring> 9 #include <algorithm> 10 #include <math.h> 11 using namespace std; 12 typedef long long ll; 13 typedef unsigned long long ull; 14 const int MAX=1e5+5; 15 vector <int> a[MAX],dp[MAX]; 16 int n,m; 17 int len[MAX]; 18 int main() 19 { 20 scanf("%d %d",&n,&m); 21 int i,j; 22 for(i=1;i<=n;i++) 23 { 24 a[i].resize(m+1); 25 for(j=1;j<=m;j++) 26 scanf("%d",&a[i][j]); 27 } 28 for(i=1;i<=n;i++) 29 { 30 dp[i].resize(m+1,1); 31 if(i-1) 32 for(j=1;j<=m;j++) 33 dp[i][j]+=((a[i][j]>=a[i-1][j])?dp[i-1][j]:0); 34 for(j=1;j<=m;j++) 35 len[i]=max(len[i],dp[i][j]); 36 } 37 int k; 38 scanf("%d",&k); 39 int l,r; 40 while(k--) 41 { 42 scanf("%d %d",&l,&r); 43 if(len[r]>=r-l+1) 44 printf("Yes\n"); 45 else 46 printf("No\n"); 47 } 48 49 }
1 #include <iostream> 2 #include<bits/stdc++.h> 3 #include <stack> 4 #include <queue> 5 #include <map> 6 #include <set> 7 #include <cstdio> 8 #include <cstring> 9 #include <algorithm> 10 #include <math.h> 11 using namespace std; 12 typedef long long ll; 13 typedef unsigned long long ull; 14 const int MAXN=500005; 15 string str[MAXN]; 16 void solve(int l,int r,int d) 17 { 18 for(int i=l;i<=r;i++) 19 { 20 if(i==l) 21 { 22 if((int)str[i].size()==d)l++; 23 continue; 24 } 25 if((int)str[i].size()==d || str[i][d]<str[i-1][d]) 26 { 27 for(int j=l;j<i;j++) 28 while((int)str[j].size()>d)str[j].pop_back(); 29 l=i--; 30 } 31 } 32 for(int i=l,j=l;i<=r;i=j) 33 { 34 while(j<=r && str[j][d]==str[i][d])j++; 35 solve(i,j-1,d+1); 36 } 37 } 38 int main() 39 { 40 ios::sync_with_stdio(false); 41 cin.tie(NULL); 42 int n; 43 cin>>n; 44 for(int i=1;i<=n;i++) 45 cin>>str[i]; 46 solve(1,n,0); 47 for(int i=1;i<=n;i++) 48 cout<<str[i]<<"\n"; 49 return 0; 50 }
明天一早坐飞机,具体分析明天补上。
Codeforces Round #401 (Div. 2)解题报告
标签:scan for vector i++ view pre ble cat hash
原文地址:http://www.cnblogs.com/quintessence/p/6440483.html