2018 多校4 hdu 6335 6336 6342 6343

6335 d题

链接:http://acm.hdu.edu.cn/showproblem.php?pid=6335

题意:n个问题,m个学生,每道题的正确选项有一个,错误选项有bi个,选问题的子集,想要保证至少有一个同学这些问题全对,求问题的个数。

题解:将问题选项数进行排序,从小到大累乘再与学生数m对比。

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <string>
 6 #include <algorithm>
 7 using namespace std;
 8 
 9 int a[110];
10 
11 int main(){
12     int t;
13     cin>>t;
14     while(t--){
15         int n,m,d;
16         cin>>n>>m;
17         for(int i = 0; i < n; i ++){
18             scanf("%d%d",&d,&a[i]);
19             a[i]+=d;
20         }
21         sort(a,a+n);
22         long long mul=1;
23         bool flag = true; 
24         for(int i = 0 ;i < n; i++){
25             mul*=a[i];
26             if(mul>m) {
27                 cout<<i<<endl;
28                 flag = false;
29                 break;
30             }
31         }
32         if(flag) cout<<n<<endl;
33     } 
34     return 0;
35  } 
View Code

6336 e题

找规律可发现是2L*2L的矩阵一直在重复

代码待补(

6342 k题

模拟题

当字符串中有+0?的时候,把?改成+或者*,再判断是否正确

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <string>
 6 #include <algorithm>
 7 using namespace std;
 8 
 9 char s[10010];
10 
11 int main(){
12     int t;
13     cin>>t;
14     while(t--){
15         scanf("%s",s);
16         int l = strlen(s);
17         bool flag = false;
18         for(int i = 0;i < l;i++){
19             if(s[i] == '?'){
20                 if(i == 1 && s[i - 1] == '0')
21                     s[i] = '+';
22                 else if(i >= 2 && s[i - 1] == '0' && (s[i - 2] == '+' || s[i - 2] == '*'))
23                     s[i] = '+';
24                 else
25                     s[i] = '1';
26             }
27         }
28         for(int i = 0;i < l;i++){
29             if(s[i] == '0' && (s[i + 1] >= '0' && s[i + 1] <= '9' && i < l - 1) && (i == 0 || (s[i - 1] < '0' || s[i - 1] > '9'))){
30                 flag = true;
31                 break;
32             }
33             if((s[i] == '*' || s[i] == '+') && (s[i + 1] == '*' || s[i + 1] == '+') && i < l - 1){
34                 flag = true;
35                 break;
36             }
37             if(s[i] == '+' || s[i] == '*'){
38                 if(i == 0 || i == l - 1){
39                     flag = true;
40                     break;
41                 }
42                 if(s[i - 1] < '0' || s[i - 1] > '9'){
43                     flag = true;
44                     break;
45                 }
46                 if(s[i + 1] < '0' || s[i + 1] > '9'){
47                     flag = true;
48                     break;
49                 }
50             }
51         }
52         if(flag) printf("IMPOSSIBLE
");
53         else printf("%s
",s);
54     } 
55     return 0;
56  } 
View Code

用自己样例的时候,注意?是英文符号……中英文没切换怎么试都是错的

6343 j题

简单数学

由不等式可以推出直接从1到n就是最短的

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <string>
 6 #include <algorithm>
 7 using namespace std;
 8 const int maxn = 1e5 + 10;
 9 int a[maxn];
10 
11 int main(){
12     int t;
13     cin>>t;
14     while(t--){
15         int n;
16         cin>>n;
17         for(int i = 0; i < n;i ++) scanf("%d",&a[i]);
18         double ans = sqrt(abs(a[n-1] - a[0]));
19         cout<<(int)ans<<endl;
20     }
21     return 0;
22  } 
View Code
原文地址:https://www.cnblogs.com/moomight/p/11236393.html