获取中...

-

Just a minute...

题目链接:

http://codeforces.com/contest/1119/problem/B

题目思路:

比赛的时候这个题写了好久,主要是就想着按照俩个间距最小放一起,然后就想着放一个把前面的优化一次就写不出来

然后看了这个豁然开朗,排完序相邻的就是间距最小了,嗯,就是这样

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define LL long long
using namespace std;
const int MAX = 10010;
const int INF = 0xfffffff;//268435455,2e8;
const int MOD = 1;
int T,N,M;
//std::ios::sync_with_stdio(false);
/*-------------------------------------------------------*/

vector<int> bottle;

/* --------------------------------------------------------------*/


int main()
{
cin >> N >> M;
int flag= 1;
for(int i = 0;i < N;i++)
{
int x;
int height = 0;
cin >> x;
bottle.push_back(x);
sort(bottle.begin(),bottle.end());
for(int i = bottle.size()-1;i >= 0;i -= 2)
{
if(i >= 1) height += max(bottle[i],bottle[i-1]);
else height += bottle[0];
}
if(height > M)
{
for(int j = i+1;j<N;j++)
{
int x;
cin >> x;
}
cout << i <<endl;
flag = 0;
break;
}
}
if(flag)cout << N << endl;
return 0;
}

题目链接:

http://codeforces.com/contest/1119/problem/E

题目思路:

​ 这题吧比赛的时候因为B题做了好久其实就没怎么看,我也不知道会不会,啊哈哈哈

​ 看了题解发现挺简单的吧,比D要简单

​ 就是能构成三角形的只有三个相同边。或者是俩大一小(三个不同,俩小一大都可以证明不能构成三角形)

​ 然后就是贪心吧,优先俩大一小,然后三边相同

题目代码:

MY:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAX = 1000010;
const int INF = 0xfffffff;//268435455,2e8;
const int EPS = 0.0000001;
const int MOD = 1e9+7;
int T,N,M;
//std::ios::sync_with_stdio(false);
/*-------------------------------------------------------*/


/* --------------------------------------------------------------*/


int main()
{
cin >> N;
LL ans = 0;
LL surplus = 0;
while(N--)
{
LL x;
cin >> x;
if(x >= 2)
{
if(surplus > 0)
{
LL k = x / 2;
if(k > surplus)
{
ans += surplus;
x -= 2 * surplus;
surplus = 0;
if(x >= 3)
{
ans += x / 3;
surplus += x % 3;
}
else
{
surplus += x;
}
}
else
{
surplus -= k;
ans += k;
if(x % 2 == 1) surplus += 1;
}
}
else
{
ans += x / 3;
surplus += x % 3;
}

}
else
{
surplus += x;
}
}
cout << ans << endl;
return 0;

}

Other:

这个好简洁呀,没那么分类,直接一次通式处理QAQ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1000010;
const int INF = 0xfffffff;//268435455,2e8;
const int EPS = 0.0000001;
const int MOD = 1e9+7;
int T,N,M;
//std::ios::sync_with_stdio(false);
/*-------------------------------------------------------*/

/* --------------------------------------------------------------*/
int main()
{
cin >> N;
LL ans = 0;
LL surplus = 0;
while(N--)
{
LL x;
cin >> x;
LL k;
k = min(surplus,x/2);
ans += k;
surplus -= k;
x -= 2*k;
ans += x / 3;
surplus += x % 3;
}
cout << ans << endl;
return 0;
}
相关文章
评论
分享
  • ECF-70-2

    Educational Codeforces Round 70 (Rated for Div. 2)A.You Are Given Two Binary Strings乘2^k次,其实就是把二进制左移了k位 加法就是对应位加就好了,然...

    ECF-70-2
  • CF-577-2

    Codeforces Round #577 (Div. 2)A.Important Exam问学生分数总和最大为多少 那么就是每道题选的最多的选项为答案,计算即可 B.Zero Array如果sum是奇数的一定不行 如果是偶数的话就看...

    CF-577-2
  • CF-569-2

    吹爆这一场,第一次打到这么前,虽然赛后打得 Codeforces Round #569 (Div. 2)A.Alex and a Rhombus每次增多(i-1)*4个 B.Nick and Array他的操作真正的意思就是,变负数绝...

    CF-569-2
  • CF-576-2

    Codeforces Round #576 (Div. 2)A.City Day啊,爆哭,还想着怎么能优化一下,感觉会超时 结果优化wa了,真好,那就纯暴力 对每一个a,都找到l,r判断区间符不符合条件 注意0天的时候就好 B.Wat...

    CF-576-2
  • ECF-69-2

    Educational Codeforces Round 69 (Rated for Div. 2)A.DIY Wooden Ladder找最长的的俩个,然后看是能放的木板多,还是给的木板多 B.Pillars观察发现这个序列有三种情...

    ECF-69-2
  • CF-575-3

    Codeforces Round #575 (Div. 3)A.Three Piles of Candies傻逼题,一人拿一堆,剩下一堆还能随便分,加起来除2 B.Odd Sum Segments一个序列里只有奇数个奇数时和才是奇数 ...

    CF-575-3
  • CF-574-2

    Codeforces Round #574 (Div. 2)A.Drinks Choosing就把可以凑对的凑在一起,不能的俩俩组合 B.Sport Mafia题目思路:算出全放糖果的sum,算出与留下糖果的差cha 可知,每少放一次...

    CF-574-2
  • CF-571-2

    Codeforces Round #571 (Div. 2)Vus the Cossack and a Contestm,k都不小于n Vus the Cossack and Strings通过观察可以发现当字符串中’1’的数量奇偶相...

    CF-571-2
  • ECF-68-2

    Educational Codeforces Round 68 (Rated for Div. 2)Remove a Progression找到规律,隔一个删一个 Yet Another Crosses Problem这个气死了,存的...

    ECF-68-2
  • CF-559-2(未完待续)

    就学了一个lower把,先放在这里 还要学习读题23333 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748...

    CF-559-2(未完待续)
Please check the parameter of comment in config.yml of hexo-theme-Annie!