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 }
View Code

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 }
View Code

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 }
View Code

猜你喜欢

转载自www.cnblogs.com/jaydenouyang/p/9096902.html
今日推荐