Codeforces Round #270 1002
Codeforces Round #270 1002
B. Design Tutorial: Learn from Life
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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?
Input
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
Output a single integer — the minimal time needed to achieve the goal.
Sample test(s)
Input
3 2
2 3 4
Output
8
Input
4 2
50 100 50 100
Output
296
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; int N,M;
struct node
{
int str;
bool operator < (const node &rhs) const
{
return str>rhs.str;
}
}num[]; int main()
{
scanf("%d%d",&N,&M);
for(int i = ;i<N;i++)
{
scanf("%d",&num[i].str);
}
sort(num,num+N);
int t = N/M;
if(N%M!=) t+=;
//cout<<t<<endl;
int ans = ;
for(int i = ;i<t;i++)
{
ans+=*(num[i*M].str-);
}
printf("%d\n",ans);
return ;
}
Codeforces Round #270 1002的更多相关文章
- Codeforces Round #270 1003
Codeforces Round #270 1003 C. Design Tutorial: Make It Nondeterministic time limit per test 2 second ...
- Codeforces Round #270 1001
Codeforces Round #270 1001 A. Design Tutorial: Learn from Math time limit per test 1 second memory l ...
- Codeforces Round #270 A~D
Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...
- Codeforces Round #270(利用prim算法)
D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 mega ...
- 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题(奇偶法、打表法和Miller_Rabin(这个方法才是重点))
题目链接:http://codeforces.com/contest/472/problem/A 题目: 题意:哥德巴赫猜想是:一个大于2的素数一定可以表示为两个素数的和.此题则是将其修改为:一个大于 ...
- Codeforces Round #270 D Design Tutorial: Inverse the Problem --MST + DFS
题意:给出一个距离矩阵,问是不是一颗正确的带权树. 解法:先按找距离矩阵建一颗最小生成树,因为给出的距离都是最短的点间距离,然后再对每个点跑dfs得出应该的dis[][],再对比dis和原来的mp是否 ...
- Codeforces Round #270 D C B A
谈论最激烈的莫过于D题了! 看过的两种做法不得不ORZ,特别第二种,简直神一样!!!!! 1th:构造最小生成树. 我们提取所有的边出来按边排序,因为每次我们知道边的权值>0, 之后每次把边加入 ...
- Codeforces Round #270
A 题意:给出一个数n,求满足a+b=n,且a+b均为合数的a,b 方法一:可以直接枚举i,n-i,判断a,n-i是否为合数 #include<iostream> #include< ...
随机推荐
- Application.DoEvents()的使用
最近做了一个个人数字图书馆管理系统,因为牵扯到电脑文件的扫描,想做一个实时显示当前扫面文件的功能,就类似于360文件扫描时的效果,本来打算用多线程来实现,但是方法太多没有实现,后来在程序中进行控制,由 ...
- [iOS 视频流开发-获得视频帧处理]
调用视频流所使用框架:<Foundation/Foundation.h> 必须定义的参数: 1.AVCaptureDevice(捕获设备:前置.后置摄像头等) 2.AVCaptureInp ...
- jpa findOne()用法
findOne(Interger id) 如果实体类没有id这个属性的话是会报错的 改别人的代码神烦...
- 批处理(.bat)For命令使用
for命令使用 @echo off REM 打印当前目录里所有子目录的名称 REM for /d %%i in (*) do @echo %%i REM 打印当前目录里所有名字为3个字符的子目录的名称 ...
- Scala类基础
最近在开始学习Scala,本篇文章我们来讲解一下Scala中类的使用 class Counter { var defaultValue = 0 val valValue = 0 private var ...
- WPF中ListBox控件在选择模式(SelectionMode)为Single时仍然出现多个Item被选中的问题
最近在学习WPF过程中使用到了ListBox控件,在使用时遇到下面的奇怪问题: 代码如下: listBox.Items.Add("绘图"); listBox.Items.Add(& ...
- Linux 吃掉我的内存
在Windows下资源管理器查看内存使用的情况,如果使用率达到80%以上,再运行大程序就能感觉到系统不流畅了,因为在内存紧缺的情况下使用交换分区,频繁地从磁盘上换入换出页会极大地影响系统的性能.而当我 ...
- 理解Docker单机容器网络
在” 理解Docker单机容器网络 “一文中,还有一个Docker容器网络的功能尚未提及,那就是Docker容器的端口映射.即将容器的服务端口P’ 绑定到宿主机的端口P上,最终达到一种效果:外部程序通 ...
- 增量式PID简单翻板角度控制
1.研究背景 随着电子技术.信息技术和自动控制理论技术的完善与发展,近来微型处理器在控制方面的应用也越来越多.随之逐渐渗透到我们生活的各个领域.如导弹导航装置,飞机上仪表的控制,网络通讯与数据传输,工 ...
- Java数据结构——队列
//================================================= // File Name : Queue_demo //-------------------- ...