2020.10.9 19级training 补题报告

E - High School: Become Human

 1.题意

  给定两个正整数x, y,问x的y次方大还是y的x次方大。

2.题解

  一开始想用快速幂做,但是数据太大了。找规律发现只要两个数至少有一个大于等于3,如果x>y,x的y次方肯定小于y的x次方,反之同理。还有一些特例,2和3,2和4,x为1,y为1。

3.代码

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 const int maxn = 1e4 + 5;
 5 int main() {
 6     ll x, y;
 7     scanf("%lld%lld", &x, &y);
 8     
 9     if(x == y) {
10         cout << "=" << endl;
11         return 0;
12     }
13     if((x == 2 && y == 4) || (x == 4 && y == 2)) {
14         cout << "=" << endl;
15         return 0;
16     }
17     if(x == 2 && y == 3 || x == 1) {
18         cout << "<" << endl;
19         return 0;
20     }
21     if(x == 3 && y == 2 || y == 1) {
22         cout << ">" << endl;
23         return 0;
24     }
25     
26     if(x < y) {
27         cout << ">" << endl;
28         return 0;
29     }
30     if(x > y) {
31         cout << "<" << endl;
32         return 0;
33     }
34 
35 }
View Code

F - Three displays

 1.题意

  有n个位置,每个位置有两个属性s和c,找出三个位置i,j,k,满足si<sj<sk,且三个位置的c之和最小并输出这个和。

 2.题解

  枚举中间的数,各遍历左右两端的位置,找出符合s条件的位置并更新使得c越来越小,枚举一次记录c的和并维护最小值。

 3.代码

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 3e3 + 5;
 4 const int INF = 0x7fffffff;
 5 int n;
 6 int s[3010], c[3010];
 7 int main() {
 8     scanf("%d", &n);
 9     for(int i = 1; i <= n; i++) {
10         scanf("%d", &s[i]);
11     }
12     for(int i = 1; i <= n; i++) {
13         scanf("%d", &c[i]);
14     }
15     
16     c[0] = c[n+1] = INF;
17     int l, r;
18     int ans = INF;
19     
20     for(int i = 2; i <= n - 1; i++) {
21         l = 0;
22         r = n + 1;
23         for(int j = 1; j < i; j++) {
24             if(s[j] < s[i]) {
25                 if(c[j] < c[l]) {
26                     l = j;
27                 }
28             }      
29         }
30             
31         for(int j = i + 1; j <= n; j++) {
32             if(s[j] > s[i]) {
33                 if(c[j] < c[r]) {
34                     r = j;
35                 }
36             }       
37         }
38             
39         if(l != 0 && r != n + 1) {
40             ans = min(ans, c[l] + c[r] + c[i]);    
41         }
42     }
43     
44     if(ans == INF) {
45         printf("-1");
46     } else {
47         printf("%d",ans);
48     }
49     
50     return 0;
51 }
View Code

 

原文地址:https://www.cnblogs.com/lvguapi/p/13834683.html