【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 ...
随机推荐
- RestController注解下返回到jsp视图页面(转)
这个问题我也遇到过,下面的方法可以试试 蓝萝卜blu @RestController注解下返回到jsp视图页面 spring4.1中添加了@RestController注解很方便,集成了@Respon ...
- python findall函数
- MaxCompute推出面向开发者的专属版本,普惠大数据开发者
3月20号,阿里云正式对外宣布推出MaxCompute产品的新规格-开发者版.MaxCompute开发者版是阿里云大数据计算服务发布的开发者专属版本.区别于原有的按量付费.按CU预付费规格,开发者版是 ...
- Codeforces 414A
题目链接 首先考虑无解的情况: n / 2 > k 或者 n==1 且 k != 0 (因为两个数的最大公约数最小为1) 然后因为有 n / 2 组(把 a[i] 和 a[i+1] 看成一组), ...
- python判断输入日期是该年的第几天
1.输入日期,判断日期是该年度的第几天 iyear = int(input("请输入年:\n")) imonth = int(input("请输入月:\n")) ...
- Nginx教程(五) Nginx配置文件详解 (转)
一. Nginx配置文件nginx.conf中文详解 #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processe ...
- python 同名变量引用
- Leetcode811.Subdomain Visit Count子域名访问计数
一个网站域名,如"discuss.leetcode.com",包含了多个子域名.作为顶级域名,常用的有"com",下一级则有"leetcode.com ...
- 远程安装App到手机
注意: 必须是手机和电脑网络连通正常 1. 手机端安装终端模拟器. 2. 打开终端模拟器执行下面命令(也可以在adb shell中执行): su setprop service.adb.tcp.por ...
- PLAY2.6-SCALA(七) Streaming HTTP response
1.从HTTP1.1开始,服务端为了在single connection下对HTTP请求及响应提供服务,需要在response中提供响应的Content-Length. 默认情况下,不需要显示的指明C ...