【codeforces 789A】Anastasia and pebbles
【题目链接】: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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 509B】Painting Pebbles
[题目链接]:http://codeforces.com/contest/509/problem/B [题意] 给n鹅卵石染色; 有k种颜色可供选择; 问你有没有染色方案; 使得各个堆的鹅卵石里面,第 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
随机推荐
- 【风马一族_SQL Server】
原文来自:http://www.cnblogs.com/sows/p/6097684.html (博客园的)风马一族 侵犯版本,后果自负 2016-11-24 14:25:45 命令行方式处理服务管 ...
- JQuery--动画队列以及清空队列.stop()方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- RGBA(0,0,0,0)调色
前三个值(红绿蓝)的范围为0到255之间的整数或者0%到100%之间的百分数.这些值描述了红绿蓝三原色在预期色彩中的量. 第四个值,alpha值,制定了色彩的透明度/不透明度,它的范围为0.0到1.0 ...
- 遗传算法MATLAB实现(3):多元函数优化举例
多峰的Shubert为: 求f(x,y)在[-10,10]x[-10,10]上的最大值. MATLAB代码: fun_mutv函数为: function my=fun_mutv(x,y) t1=zer ...
- Directx教程(26) 简单的光照模型(5)
原文:Directx教程(26) 简单的光照模型(5) 在前面的工程中,我们都是在vs中实现顶点光照计算,然后再把顶点颜色传到ps中.本章中我们尝试fragment光照(或者说叫ps光照),在 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- Direct12优化
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- Direct12优化 第一章:向量代数 1.向量计算的时候,使用XMV ...
- 寒哥带你深入了解下Swift中的Value Type
http://www.cocoachina.com/swift/20150923/13539.html 关于开发到底使用ValueType 值类型还是Reference Type 引用类型,关于这个, ...
- 【风马一族_php】NO4_php基础知识
原文来自:http://www.cnblogs.com/sows/p/6017018.html(博客园的)风马一族 侵犯版本,后果自负 回顾 运算符:算术运算符.逻辑运算符.比较运算符.位运算符.赋值 ...
- hdu5289 RMQ+二分
RMQ预处理最大值,最小值,然后对于每一点,二分可能满足的区间长度,长度-1就是该店开始的区间满足的个数. #include<stdio.h> #include<string.h&g ...
- KiCad 安装后没有元件怎么办?
KiCad 安装后没有元件怎么办? 按以下步骤试试. 卸载 KiCad EDA. 按 Win+R 输入 %appdata%/kicad 进入 KiCad 的配置目录. 将里面的内容打包成一个 zip ...