cf472B Design Tutorial: Learn from Life
1 second
256 megabytes
standard input
standard output
One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.
Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following way. We have n people standing on the first floor, the i-th person wants to go to the fi-th floor. Unfortunately, there is only one elevator and its capacity equal to k (that is at most k people can use it simultaneously). Initially the elevator is located on the first floor. The elevator needs |a - b| seconds to move from the a-th floor to the b-th floor (we don't count the time the people need to get on and off the elevator).
What is the minimal number of seconds that is needed to transport all the people to the corresponding floors and then return the elevator to the first floor?
The first line contains two integers n and k (1 ≤ n, k ≤ 2000) — the number of people and the maximal capacity of the elevator.
The next line contains n integers: f1, f2, ..., fn (2 ≤ fi ≤ 2000), where fi denotes the target floor of the i-th person.
Output a single integer — the minimal time needed to achieve the goal.
3 2
2 3 4
8
4 2
50 100 50 100
296
10 3
2 2 2 2 2 2 2 2 2 2
8
In first sample, an optimal solution is:
- The elevator takes up person #1 and person #2.
- It goes to the 2nd floor.
- Both people go out of the elevator.
- The elevator goes back to the 1st floor.
- Then the elevator takes up person #3.
- And it goes to the 2nd floor.
- It picks up person #2.
- Then it goes to the 3rd floor.
- Person #2 goes out.
- Then it goes to the 4th floor, where person #3 goes out.
- The elevator goes back to the 1st floor.
n个人坐电梯……第i个人要去第a[i]层。电梯只能同时载m个人,求电梯最少要移动几层
贪心……排序完显然电梯必须要到层数最大的那一层一次,还要下来。那就在这一次取层数尽可能大的m个人。
具体做法就是排序完如果n%m!=0就不断加个层数最小的,然后统计所有i是m的倍数的a[i]
还是比较好yy出来的……但是我比较逗忘记从n层到1层只要n-1层……然后样例1过不去傻傻的调了好久
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
LL n,m,sum;
LL a[100000];
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)a[i]=read()-1;
sort(a+1,a+n+1);
while(n%m!=0)
{
a[++n]=a[1];
}
sort(a+1,a+n+1);
for (int i=m;i<=n;i+=m)
sum+=2*a[i];
printf("%lld\n",sum);
}
cf472B Design Tutorial: Learn from Life的更多相关文章
- 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都是合数,给你一个偶数,你减去一个偶 ...
- Design Tutorial: Learn from Life
Codeforces Round #270 B:http://codeforces.com/contest/472/problem/B 题意:n个人在1楼,想要做电梯上楼,只有1个电梯,每次只能运k个 ...
- codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)
题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...
随机推荐
- 发送cookie
- 初识lucene
lucene的介绍网上有好多,再写一遍可能有点多余了. 使用lucene之前,有一系列的疑问 为什么lucene就比数据库快? 倒排索引是什么,他是怎么做到的 lucene的数据结构是什么样的,cpu ...
- C 本地文件夸网文件Cp操作
1,linux平台C简单实现本地文件cp 码子及运行效果测试
- 计算机程序的思维逻辑 (63) - 实用序列化: JSON/XML/MessagePack
上节,我们介绍了Java中的标准序列化机制,我们提到,它有一些重要的限制,最重要的是不能跨语言,实践中经常使用一些替代方案,比如XML/JSON/MessagePack. Java SDK中对这些格式 ...
- WEB程序会话管理--HttpSession和Cookie
WEB应用的会话管理的原理: 由于WEB应用的请求和响应是基于HTTP的,而HTTP由属于无状态的通信协议,只能记录本次请求的信息,因此服务器不会记住这一次的请求和下一次请求的关系.所以会话管理的原理 ...
- 谷歌Cartographer学习(2)-原理阐述与源码解析
最近终于写完了毕业论文.想仔细研究下Cartographer.无奈自己学识有限,先看下网上大牛的解析,作一个汇总. 一.泡泡机器人原创专栏-cartographer理论及实践浅析 http://mp. ...
- 五分钟读懂UML类图
平时阅读一些远吗分析类文章或是设计应用架构时没少与UML类图打交道.实际上,UML类图中最常用到的元素五分钟就能掌握,下面赶紧来一起认识一下它吧: 一.类的属性的表示方式 在UML类图中,类使用包含类 ...
- 配置数据库连接池,Tomcat6.0 连接池的配置
Tomcat6.0 连接池的配置1.本人当前使用的Tomcat版本为:6.0.20,oracle为稳定的9i版本 2.下文为方便起见,依习惯以%Tomcat_Home%表示Tomcat安装的目录,本人 ...
- 【转】invokeRequired属性和 invoke()方法
C#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它. 此时它将会在内部调用n ...
- hdu4506小明系列故事——师兄帮帮忙 (用二进制,大数高速取余)
Problem Description 小明自从告别了ACM/ICPC之后,就開始潜心研究数学问题了,一则能够为接下来的考研做准备,再者能够借此机会帮助一些同学,尤其是美丽的师妹.这不,班里唯一的女生 ...