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\n",maxn);
25     return 0;
26 }

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

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\n",cnt,a[cnt]);
34     //    printf("b[%d]=%d\n",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\n",p[n-1].x-p[0].x,cnt);
45     for(i=0;i<cnt;i++) printf("%d %d\n",a[i]+1,b[i]+1);
46     return 0;
47 }

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

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<<"\n";
33     return 0;
34 }

D是二分搜索

E是dp

再补吧----

go---go--

时间: 2024-08-04 13:30:04

Codeforces Round #274 (Div. 2)的相关文章

codeforces水题100道 第八题 Codeforces Round #274 (Div. 2) A. Expression (math)

题目链接:http://www.codeforces.com/problemset/problem/479/A题意:给你三个数a,b,c,使用+,*,()使得表达式的值最大.C++代码: #include <iostream> using namespace std; int a, b, c, ans; int main() { cin >> a >> b >> c; int t = max(a+b, a*b); ans = max(t + c, t * c

Codeforces Round #274 (Div. 2) E:Riding in a Lift DP + 前缀优化

题意: n,a,b,k(2?≤?n?≤?5000,1?≤?k?≤?5000,1?≤?a,?b?≤?n,a?≠?b).四个数.1到n的数,顺序排列,其实位置人在a位置而中心位置在b,人每次只能走一个点走动的距离必须小于|b?a|,人走k步之后停止,问人一共有多少种走法. 分析: 开始很容易想到一个深度优先搜索实现递归方法dfs(a, k)但k变为0就到达搜索底部,这样时间复杂度是O(nk)显然非常不好. 然后可以想到会有重算的情况,就可以加一个记忆优化把算过的(a,k)的二元组都保存下来.这样处理

Codeforces Round #274 (Div. 2) B. Towers

As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of ai cubes stacked one on top of the other. Petya defines the instability of a set of towers a

Codeforces Round #274 (Div. 2) C. Exams

Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several

Codeforces Round #274 (Div. 2) E. Riding in a Lift(DP)

Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take t

Codeforces Round #274 Div.1 C Riding in a Lift --DP

题意:给定n个楼层,初始在a层,b层不可停留,每次选一个楼层x,当|x-now| < |x-b| 且 x != now 时可达(now表示当前位置),此时记录下x到序列中,走k步,最后问有多少种可能的数的序列. 解法: 定义:      dp[i][j] 表示第i步在j楼的不同序列的个数 转移方程: 当j<b时, 那么dp[i][j] += dp[i-1][0~(j与b的中点(以下))] 当j>b时, 那么dp[i][j] += dp[i-1][(j与b的中点(以下))~n] 由于dp[

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿