GCJ 2015 1A

Problem A. Mushroom Monster

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
7 points
Large input
8 points

Problem

Kaylin loves mushrooms. Put them on her plate and she'll eat them up! In this problem she's eating a plate of mushrooms, and Bartholomew is putting more pieces on her plate.

In this problem, we'll look at how many pieces of mushroom are on her plate at 10-second intervals. Bartholomew could put any non-negative integer number of mushroom pieces down at any time, and the only way they can leave the plate is by being eaten.

Figure out the minimum number of mushrooms that Kaylin could have eaten using two different methods of computation:

  1. Assume Kaylin could eat any number of mushroom pieces at any time.
  2. Assume that, starting with the first time we look at the plate, Kaylin eats mushrooms at a constant rate whenever there are mushrooms on her plate.

For example, if the input is 10 5 15 5:

With the first method, Kaylin must have eaten at least 15 mushroom pieces: first she eats 5, then 10 more are put on her plate, then she eats another 10. There's no way she could have eaten fewer pieces.

With the second method, Kaylin must have eaten at least 25 mushroom pieces. We can determine that she must eat mushrooms at a rate of at least 1 piece per second. She starts with 10 pieces on her plate. In the first 10 seconds, she eats 10 pieces, and 5 more are put on her plate. In the next 5 seconds, she eats 5 pieces, then her plate stays empty for 5 seconds, and then Bartholomew puts 15 more pieces on her plate. Then she eats 10 pieces in the last 10 seconds.

Input

The first line of the input gives the number of test cases, TT test cases follow. Each will consist of one line containing a single integer N, followed by a line containing N space-separated integers mi; the number of mushrooms on Kaylin's plate at the start, and at 10-second intervals.

Output

For each test case, output one line containing "Case #x: y z", where x is the test case number (starting from 1), y is the minimum number of mushrooms Kaylin could have eaten using the first method of computation, and z is the minimum number of mushrooms Kaylin could have eaten using the second method of computation.

Limits

1 ≤ T ≤ 100.

Small dataset

2 ≤ N ≤ 10.
0 ≤ mi ≤ 100.

Large dataset

2 ≤ N ≤ 1000.
0 ≤ mi ≤ 10000.

Sample


Input 
 

Output 
 
4
4
10 5 15 5
2
100 100
8
81 81 81 81 81 81 81 0
6
23 90 40 0 100 9

Case #1: 15 25
Case #2: 0 0
Case #3: 81 567
Case #4: 181 244

水题,给你一些等间隔时间点的蘑菇,求2种吃法至少吃多少蘑菇。

#include <bits/stdc++.h>
using namespace std;
#define prt(k) cerr<<#k" = "<<k<<endl
#define pb push_back
#define MP make_pair
#define fi  first
#define se  second
#define SZ(X) ((int)(X.size()))
const int inf = 0x3f3f3f3f;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef pair<int,int> pii;
template <class T>
void Max(T &a, T b) { a=max(a, b); }
template <class T>
void Min(T &a, T b) { a=min(a, b); }
const int N = 2333;
int a[N];
int main()
{
    freopen("a.in", "r", stdin); freopen("a.out", "w", stdout);
    int n, re,ca=1; cin>>re;
    while (re--)
    {
        cin>>n;
        for (int i=0;i<n;i++) cin>>a[i];
        int ans1 = 0;
        for (int i=0;i<n-1;i++) ans1+=max(0, a[i]-a[i+1]);
        int rate = 0;
        for (int i=0;i<n-1;i++) Max(rate, a[i]-a[i+1]);
        int ans2=0;
        for (int i=0;i<n-1;i++) ans2 += min(rate, a[i]);
        printf("Case #%d: %d %d\n", ca++, ans1, ans2);
    }
}


Problem B. Haircut

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
11 points
Judge's response for last submission: Correct.
Large input
22 points
Judge's response for last submission: Correct.

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, TT 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  M1M2, ...,  MB.

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


Input 
 

Output 
 
3
2 4
10 5
3 12
7 7 7
3 8
4 2 1

Case #1: 1
Case #2: 3
Case #3: 1

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.

可以算出 T 时刻多少人已经得到服务,然后二分就知道我什么时候得到服务,求出排在我前面的人多少人和我同时得到服务,问题就解决了。

#include <bits/stdc++.h>
using namespace std;
#define prt(k) cerr<<#k" = "<<k<<endl
#define pb push_back
#define MP make_pair
#define fi  first
#define se  second
#define SZ(X) ((int)(X.size()))
const int inf = 0x3f3f3f3f;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef pair<int,int> pii;
template <class T>
void Max(T &a, T b) { a=max(a, b); }
template <class T>
void Min(T &a, T b) { a=min(a, b); }
const int N = 2333;
ll a[N];
ll n, m;
ll f(ll T) /// 现在时间是 T ,多少人已经得到服务
{
    if (T < 0) return 0;
    ll ret = 0;
    for (ll i=0;i<n;i++)
        ret += T / a[i] + 1;
    return ret;
}
ll can()  /// 我什么时候得到服务
{
    ll ans = -1;
    ll l = 0, r = 10000ll * m;
    while (l<=r)
    {
        ll mid = (l+r)/2;
        ll t = f(mid);
        if (t < m) {
            l = mid + 1;
        }
        else {
            ans = mid;
            r = mid - 1;
        }
    }
    return ans;
}
int main()
{
    freopen("b.in", "r", stdin); freopen("b.out", "w", stdout);
    ll re,ca=1; cin>>re;
    while (re--)
    {
        cin>>n>>m;
        for (ll i=0;i<n;i++) cin>>a[i];
        ll ans = -1;
        ll T = can(); /// 我什么时候得到服务
        ll t = f(T - 1); /// 多少人比我早得到服务
        ll left = m - t ; /// 排在我前面的人多少人和我同时得到服务

        for (ll i=0;i<n;i++)
        if (T % a[i] == 0)
        {
            left--;
            if (left == 0)
            {
                ans = i ;
                break;
            }
        }
        printf("Case #%lld: %lld\n", ca++, ans+1);
    }
    return 0;
}

C题

http://blog.csdn.net/oilover/article/details/45560057


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值