Codeforces 789A Anastasia and pebbles(数学,思维题)
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time. There are n different pebble types in the park, and there are wi pebbles of the i-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
3 2
2 3 4
3
5 4
3 1 8 9 7
5
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type.
 - In the second day she collects 8 pebbles of the fourth type.
 - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type.
 - In the fourth day she collects 7 pebbles of the fifth type.
 - In the fifth day she collects 1 pebble of the second type.
 
题目链接:http://codeforces.com/contest/789/problem/A
思路:开始用暴力直接搜,然后太复杂了,然后WA了,看了下别人的题解,发现好像有个这样的计算公式:
设每种石子的数量分别为x(用循环来做),每个口袋可以装的石子数为k
计算每种石子装满一个口袋需要的天数sum=(k+x-1)/k(容易看出它这样做是为了向下取整);
每次将天数进行累加,最终得到的天数sum=(sum+1)/2(同样是向上取整);
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k,x;
while(scanf("%d%d",&n,&k)!=EOF)
{
int sum=;
while(n--)
{
scanf("%d",&x);
sum+=(x+k-)/k;
}
printf("%d\n",(sum+)/);
}
return ;
}
Codeforces 789A Anastasia and pebbles(数学,思维题)的更多相关文章
- Codeforces 789A Anastasia and pebbles( 水 )
		
链接:传送门 题意:这个人每次都去公园捡石子,她有两个口袋,每个口袋最多装 k 个石子,公园有 n 种石子,每种石子 w[i] 个,询问最少几天能将石子全部捡完 思路:排个序,尽量每天都多装,如果 k ...
 - PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
		
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
 - 789A Anastasia and pebbles
		
A. Anastasia and pebbles time limit per test 1 second memory limit per test 256 megabytes input stan ...
 - Codeforces 718E - Matvey's Birthday(思维题)
		
Codeforces 题面传送门 & 洛谷题面传送门 首先注意到这个图的特殊性:我们对于所有 \(s_i=s_j\) 的 \((i,j)\) 之间都连了条边,而字符集大小顶多只有 \(8\ ...
 - Codeforces 643F - Bears and Juice(思维题)
		
Codeforces 题目传送门 & 洛谷题目传送门 首先直接暴力枚举显然是不现实的,我们不妨换个角度来处理这个问题,考虑这 \(R_i\) 个瓶子中每一瓶被哪些熊在哪一天喝过. 我们考虑对这 ...
 - Codeforces 627E - Orchestra(双向链表,思维题)
		
Codeforces 题目传送门 & 洛谷题目传送门 下设 \(n,m\) 同阶. 首先有一个傻子都会的暴力做法,枚举矩形的上.下边界 \(l,r\),考虑集合多重集 \(S=\{y|x\in ...
 - 51Nod 1003 阶乘后面0的数量(数学,思维题)
		
1003 阶乘后面0的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720 ...
 - Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
		
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
 - Gym 100801D	Distribution in Metagonia (数学思维题)
		
题目:传送门.(需要下载PDF) 题意:t组数据,每组数据给定一个数ni(1 ≤ ni ≤ 10^18),把ni拆成尽可能多的数,要求每个数的素因子只包含2和3,且这些数不能被彼此整除,输出一共能拆成 ...
 
随机推荐
- 【java】缓冲字符字节输入输出流:java.io.BufferedReader、java.io.BufferedWriter、java.io.BufferedInputStream、java.io.BufferedOutputStream
			
BufferedReader最重要,因为有个方法public String readLine() package System输入输出; import java.io.BufferedReader; ...
 - iOS 实现UIImageView 的不停的旋转(更新:2017.7.26)
			
1.先创建一个UIImageView. - (void)createImageView { UIImageView *imageView = [[UIImageView alloc] initWith ...
 - React:入门计数器
			
---恢复内容开始--- 把React的官网入门例子全看一遍,理解了,但自己从头开始写有点困难,这次强迫自己从头开始写,并写好注释: import React, { Component } from ...
 - Spring之AOP二
			
在Spring之AOP一中使用动态代理将日志打印功能注入到目标对象中,其实这就是AOP实现的原理,不过上面只是Java的实现方式.AOP不管什么语言它的几个主要概念还是有必要了解一下的. 一.AOP概 ...
 - ArcGIS 网络分析[2.2] 服务区分析
			
什么是服务区? 我们先提一个很常见的社会现象:一个医院,如果要发起抢救,那么10分钟内能去多远? 时间就是生命,当结合道路网的阻力进行最短路径分析时,得到的可达的覆盖区域,这个区域就是服务区. 服务区 ...
 - Linux第三节整理 、增删改查、用户管理
			
帮助+基本文件管理+用户管理 1.怎么查看命令帮助 ls --help man ls :查看命令/man 5 file:查看配置文件 2.基本文件管理,通过{查,建,删,改} 四个维度介绍了不同的命令 ...
 - centos7 yum 安装 redis
			
//从中国科学技术大学开源镜像站 wget http://mirrors.ustc.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.r ...
 - spring boot 遇到 supported setting property http://xml.org/sax/properties/lexical-handler
			
解决链接:http://apache-fop.1065347.n5.nabble.com/org-xml-sax-SAXNotSupportedException-thrown-by-FOP-td11 ...
 - 【自问自答】关于 Swift 的几个疑问
			
感觉自己给自己释疑,也是一个极为有趣的过程.这次,我还新增了"猜想"一栏,来尝试回答一些暂时没有足够资料支撑的问题. Swift 版本是:4.0.3.不同版本的 Swift,可能无 ...
 - Maven的下载、安装与环境配置
			
在创建一个项目时,搭建环境往往是编写具体代码的先决条件,而获取到所有需要的jar包是其中的重中之重.起初,人们在需要jar包的时候总会在网上四处查找,而且如果不知道某jar包版本的更迭,写出的代码或许 ...