【题目链接】: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. Leetcode703.Kth Largest Element in a Stream数据流中的第K大元素

    设计一个找到数据流中第K大元素的类(class).注意是排序后的第K大元素,不是第K个不同的元素. 你的 KthLargest 类需要一个同时接收整数 k 和整数数组nums 的构造器,它包含数据流中 ...

  2. 无线传感网络协议——Smart Mesh IP

    前言: SmartMesh IP 专为实现 IP 兼容性而设计,并基于 6LoWPAN 和 802.15.4e 标准.SmartMesh IP 产品线实现了网络适应性.可靠性和可扩展性水平,并拥有高级 ...

  3. kibana一直弹出来报错?

    1,这个我们需要授权 2.授予安全

  4. fedora下eclipse安装tomcat插件

    首先下载tomcat插件: http://www.eclipsetotale.com/tomcatPlugin.html,下载最新的3.3版本: 由于我的eclipse是通过yum自动安装的,因此ec ...

  5. python 自定义检测缺失值的方法

  6. select标签模拟placeholder属性与一般操作(最重要的是ios某一项被选中的兼容)

    1.为了统一样式,常常要模拟placeholder <select> <option disabled selected hidden>请选择</option> & ...

  7. 常用的Markdown编辑器, markdown导出HTML/PDF/JSON/word

              markdown导出word.             常用的Markdown 编辑器 OSX Atom,setting-->package install,搜package ...

  8. VS中,卸载,移除,删除项目的区别

    不说话,上图.

  9. zabbix3.4.x添加短信报警

    一.修改zabbix_server.conf #vi /etc/zabbix/zabbix_server.conf 去掉注释: ### Option: AlertScriptsPath # Full ...

  10. Java练习 SDUT-3338_计算各种图形的周长(接口与多态)

    计算各种图形的周长(接口与多态) Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 定义接口Shape,定义求周长的方法l ...