codeforces 789 A. Anastasia and pebbles
链接
题意
这个人有两个口袋,有n种类型的鹅卵石,每种鹅卵石有wi个,每次可以放同一种最多k个,每次不能把不同类型的鹅卵石放进同一个口袋,但是她可以同时把不同种类的鹅卵石放在不同的口袋里,一天只能收集一次,问收集完所有的鹅卵石需要多少天
做法
我们只需要计算出每种类型需要多少次装进袋子里,即 ,然后由于有两个袋子,所以
,考虑到不能整除的情况,所以要对结果向上取整,复杂度O(n)。
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100010;
int main() {
int n,k;
cin>>n>>k;
int w[maxn];
int sum=0;
for(int i=0;i<n;i++){
cin>>w[i];
sum+=w[i]/k+(w[i]%k>0);
}
cout<<(sum/2+(sum%2>0))<<endl;
return 0;
}
codeforces 789 A. Anastasia and pebbles的更多相关文章
- 【codeforces 789A】Anastasia and pebbles
[题目链接]:http://codeforces.com/contest/789/problem/A [题意] 有n种物品,每种物品有wi个; 你有两个口袋,每个口袋最多装k个物品; 且口袋里面只能装 ...
- Codeforces 789A Anastasia and pebbles(数学,思维题)
A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:stan ...
- CF789A. Anastasia and pebbles
/* CF789A. Anastasia and pebbles http://codeforces.com/contest/789/problem/A 水题 题意:有两个背包,每次分别可取k个物品, ...
- 789A Anastasia and pebbles
A. Anastasia and pebbles time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 【贪心】Codeforces Round #407 (Div. 2) A. Anastasia and pebbles
贪心地一个一个尽可能往口袋里放,容易发现和顺序无关. #include<cstdio> #include<iostream> using namespace std; type ...
- Codeforces 789A Anastasia and pebbles( 水 )
链接:传送门 题意:这个人每次都去公园捡石子,她有两个口袋,每个口袋最多装 k 个石子,公园有 n 种石子,每种石子 w[i] 个,询问最少几天能将石子全部捡完 思路:排个序,尽量每天都多装,如果 k ...
- codeforces 789 C. Functions again(dp求区间和最大)
题目链接:http://codeforces.com/contest/789/problem/C 题意:就是给出一个公式 然后给出一串数求一个区间使得f(l,r)最大. 这题需要一个小小的处理 可以设 ...
- codeforces 509 B题 Painting Pebbles
转载地址:http://blog.csdn.net/nike0good/article/details/43449739 B. Painting Pebbles time limit per test ...
- codeforces 789 B. Masha and geometric
链接 B. Masha and geometric depression 题意 给你一个等比数列的首项和公比q,然后给出一个上限l,m个数字,在这个等比数列里,小于l且没有在m个数字里面出现过的可以写 ...
随机推荐
- 2、Linux的关机方式
shutdown 关机指令,你可以man shutdown 来看一下帮助文档.例如你可以运行如下命令关机: shutdown –h 10 ‘This server will shutdown afte ...
- 1 java开发工具IDEA的使用
IntelliJ IDEA 2017.1汉化破解版安装图文教程(附汉化补丁) 注册码:http://idea.lanyus.com/ 点击在线生成 IntelliJ IDEA 2017.1正式版发布 ...
- 利用IO多路复用,使用linux下的EpollSelector实现并发服务器
import socket import selectors # IO多路复用选择器的模块 # 实例化一个和epoll通信的选择器 epoll_selector = selectors.EpollSe ...
- (13)处理静态资源(默认资源映射)【从零开始学Spring Boot】
Spring Boot 默认为我们提供了静态资源处理,使用 WebMvcAutoConfiguration 中的配置各种属性. 建议大家使用Spring Boot的默认配置方式,如果需要特殊处理的再通 ...
- mybatis源码阅读-Transaction和TransactionFactory(四)
Transaction 类图 接口定义 public interface Transaction { Connection getConnection() throws SQLException; v ...
- 孟晓阳:IT运行监控系统设计与使用心得
http://www.cn-healthcare.com/article/20160325/content-482138.html
- ubuntu-kill命令-杀死进程
显示进程pid ps -A 杀进程的命令 kill -s 9 xxx(进程pid)
- JavaFX本地应用自己主动更新功能的实现FXLauncher
JavaFX本地应用自己主动更新功能的实现--FXLauncher 作者:chszs,未经博主同意不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs 一. ...
- Squares-暴力枚举或者二分
B - Squares Time Limit:3500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- eclipse导入myeclipse中的web项目
场景:在myeclipse编写的一个简单的电信计费系统项目,后面公用到eclipse,想把它给导入到eclipse中 操作:eclipse中在packag explorer空白处右键>impor ...