Codeforces 472B - Design Tutorial: Learn from Life(模拟)
来源:互联网 发布:账本软件 编辑:程序博客网 时间:2024/05/22 04:45
题意
有一个载重量为K的电梯,有N个人,每个人都有想去的地方,求电梯送他们到站的最少时间。
思路
一开始我想从低到高来载,发现不好搞。
换个思路,先运最高的人,如果还有空的话顺路载一下低一点的人。
不过还是感觉我的思路很low。。。
代码
#include <cstdio>
#include <stack>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <map>
#include <cmath>
#define LL long long
#define lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(arr, num) memset(arr, num, sizeof(arr))
#define PB push_back
#define F first
#define S second
#define ROP freopen("input.txt", "r", stdin);
#define BitCount(x) __builtin_popcount(x)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
using namespace std;
const int MAXN = 2000 + 5;
const int MOD = 20071027;
typedef pair<int, int> pii;
typedef vector<int>::iterator viti;
typedef vector<pii>::iterator vitii;
int num[MAXN];
int main()
{
//ROP;
int n, cap, i, j;
int tmp;
scanf("%d%d", &n, &cap);
for (i = 0; i < n; i++)
{
scanf("%d", &tmp);
num[tmp]++;
}
int cur = cap, ans = 0;
for (i = 2000; i >= 2; i--)
{
while (num[i])
{
if (cur != cap)
{
if (num[i] >= cur)
{
num[i] -= cur;
cur = 0;
}
else
{
cur -= num[i];
num[i] = 0;
}
if (cur == 0) cur = cap;
continue;
}
else if (num[i] >= cur)
{
num[i] -= cur;
cur = 0;
ans += ((i - 1) << 1);
}
else
{
ans += ((i - 1) << 1);
cur -= num[i];
num[i] = 0;
}
if (cur == 0) cur = cap;
}
}
printf("%d\n", ans);
return 0;
}
0 0
- Codeforces 472B - Design Tutorial: Learn from Life(模拟)
- codeforces-#472B. Design Tutorial: Learn from Life(贪心)
- 【CODEFORCES】 B. Design Tutorial: Learn from Life
- Codeforces #270 B. Design Tutorial: Learn from Life(数据结构:优先队列模拟题)
- Codeforces Round #270--B. Design Tutorial: Learn from Life
- codeforces 之 Design Tutorial: Learn from Life
- B. Design Tutorial: Learn from Life
- Codeforces 472B. Design Tutorial: Learn from Life(坐电梯扯淡题)
- codeforce 472B. Design Tutorial: Learn from Life
- CF 270 B - Design Tutorial: Learn from Life
- cf472B Design Tutorial: Learn from Life
- codeforces 472BDesign Tutorial: Learn from Life(简单贪心)
- codeforces 472A. Design Tutorial: Learn from Math
- codeforces-#472A. Design Tutorial: Learn from Math
- codeforces 472A Design Tutorial: Learn from Math
- Codeforces Design Tutorial: Learn from Math
- 472A - Design Tutorial: Learn from Math
- 472A - Design Tutorial: Learn from Math
- apache伪静态配置
- Eclipse Java注释模板设置详解
- 揭秘马斯克26亿美元打造“太空出租车”
- Android使用eclipse开发常用快捷键
- 一个去中心化网络模型
- Codeforces 472B - Design Tutorial: Learn from Life(模拟)
- MYSQL
- 关于ValidatorEnable的工作机制
- 块(复合语句)
- hdu - 5045 - Contest(状态压缩dp)
- MFC_LISTCTRL使用出错总结
- C++ String 操作学习
- 大型网站系统架构的演化
- java+axis2-1.6.2 webservice接口开发