2018ccpc_hn
A. Easy h-index
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <map> 7 #include <cmath> 8 #include <vector> 9 10 #define Faster ios::sync_with_stdio(false),cin.tie(0) 11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) 12 #define Close fclose(stdin),fclose(stdout) 13 const int maxn = 2*1e5 + 5; 14 using namespace std; 15 const int MOD = 1e9+7; 16 typedef long long ll; 17 18 int a[maxn]; 19 20 int main(){ 21 Faster; 22 int n; 23 while(cin >> n){ 24 for(int i = 0;i <= n;i++){ 25 cin >> a[i]; 26 } 27 28 int sum = 0; 29 int h = n+1; 30 while(sum < h){ 31 sum += a[--h]; 32 } 33 cout << h << endl; 34 } 35 return 0; 36 }
B. Higher h-index
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <map> 7 #include <cmath> 8 #include <vector> 9 10 #define Faster ios::sync_with_stdio(false),cin.tie(0) 11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) 12 #define Close fclose(stdin),fclose(stdout) 13 const int maxn = 2*1e5 + 5; 14 using namespace std; 15 const int MOD = 1e9+7; 16 typedef long long ll; 17 18 int a[maxn]; 19 20 int main(){ 21 Faster; 22 int n, a; 23 while(cin >> n >> a){ 24 if(n < a) 25 cout << n << endl; 26 else{ 27 int h = a + (n-a)/2; 28 cout << h << endl; 29 } 30 } 31 return 0; 32 }
F. Sorting
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <map> 7 #include <cmath> 8 #include <vector> 9 10 #define Faster ios::sync_with_stdio(false),cin.tie(0) 11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) 12 #define Close fclose(stdin),fclose(stdout) 13 const int maxn = 1e3+5; 14 using namespace std; 15 const int MOD = 1e9+7; 16 typedef long long ll; 17 18 struct node 19 { 20 ll a,b,c; 21 int id; 22 }t[maxn]; 23 24 bool cmp(node x, node y){ 25 ll xx = x.a*y.c + x.b*y.c; 26 ll yy = y.a*x.c + y.b*x.c; 27 if(xx == yy) 28 return x.id < y.id; 29 return xx < yy; 30 } 31 32 int main(){ 33 Faster; 34 int n; 35 while(cin >> n){ 36 for(int i = 0;i < n;i++){ 37 cin >> t[i].a >> t[i].b >> t[i].c; 38 t[i].id = i+1; 39 } 40 sort(t,t+n,cmp); 41 for(int i = 0;i < n;i++){ 42 if(i == 0) 43 cout << t[i].id; 44 else 45 cout << " " << t[i].id; 46 } 47 cout << endl; 48 } 49 return 0; 50 }
G. String Transformation
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <map> 7 #include <cmath> 8 #include <vector> 9 10 #define Faster ios::sync_with_stdio(false),cin.tie(0) 11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) 12 #define Close fclose(stdin),fclose(stdout) 13 const int maxn = 1e5 + 5; 14 using namespace std; 15 const int MOD = 1e9+7; 16 typedef long long ll; 17 18 int main(){ 19 Faster; 20 string s; 21 string t; 22 while(cin >> s >> t){ 23 int sc, tc; 24 sc = tc = 0; 25 for(char x:s){ 26 if(x == 'c'){ 27 sc++; 28 } 29 } 30 for(char x:t){ 31 if(x == 'c'){ 32 tc++; 33 } 34 } 35 if(sc != tc){ 36 cout << "No" << endl; 37 continue; 38 } 39 int i, j, sa, sb, ta, tb; 40 i = j = sa = sb = ta = tb = 0; 41 bool ok = true; 42 s += "c"; 43 t += "c"; 44 while(i < s.size() && j < t.size()){ 45 while(s[i] != 'c' && i < s.size()){ 46 if(s[i] == 'a') 47 sa++; 48 if(s[i] == 'b') 49 sb++; 50 i++; 51 } 52 while(t[j] != 'c' && j < t.size()){ 53 if(t[j] == 'a') 54 ta++; 55 if(t[j] == 'b') 56 tb++; 57 j++; 58 } 59 if( sa%2 != ta%2 || sb%2 != tb%2){ 60 ok = false; 61 break; 62 } 63 if(s[i] == 'c'){ 64 sa = sb = 0; 65 i++; 66 } 67 if(t[j] == 'c'){ 68 ta = tb = 0; 69 j++; 70 } 71 } 72 if(ok) 73 cout << "Yes" << endl; 74 else 75 cout << "No" << endl; 76 } 77 return 0; 78 }
K. 2018
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <map> 7 #include <cmath> 8 #include <vector> 9 10 #define Faster ios::sync_with_stdio(false),cin.tie(0) 11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) 12 #define Close fclose(stdin),fclose(stdout) 13 const int maxn = 1e4 + 5; 14 using namespace std; 15 const int MOD = 1e9+7; 16 typedef long long ll; 17 18 int main(){ 19 Faster; 20 ll a, b, c, d; 21 while(cin >> a >> b >> c >> d){ 22 ll sum = 0; 23 ll x = (b/2018 - (a-1)/2018); 24 ll y = (d/2018 - (c-1)/2018); 25 sum += x*(d-c+1)+y*(b-a+1)-x*y; //减去重复的部分 26 27 sum += (b/1009 - (a-1)/1009 - x)*(d/2 - (c-1)/2 - y); 28 sum += (d/1009 - (c-1)/1009 - y)*(b/2 - (a-1)/2 - x); 29 cout << sum << endl; 30 } 31 32 return 0; 33 }