More than 2018 school 4 hdu 6335 6336 6342 6343

6335 d title

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

Meaning of the questions: n question, m a student, the correct option for each question there is a wrong option there is a bi subset choice questions, want to ensure that students have at least one of these problems all right, find the number of issues.

Solution: The number of options to sort the problem, from small to large that multiplies the number of students and then compared with m.

Code:

 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 title

Find the law can be found in a 2L * 2L matrix has been repeated

Code to be completed (

 

6342 k title

Simulation title

When there is a string +0? When putting? + * Or changed, and then determine whether the correct

Code:

 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\n");
53         else printf("%s\n",s);
54     } 
55     return 0;
56  } 
View Code

 

With examples of their own time, pay attention to? English sign in English and has not changed ...... how test is wrong

 

6343 j title

Simple math

It can be introduced directly by the inequality n is from 1 to shortest

Code:

 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

 

Guess you like

Origin www.cnblogs.com/moomight/p/11236393.html