题意:有一个电梯,每一个人都想乘电梯到达自己想要到达的楼层!
从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的更多相关文章

  1. 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 ...

  2. cf472B Design Tutorial: Learn from Life

    B. Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes ...

  3. cf472A Design Tutorial: Learn from Math

    A. Design Tutorial: Learn from Math time limit per test 1 second memory limit per test 256 megabytes ...

  4. codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)

    题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...

  5. 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 ...

  6. 【CodeForces 472A】Design Tutorial: Learn from Math

    题 题意:给你一个大于等于12的数,要你用两个合数表示出来.//合数指自然数中除了能被1和本身整除外,还能被其他的数整除(不包括0)的数. 分析:我们知道偶数除了2都是合数,给你一个偶数,你减去一个偶 ...

  7. Design Tutorial: Learn from Life

    Codeforces Round #270 B:http://codeforces.com/contest/472/problem/B 题意:n个人在1楼,想要做电梯上楼,只有1个电梯,每次只能运k个 ...

  8. 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 ...

  9. codeforces D. Design Tutorial: Inverse the Problem

    题意:给定一个矩阵,表示每两个节点之间的权值距离,问是否可以对应生成一棵树, 使得这棵树中的任意两点之间的距离和矩阵中的对应两点的距离相等! 思路:我们将给定的矩阵看成是一个图,a 到 b会有多条路径 ...

随机推荐

  1. curl上传、下载、https登陆

    1.下载 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "ftp://127.0.0.1/downtest.txt"); cur ...

  2. MAT(Memory Analyzer Tool)工具入门介绍(转)

    1.MAT是什么? MAT(Memory Analyzer Tool),一个基于Eclipse的内存分析工具,是一个快速.功能丰富的JAVA heap分析工具,它可以帮助我们查找内存泄漏和减少内存消耗 ...

  3. QQ邮箱的安全问题

    下午同事群里有人提醒,小心欺诈邮件.邮件内容为你的帐户在XX存在异地登录,已经进入了[保护模式],如需解除请点击[解除保护模式] 除了链接之外,其它跟官方的是一模一样,包括标题. 那个链接的地址是:h ...

  4. CMSIS OS None

    /* ---------------------------------------------------------------------- * Copyright (C) 2011 ARM L ...

  5. 什么是automatic variable?

    看代码符号$?搞不清楚是什么?   看代码. $share = Get-WmiObject -Class Win32_Share -ComputerName $Server.name -Credent ...

  6. linux shell 多线程执行程序

    Shell中并没有真正意义的多线程,要实现多线程可以启动多个后端进程,最大程度利用cpu性能. 直接看代码示例吧. (1) 顺序执行的代码 #!/bin/bash date ` do { echo & ...

  7. windows批处理

    1.日期作为变量当做文件名的一部分. C:\Documents and Settings\Simon>echo %date%2008-09-09 星期二 C:\Documents and Set ...

  8. 用eclipse建立servlet工程

    1.打开eclipse,选择[文件]|[新建]|[项目] 2.选择[Tomcat  Project]后单击下一步,输入项目名[TestTomcat],选择下一步,将[Can update contex ...

  9. Jmeter报告优化之New XSL stylesheet

    Jmeter默认的报告展示的信息比较少,如果出错了,不是很方便定位问题.由Jmeter默认报告优化这篇文章可知,其实由.jtl格式转换为.html格式的报告过程中,style文件起了很关键的作用.下面 ...

  10. 【Linux】文件特殊权限 SUID/SGID/Sticky Bit

    linux中除了常见的读(r).写(w).执行(x)权限以外,还有3个特殊的权限,分别是setuid.setgid和stick bit 1.setuid.setgid 先看个实例,查看你的/usr/b ...