Design Tutorial: Learn from Life
Codeforces Round #270 B:http://codeforces.com/contest/472/problem/B
题意:n个人在1楼,想要做电梯上楼,只有1个电梯,每次只能运k个人,每移动一层需要1秒。问最小的是时间把所有人送到想去的楼层。
题解:贪心,每次选择楼层数最大k个人,用优先队列维护一下即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=;
int n,k,temp;
int main(){
scanf("%d%d",&n,&k);
priority_queue<int>Q;
for(int i=;i<=n;i++){
scanf("%d",&temp);
Q.push(temp);
}
int ans=,tt=k;
while(Q.size()>k){
tt=k;
ans+=(Q.top()-);
while(tt--)
Q.pop();
}
if(Q.size()>)
ans+=(Q.top()-);
printf("%d\n",ans*);
}
Design Tutorial: Learn from Life的更多相关文章
- cf472B Design Tutorial: Learn from Life
B. Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes ...
- cf472A Design Tutorial: Learn from Math
A. Design Tutorial: Learn from Math time limit per test 1 second memory limit per test 256 megabytes ...
- Codeforces Round #270--B. Design Tutorial: Learn from Life
Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes in ...
- Codeforces Round #270 A. Design Tutorial: Learn from Math【数论/埃氏筛法】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- A - Design Tutorial: Learn from Math(哥德巴赫猜想)
Problem description One way to create a task is to learn from math. You can generate some random mat ...
- codeforces B. Design Tutorial: Learn from Life
题意:有一个电梯,每一个人都想乘电梯到达自己想要到达的楼层!从a层到b层的时间是|a-b|, 乘客上下电梯的时间忽略不计!问最少需要多少的时间.... 这是一道神题啊,自己的思路不知不觉的就按 ...
- codeforce A. Design Tutorial: Learn from Math
题意:将一个数拆成两个合数的和, 输出这两个数!(这道题做的真是TMD水啊)开始的时候不知道composite numbers是啥意思,看了3遍才看懂.... 看懂之后又想用素数筛选法来做,后来决定单 ...
- 【CodeForces 472A】Design Tutorial: Learn from Math
题 题意:给你一个大于等于12的数,要你用两个合数表示出来.//合数指自然数中除了能被1和本身整除外,还能被其他的数整除(不包括0)的数. 分析:我们知道偶数除了2都是合数,给你一个偶数,你减去一个偶 ...
- codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)
题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...
随机推荐
- Android的几种alert对话框
@Override public void onClick(View v) { switch (v.getId()) { case R.id.d1: AlertDialog.Builder build ...
- dedecms安装步骤
GD支持:PHP设置-PHP扩展-php_gd2 初始化数据体验包:点击下载:或者点击取消 如果是本地安装在数据库的在数据库用户名选择默认的(root),密码为空 主要是如果是基于远程服务器的 ...
- 基于mvc结构的前端页面框架搭建
前端开发一年了,向大家交流下自己实践总结下来的一点点开发心得.人生难免磕磕碰碰,前进的道路很多,在学习工作上我们都得学会如何让自己过的更高效,代码亦是如此. 下面,开始介绍自己总结的前端框架搭建(布局 ...
- 汉诺塔的问题:4个柱子,如果塔的个数变位a,b,c,d四个,现要将n个圆盘从a全部移到d,移动规则不变
四柱汉诺塔问题的求解程序.解题思路:如a,b,c,d四柱. 要把a柱第n个盘移到目标柱子(d柱),先把上层 分两为两部份,上半部份移到b柱,下半部分移到c柱,再把第n盘移到 目标柱子,然后,c柱盘子再 ...
- MongoDB 的分组操作 In C#
C#对mongodb的分组查询操作,主要通过脚本或Aggregate方法来实现,以下通过一些实例作解析: 参考资料:http://www.tuicool.com/articles/2iqUZj h ...
- LaTeX Pdf to Word
用LaTeX写的文稿,生成的pdf,如果要改成word文档,如何是最合适的方式? 查了很多帖子,比较靠谱的一种方式是先将pdf转成rtf格式,再用word打开rtf文件.也有直接从tex文件直接转成d ...
- 数据库E-R模型,数据字典
概述:实体-联系模型(简称E-R模型) 模型结构: E-R模型的构成成分是实体集.属性和联系集,其表示方法如下: (1) 实体集用矩形框表示,矩形框内写上实体名. (2) 实体的属性用椭圆框表示,框内 ...
- How to: Extract files from a compiled setup.exe created by Inno setup
Use innounp.exe to unpack setup.exe created by using Inno setup: for example, unpack all the files w ...
- Java7 switch新特性
在Java7之前,switch只能匹配整数值,和字符:而Java7添加了字符串的匹配特性. 代码如下: package blog; public class Main { public static ...
- 在Mac OS X中使用VIM开发STM32(2)
本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 在我先前的博文⎣在Mac OS X中使用VIM开发STM32(1)⎤中,我们安装完成了MACVIM,这一 ...