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 & ...
随机推荐
- SoftLayerDebug
- feof()
百度知道 >电脑/网络 >编程语言 >C/C++ feof()这个函数是用来判断指针是否已经到达文件尾部的. 若fp已经指向文件末尾,则feof(fp)函数值为"真&quo ...
- xcode 执行时模拟器不可选的问题
好久没写博客了,上一次是什么时候都想不起来了. 之前总认为脑袋记住了,用过了就能够了,干嘛要写博客,简直浪费时间.事实上没事写写博客优点还是挺多的.这样既能够对自己用过的和学到的东西做一个总结,也能提 ...
- C++入门学习——标准模板库之vector
vector(向量容器),是 C++ 中十分实用一个容器.vector 之所以被觉得是一个容器,是由于它可以像容器一样存放各种类型的对象,简单地说,vector 是一个可以存放随意类型(类型可以是in ...
- Linux各个目录的作用
/binbin是binary的缩写.这个目录沿袭了UNIX系统的结构,存放着使用者最经常使用的命令.例如cp.ls.cat,等等./boot这里存放的是启动Linux时使用的一些核心文件./dev ...
- 网络爬虫(3)--Beautiful页面解析
前面2节中对页面内容的访问都是直接通过标签访问的,这样虽然也可以达到解析页面内容的目的,但是在网页复杂,页面结构发生变化时,爬虫就失效了.为了使爬虫能够更加鲁棒的工作,我们需要学习通过 ...
- Hacker(12)----个人计算机安全防护策略
了解了黑客的常用入侵方法,针对这些方法分别指定对应的防护策略不太现实,因此用户只能掌握个人计算机安全的常见防护策略,以确保计算机处在一个相对安全的环境中.常见个人计算机防护策略有:安装并及时升级杀毒软 ...
- Linux远程登录
Linux远程登录 远程登录 关闭linux的防火墙 /etc/init.d/iptables stop 启动VNC服务器 Vncserver & 然后记住desktop is localho ...
- html中opacity的使用
今天做项目要用到一个层背景透明,层上的内容不透明的效果 结果网上找了半天,没一个靠谱的, 最后倒是被一句话点醒了:纸烧了,纸上面的字也会没了 所以,要设2层遮罩层,看代码: .dialog_1//内容 ...
- IE下使用jquery ajax失效
ie是根据请求的url是不是一样来是否发送请求,对于同一请求,ie只发送一次http请求,得到缓存之后就不再请求,所以同一请求发送多次,但ie实际是不会发送的 在你的第二次请求之前 使用 $.ajax ...