【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 ...
随机推荐
- 学习JDK1.8集合源码之--LinkedHashSet
1. LinkedHashSet简介 LinkedHashSet继承自HashSet,故拥有HashSet的全部API,LinkedHashSet内部实现简单,核心参数和方法都继承自HashSet,只 ...
- StringUtils常用方式留存
StringUtils是org.apache.commons.lang下的一个工具包.主要用途从名字可以看出是针对于String的一些操作工具,里面包含的方法非常多,英语水平尚可以的人可以前往它的官方 ...
- [case49]聊聊flink的checkpoint配置
序 本文主要研究下flink的checkpoint配置 实例 StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecut ...
- 2019-10-18-dotnet-修复找不到-System.ServiceProcess-定义
title author date CreateTime categories dotnet 修复找不到 System.ServiceProcess 定义 lindexi 2019-10-18 21: ...
- Hibernate的映射机制是怎样?
Hibernate的映射机制对象关系映射(Object Relation Mapping(ORM))是一种为了解决面向对象与面向关系数据库互不匹配现象的技术,简而言之ORM是通过使用描述对象之间映射的 ...
- vagrant up 时提示错误 cound not open file
根据教程:https://laravel-china.org/docs/laravel-development-environment/5.5/development-environment-wind ...
- docker-ce 安装和卸载
一.按照官网给的安装方法进行Ubuntu16.04 docker-ce 的安装,步骤如下: 1.由于apt官方库里的docker版本可能比较旧,所以先卸载可能存在的旧版本: sudo apt-get ...
- 前端规范1-HTML规范
HTML规范 1代码风格(参1,) 使用Tab字符(四个空格长度) 层级关系太多时尽量写在一行,但保证每行代码不宜过长 例,代码不宜过长 例,尽量写在一行 2命名(参1,) class必须使用小写, ...
- AcWing95. 费解的开关 枚举+位运算
这道题的确比较难想,首先我们知道图比较小,有可能是枚举,那么该如何枚举呢??? 你可以发现,我们只要把第一排定了,并且保证第一排不准动,那么答案就定了 也就是说,我们首先用二进制枚举,枚举第一行需要翻 ...
- 设置select和option的文字居中
select{ width: auto; padding: 0 1%; //左右一定要设置 margin: 0; } option{ text-align:center; }