Codeforces Round #274 (Div. 2)

A. Expression

题意:给出a,b,c,给出"+","*",“()”在这三个数中任意放置这三个符号,求最大值

直接枚举6种情况就可以了,自己写的时候是挨个比找的最大值,后来发现别人的题解里面,直接将这6个值排序取最后一个数就可以了。

 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath>   
 5 #include<algorithm>  
 6 using namespace std;
 7 
 8 typedef long long LL;
 9 
10 int main()
11 {
12     int a,b,c,x,maxn=-100,i;
13     cin>>a>>b>>c;
14     for(i=1;i<=6;i++)
15     {
16         if(i==1) x=a+b+c;
17         if(i==2) x=a*b+c;
18         if(i==3) x=a+b*c;
19         if(i==4) x=a*b*c;
20         if(i==5) x=(a+b)*c;
21         if(i==6) x=a*(b+c);
22         maxn=max(maxn,x);
23     }
24     printf("%d
",maxn);
25     return 0;
26 }
View Code

补-----------

B. Towers

题意:给出n座塔,n座塔的高度,搬运的次数m,每次从更高的塔搬1个立方体到更低的立方体,在不超过k次搬运的条件下,获得的最高的塔的高度与最低的塔的高度差最小是多少,搬运了多少次,并输出是从哪座塔搬到哪座塔

每次移动,都从最多的拿给最少的,直到两者的差值<=1(因为等于1的时候再搬运的话会使差值为2,不符合最小),再用两个数组分别将移动的位置存下来

 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath>   
 5 #include<algorithm>  
 6 using namespace std;
 7 
 8 typedef long long LL;
 9 int a[10005],b[10005];
10 
11 struct node{
12     int x,pos;
13 } p[10005];
14 
15 int cmp(node n1,node n2){
16     return n1.x<n2.x;
17 }
18 
19 int main()
20 {
21     int n,m,i,cnt=0;
22     cin>>n>>m;
23     for(i=0;i<n;i++) {
24         cin>>p[i].x;
25         p[i].pos=i;    
26     }
27     
28     while(m--){
29         sort(p,p+n,cmp);
30         if(p[n-1].x-p[0].x<=1) break;
31         a[cnt]=p[n-1].pos;
32         b[cnt]=p[0].pos;
33     //    printf("a[%d]=%d
",cnt,a[cnt]);
34     //    printf("b[%d]=%d
",cnt,b[cnt]);
35         
36         
37         cnt++;
38         
39         p[n-1].x--;
40         p[0].x++;
41     }
42     sort(p,p+n,cmp);
43     
44     printf("%d %d
",p[n-1].x-p[0].x,cnt);
45     for(i=0;i<cnt;i++) printf("%d %d
",a[i]+1,b[i]+1);
46     return 0;    
47 }
View Code

另外= =为何题目里面第二个样例输出来和最后评的数据不一样-----(干瞪眼找半天都木有找出错-----后来交了题解的代码是过了的发现应该是打印错吗------)

C. Exams

题意:给出n场考试,a[i]为老师规定的学生参加考试的时间,b[i]为老师允许学生参加考试的时间,即学生既可以在a[i]参加第i场考试,也可以在b[i]参加第i场考试,问学生至少花费多少天参加完所有考试(同时保证a[i]从小到大)

先按两个关键字排序,排序后再扫描一遍,

如果a[i].y小于ans(当前最大值),那么 ans=max(ans,a[i].x);(因为参加考试既可以在a[i],也可以在b[i])= =因为没有想到这一点,一直挂在34个数据上------555555

 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath>   
 5 #include<algorithm>  
 6 using namespace std;
 7 
 8 typedef long long LL;
 9 struct node{
10     LL x,y;
11 }a[10005];
12 
13 int cmp(node n1,node n2){
14     if(n1.x!=n2.x) return n1.x<n2.x;
15     return n1.y<n2.y;
16 }
17 
18 int main()
19 {
20     int n,i;
21     LL ans=0;
22     scanf("%d",&n);
23     for(i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
24     sort(a+1,a+n+1,cmp);
25     
26     ans=0;
27     int flag=0;
28     for(i=1;i<=n;i++){
29         if(a[i].y>=ans) ans=a[i].y;
30         else ans=max(ans,a[i].x);
31     }
32     cout<<ans<<"
";
33     return 0;
34 }
View Code

D是二分搜索

E是dp

再补吧----

go---go--

原文地址:https://www.cnblogs.com/wuyuewoniu/p/4321000.html