Design Tutorial: Learn from Life
2014-10-06 18:01
274 查看
Codeforces Round #270 B:http://codeforces.com/contest/472/problem/B
题意:n个人在1楼,想要做电梯上楼,只有1个电梯,每次只能运k个人,每移动一层需要1秒。问最小的是时间把所有人送到想去的楼层。
题解:贪心,每次选择楼层数最大k个人,用优先队列维护一下即可。
View Code
题意:n个人在1楼,想要做电梯上楼,只有1个电梯,每次只能运k个人,每移动一层需要1秒。问最小的是时间把所有人送到想去的楼层。
题解:贪心,每次选择楼层数最大k个人,用优先队列维护一下即可。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; const int N=2004; int n,k,temp; int main(){ scanf("%d%d",&n,&k); priority_queue<int>Q; for(int i=1;i<=n;i++){ scanf("%d",&temp); Q.push(temp); } int ans=0,tt=k; while(Q.size()>k){ tt=k; ans+=(Q.top()-1); while(tt--) Q.pop(); } if(Q.size()>0) ans+=(Q.top()-1); printf("%d\n",ans*2); }
View Code
相关文章推荐
- CF 270 B - Design Tutorial: Learn from Life
- Codeforces 472B - Design Tutorial: Learn from Life(模拟)
- codeforces 之 Design Tutorial: Learn from Life
- Codeforces Round #270--B. Design Tutorial: Learn from Life
- Codeforces Round #270--B. Design Tutorial: Learn from Life
- codeforces B. Design Tutorial: Learn from Life
- codeforce 472B. Design Tutorial: Learn from Life
- cf Learn from Life (简单贪心)
- codeforces 472BDesign Tutorial: Learn from Life(简单贪心)
- 472A - Design Tutorial: Learn from Math
- 472A - Design Tutorial: Learn from Math
- codeforces-#472B. Design Tutorial: Learn from Life(贪心)
- What life philosophy do l learn from the process of doing push-up(1)
- 【CodeForces 472A】Design Tutorial: Learn from Math
- cf472B Design Tutorial: Learn from Life
- Codeforces #270 B. Design Tutorial: Learn from Life(数据结构:优先队列模拟题)
- cf472B Design Tutorial: Learn from Life
- 【CODEFORCES】 B. Design Tutorial: Learn from Life
- Codeforces 472B. Design Tutorial: Learn from Life(坐电梯扯淡题)
- B. Design Tutorial: Learn from Life