【题目链接】:http://codeforces.com/contest/789/problem/A

【题意】



有n种物品,每种物品有wi个;

你有两个口袋,每个口袋最多装k个物品;

且口袋里面只能装同一种物品;

问你最多需要多少天能拿走所有的物品;

这里你每天只拿一次,也就是说你每天只能使用你的两个口袋一次;

下一天又能使用了;

【题解】



贪心即可;

对于每一种物品,如果需要用两个口袋装,就用两个口袋去装;

如果只要一个口袋装,就另外一个口袋装下一种物品



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5+100; int n, k, a[N],ans=0; void in()
{
rei(n), rei(k);
rep1(i, 1, n)
rei(a[i]);
} void get_ans()
{
rep1(i,1,n)
if (a[i]>0)
{
if (a[i] >= 2 * k)
{
if (a[i] % (2 * k) == 0)
ans += a[i] / (2 * k);
else
ans += a[i] / (2 * k);
a[i] %= (2 * k);
} if (a[i] == 0) continue; if (a[i] > k)
{
ans++;
a[i] = 0;
}
else
{
a[i] = 0;
a[i + 1] -= min(k, a[i + 1]);
ans++;
}
}
} bool cmp1(int a, int b)
{
return a > b;
} void o()
{
printf("%d\n", ans);
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
in();//checked
get_ans();//checked
o();//checked
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 789A】Anastasia and pebbles的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 509B】Painting Pebbles

    [题目链接]:http://codeforces.com/contest/509/problem/B [题意] 给n鹅卵石染色; 有k种颜色可供选择; 问你有没有染色方案; 使得各个堆的鹅卵石里面,第 ...

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. vue源码解读-目录结构

    目录结构 ├── scripts ------------------------------- 构建相关的文件,一般情况下我们不需要动│ ├── git-hooks ---------------- ...

  2. python findall函数

  3. [运维]VMware vSphere介绍 标签: 运维 2017-04-21 19:48 532人阅读 评论(17)

    大部分的程序员,应该是使用过vmware workstation的,我们用这款软件来创建虚拟机,满足我们学习或者工作的一些问题,今天介绍的是vmware家的另一款,不算是软件,比软件范围更大,VMwa ...

  4. PHP 中Session 反序列化机制的三种方法

    �php.ini中存在三项配置项: session.save_path="" --设置session的存储路径 session.save_handler=""- ...

  5. CentOS 上MySQL报错Can't connect to local Mysql server through socket '/tmp/mysql.scok' (111)

    好吧,这是最常见的MySQL服务没有打开 那就赶紧去打开啊! 在管理员模式下运行以下语句: /usr/local/mysql/bin/mysqld_safe --user=mysql & 成功 ...

  6. 每天一个linux命令(2): nl命令

    0.学习时间 2014-05-16 1.命令格式 nl [参数] 文件名 (文件名也缺省的情况下, 从标准输入中读入) 2.命令参数 -b t 空行不加行号(默认) -b a  空行也加行号(类似于c ...

  7. NEFU 118 n!后面有多少个0【数论】

    http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=118 求n!后面有多少个0(1<=n<=1000000000) ...

  8. switch范围判断

    <?php function grade($grade){ switch (true) { case $grade>=90: echo 'A'; break; case $grade> ...

  9. 破解fireworks_cs6、phoneshop_cs6、dreamweaver_cs6

    我的Adobe密码是绿尘枫加**0,首字母大写,在我的百度云盘有这三款软件的补丁,这三款软件安装和破解的方式都一样.先下载正常安装好正版软件>正常试用一遍之后,fireworks的补丁装错了文件 ...

  10. MyBatis映射文件的基本功能

    #{}与${}区别 "#{}"使用的是preparedStatement方式预处理,就是使用了占位符来填充数据防止SQL注入. ${}使用的是statement方式进行sql语句的 ...