codeforces B. Design Tutorial: Learn from Life
题意:有一个电梯,每一个人都想乘电梯到达自己想要到达的楼层!
从a层到b层的时间是|a-b|, 乘客上下电梯的时间忽略不计!问最少
需要多少的时间....
这是一道神题啊,自己的思路不知不觉的就按照注解的思路走了,想着
用优先队列模拟一下,可能还是没有模拟好吧,一直哇!但是同学的
优先队列模拟过了! 没想到是greedy算法简单的几行就解决了!
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define N 2005
using namespace std; int f[N]; int main(){
int n, k;
cin>>n>>k;
for(int i=; i<=n; ++i)
cin>>f[i];
sort(f+, f+n+, greater<int>()); int ans = ; for(int i=; i<=n; ){//按照最高的楼层排列,将k个人装满电梯,途中让楼层低的人下去!
ans += (f[i] - )*;//所有的来回时间就是到达楼层搞的时间的2倍
i += k;
}
cout<<ans<<endl;
return ;
}
codeforces B. Design Tutorial: Learn from Life的更多相关文章
- 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 ...
- 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水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)
题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...
- 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 ...
- 【CodeForces 472A】Design Tutorial: Learn from Math
题 题意:给你一个大于等于12的数,要你用两个合数表示出来.//合数指自然数中除了能被1和本身整除外,还能被其他的数整除(不包括0)的数. 分析:我们知道偶数除了2都是合数,给你一个偶数,你减去一个偶 ...
- Design Tutorial: Learn from Life
Codeforces Round #270 B:http://codeforces.com/contest/472/problem/B 题意:n个人在1楼,想要做电梯上楼,只有1个电梯,每次只能运k个 ...
- 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 D. Design Tutorial: Inverse the Problem
题意:给定一个矩阵,表示每两个节点之间的权值距离,问是否可以对应生成一棵树, 使得这棵树中的任意两点之间的距离和矩阵中的对应两点的距离相等! 思路:我们将给定的矩阵看成是一个图,a 到 b会有多条路径 ...
随机推荐
- HTML、XHTML XML和DHTML的区别
XML与HTML的设计区别是:XML是用来存储数据的,重在数据本身.而HTML是用来定义数据的,重在数据的显示模式 XHTML(The Extensible HyperText Markup Lang ...
- mac上安装homebrew
1:关于homebrew下载地址 homebrew下载地址网上版本很多:我用了几个都是显示 404 bad request 如图:均无法现在 有一个网址会给出最新的 安装地址: the URL is: ...
- 【CUDA学习】全局存储器
全局存储器,即普通的显存,整个网格中的任意线程都能读写全局存储器的任意位置. 存取延时为400-600 clock cycles 非常容易成为性能瓶颈. 访问显存时,读取和存储必须对齐,宽度为4By ...
- CoreOS实践(1)—CoreOS初体验
CoreOS主要包含以下一些东西: (1)最小的OS:kernel+systemd (2)使用Docker运行应用 (3)使用fleet管理集群 (4)使用etcd实现服务发现:一个分布式的K/V存储 ...
- ZooKeeper典型应用场景一览
原文地址:http://jm-blog.aliapp.com/?p=1232 ZooKeeper典型应用场景一览 数据发布与订阅(配置中心) 发布与订阅模型,即所谓的配置中心,顾名思义就是发布者将数据 ...
- Apache Storm 的历史及经验教训——Nathan Marz【翻译】
英文原文地址 中英文对照地址 History of Apache Storm and lessons learned --项目创建者 Nathan Marz Apache Storm 最近成为了ASF ...
- 【Theano】安装Theano
http://blog.csdn.net/niuwei22007/article/details/47684673 http://blog.csdn.net/m624197265/article/de ...
- Why restTemplate.put() throws “HttpClientErrorException: 404 Not Found”
I make a put request RestTemplate restTemplate = new RestTemplate(); restTemplate.put(new URI(&quo ...
- .Net事件管道详解图
- Android Studio 经常使用功能介绍
为了简化 Android 的开发力度,Google 决定将重点建设 Android Studio 工具.Google 会在今年年底停止支持其它集成开发环境.比方 Eclipse. Android St ...