CodeForces - 89A - Robbery

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/sdau20163942/article/details/80343925

题目链接http://codeforces.com/problemset/problem/89/A

题意:有n堆钻石,编号为1~n,钻石个数为a1~an,现要从中拿走一些钻石,但是有警报系统规则入下:警报系统每一分钟检查一次,每次检查结果是紧挨着的的两堆钻石之和,那么n堆钻石可得结果集res12,res23,res34...res(n-1)(n),这里要保证拿钻石过程不会使得前后两次检查所得结果集不同,那么又有m限制每分钟操作次数不超过m次,这里操作分为3种:1.将一个钻石从一堆移动到另一堆;2.将钻石从某堆移动到口袋;3.将钻石从口袋移动到某一堆。总共有时间k分钟问最多能拿多少钻石。

解析:发现只有在钻石堆数为奇数时,执行如下步骤能拿走1颗钻石且警报不会触发:

1.选择某序号为奇数的钻石堆,拿走其中一个钻石

2.将其左侧的2*i堆钻石分组:从左端开始两个一组,对于所有组从左边堆拿1个钻石放到右边堆

3.将其右侧的2*j堆钻石分组:从左端开始两个一组,对于所有组从左边堆拿1个钻石放到右边堆


对于正常情况下,由于执行一次拿步骤需要(n/2)+1次操作,对于

①.m<(n/2+1)时,一颗也没法拿走;

②.m>=(n/2+1),每分钟拿走m/(n/2+1)个,直到拿了k分钟或者在过程中某奇数序号堆钻石数为0时也不能再拿了;

注意:只有一堆时(n=1)警报是不管用的,所以每分钟都可以拿m颗钻石直到拿光或者时间用光

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1e4+5;
ll n,m,k,a[M];
int main()
{
    scanf("%lld%lld%lld",&n,&m,&k);
    ll minV=0x7fffffff;
    for(ll i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        if(i&1)
            minV=min(minV,a[i]);
    }
    if(n==1)
    {
        printf("%lld\n",min(a[1],k*m));
    }else if((n&1)==0)
    {
        printf("0\n");
    }else
    {
        ll tmp=(n>>1)+1;//拿一颗钻石用几次操作
        if(m<tmp)
        {
            printf("0\n");
        }else{
            printf("%lld\n",min(minV,k*(m/tmp)));
        }
    }
    return 0;
}

Robbery

04-24

Inspector Robstop is very angry. Last night, a bank has been robbed and the robber has not been caught. And this happened already for the third time this year, even though he did everything in his power to stop the robber: as quickly as possible, all roads leading out of the city were blocked, making it impossible for the robber to escape. Then, the inspector asked all the people in the city to watch out for the robber, but the only messages he got were of the form ``We don't see him."nBut this time, he has had enough! Inspector Robstop decides to analyze how the robber could have escaped. To do that, he asks you to write a program which takes all the information the inspector could get about the robber in order to find out where the robber has been at which time.nnCoincidentally, the city in which the bank was robbed has a rectangular shape. The roads leaving the city are blocked for a certain period of time t, and during that time, several observations of the form ``The robber isn't in the rectangle Ri at time ti'' are reported. Assuming that the robber can move at most one unit per time step, your program must try to find the exact position of the robber at each time step.nnnInput nnThe input contains the description of several robberies. The first line of each description consists of three numbers W, H, t (1 <= W,H,t <= 100) where W is the width, H the height of the city and t is the time during which the city is locked.nnThe next contains a single integer n (0 <= n <= 100), the number of messages the inspector received. The next n lines (one for each of the messages) consist of five integers ti, Li, Ti, Ri, Bi each. The integer ti is the time at which the observation has been made (1 <= ti <= t), and Li, Ti, Ri, Bi are the left, top, right and bottom respectively of the (rectangular) area which has been observed. (1 <= Li <= Ri <= W, 1 <= Ti <= Bi <= H; the point (1, 1) is the upper left hand corner, and (W, H) is the lower right hand corner of the city.) The messages mean that the robber was not in the given rectangle at time ti.nnThe input is terminated by a test case starting with W = H = t = 0. This case should not be processed.nnnOutput nnFor each robbery, first output the line ``Robbery #k:'', where k is the number of the robbery. Then, there are three possibilities:nnIf it is impossible that the robber is still in the city considering the messages, output the line ``The robber has escaped.''nnIn all other cases, assume that the robber really is in the city. Output one line of the form ``Time step : The robber has been at x,y." for each time step, in which the exact location can be deduced. (x and y are the column resp. row of the robber in time step .) Output these lines ordered by time .nnIf nothing can be deduced, output the line ``Nothing known." and hope that the inspector will not get even more angry.nnOutput a blank line after each processed case.nnnSample Inputnn4 4 5n4n1 1 1 4 3n1 1 1 3 4n4 1 1 3 4n4 4 2 4 4n10 10 3n1n2 1 1 10 10n0 0 0nnnSample OutputnnRobbery #1:nTime step 1: The robber has been at 4,4.nTime step 2: The robber has been at 4,3.nTime step 3: The robber has been at 4,2.nTime step 4: The robber has been at 4,1.nnRobbery #2:nThe robber has escaped.

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试