Codeforces Round #402 (Div. 2)解题报告
A.
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 a[10],b[10],he[10]; 15 int n; 16 int cnt; 17 int main() 18 { 19 scanf("%d",&n); 20 int i; 21 int tem; 22 for(i=1;i<=n;i++) 23 { 24 scanf("%d",&tem); 25 a[tem]++; 26 he[tem]++; 27 } 28 for(i=1;i<=n;i++) 29 { 30 scanf("%d",&tem); 31 b[tem]++; 32 he[tem]++; 33 } 34 for(i=1;i<=5;i++) 35 { 36 if(he[i]%2) 37 { 38 printf("-1 ");return 0; 39 } 40 else 41 { 42 if(a[i]>he[i]/2) 43 cnt+=a[i]-he[i]/2; 44 } 45 46 } 47 printf("%d ",cnt); 48 return 0; 49 }
B.
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 a[105]; 15 int k; 16 int main() 17 { 18 scanf("%s %d",a,&k); 19 if(strlen(a)==1&&a[0]=='0') 20 { 21 printf("0 "); 22 return 0; 23 } 24 else 25 { 26 int cnt=0; 27 int an=0; 28 int ge=0; 29 int j; 30 j=strlen(a)-1; 31 while(a[j]=='0') 32 { 33 cnt++; 34 j--; 35 } 36 if(cnt>=k) 37 printf("0 "); 38 else 39 { 40 int i; 41 for(i=j;i>=0&&cnt<k;i--) 42 { 43 if(a[i]=='0') 44 cnt++; 45 else 46 ge++; 47 } 48 if(cnt==k) 49 printf("%d ",ge); 50 else if(cnt>0) 51 printf("%d ",strlen(a)-1); 52 } 53 } 54 return 0; 55 }