gcj Round 1A 2015 Haircut
来源:互联网 发布:淘宝上大拿韩代真品吗 编辑:程序博客网 时间:2024/04/30 01:56
Problem B. Haircut
11 points
22 points
Problem
You are waiting in a long line to get a haircut at a trendy barber shop. The shop has Bbarbers on duty, and they are numbered 1 through B. It always takes the kth barber exactly Mk minutes to cut a customer's hair, and a barber can only cut one customer's hair at a time. Once a barber finishes cutting hair, he is immediately free to help another customer.
While the shop is open, the customer at the head of the queue always goes to the lowest-numbered barber who is available. When no barber is available, that customer waits until at least one becomes available.
You are the Nth person in line, and the shop has just opened. Which barber will cut your hair?
Input
The first line of the input gives the number of test cases, T. T test cases follow; each consists of two lines. The first contains two space-separated integers B and N -- the number of barbers and your place in line. The customer at the head of the line is number 1, the next one is number 2, and so on. The second line contains
Output
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the number of the barber who will cut your hair.
Limits
1 ≤ T ≤ 100.
1 ≤ N ≤ 109.
Small dataset
1 ≤ B ≤ 5.
1 ≤ Mk ≤ 25.
Large dataset
1 ≤ B ≤ 1000.
1 ≤ Mk ≤ 100000.
Sample
In Case #1, you are the fourth person in line, and barbers 1 and 2 take 10 and 5 minutes, respectively, to cut hair. When the shop opens, the first customer immediately has the choice of barbers 1 and 2, and she will choose the lowest-numbered barber, 1. The second customer will immediately be served by barber 2. The third customer will wait since there are no more free barbers. After 5 minutes, barber 2 will finish cutting the second customer's hair, and will serve the third customer. After 10 minutes, both barbers 1 and 2 will finish; you are next in line, and you will have the choice of barbers 1 and 2, and will choose 1.
/***********************************************\ |Author: YMC |Created Time: 2015/4/18 9:59:11 |File Name: b.cpp |Description: \***********************************************/#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>#include <algorithm>#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#define L(rt) (rt<<1)#define R(rt) (rt<<1|1)#define mset(l,n) memset(l,n,sizeof(l))#define rep(i,n) for(int i=0;i<n;++i)#define maxx(a) memset(a, 0x3f, sizeof(a))#define zero(a) memset(a, 0, sizeof(a))#define srep(i,n) for(int i = 1;i <= n;i ++)#define MP make_pairconst int inf=0x3f3f3f3f ;const double eps=1e-8 ;const double pi=acos (-1.0);typedef long long ll;using namespace std;ll n,m;ll da[1005];ll t;int cas = 1;priority_queue<pair<ll,int>, vector<pair<ll,int> >, greater<pair<ll,int> > > pq;ll test(ll mid) { ll ans = 0; for(int i=1;i<=n;++i) ans += mid / da[i]; return ans;}ll test2(ll mid) { ll ans = 0; srep(i,n) { if(mid % da[i] == 0) ans += mid/da[i]; else ans += mid/da[i] +1; } return ans;}void solve() { ll l = 0, r = 100000*m; ll mid; ll now; while(l + 1 < r) { mid = (l + r) / 2; now = test2(mid); if(now >= m) r = mid-1; else { l = mid; } } m -= test2(l); while(!pq.empty()) pq.pop(); l ++; srep(i,n) { if(da[i] == 1) { pq.push(MP(0,i)); continue; } if(l % da[i] <= 1) { pq.push(MP(1 - l % da[i],i)); } else { pq.push(MP(da[i] + 1 - l % da[i],i)); } } pair<ll,int> tp; srep(i,m-1) { tp = pq.top(); pq.pop(); tp.first += da[tp.second]; pq.push(tp); } tp = pq.top(); printf("Case #%d: %d\n",cas ++,tp.second);}int main() {freopen("B-large-practice.in","r",stdin); freopen("out.txt","w",stdout); int T; scanf("%d",&T); while(T--) { scanf("%lld %lld",&n,&m); srep(i,n) scanf("%lld",&da[i]); solve(); }return 0;}
- gcj Round 1A 2015 Haircut
- Google Code Jam Round 1A 2015 Problem B. Haircut
- Google Code Jam 2015 Round 1A: Problem B. Haircut
- gcj Round 1A 2015 Mushroom Monster
- 2014 GCJ Round 1A
- GCJ Round 1A 2016
- GCJ 2015 1A
- GCJ Round 1A 2016 C.BFFS
- GCJ Round 1A 2017 题解
- [GCJ] 2011 Round 1A Problem A FreeCell Statistics
- GCJ Round 1A 2008 Problem A. Minimum Scalar Product
- GCJ 2008 Round 1A A - Minimum Scalar Product (贪心)
- GCJ Round 1A 2008 Problem A. Minimum Scalar Product
- GCJ 2008 Round 1A A 排序贪心
- GCJ 2015 Round D
- [GCJ] 2011 Round 1B Problem A RPI
- GCJ Round 1A 2008 Problem C. Numbers
- GCJ 2008 Round 1A Minimum Scalar Product
- JAVA中Iterator的具体作用
- 如何使用npm发布Node.JS程序包
- 【举例1】Docker环境部署过程-以Wordpress个人博客系统搭建为例
- 入学体检
- HTML 5 的自定义 data-* 属性和jquery的data()方法的使用
- gcj Round 1A 2015 Haircut
- UVa10010 - Where's Waldorf?
- HIHO_矩阵快速幂
- TCP和UDP的区别
- 【分享一个SQL函数】在SQL脚本中匹配使用特定分隔符分隔字符串的位置
- 强大的矢量图形库:Raphael JS
- 最长山峰序列
- 关于讯飞语音听写使用过程中出现的问题
- getopt 库的使用