我不管,这就是水题《2》

有长度为n的街道  有m个人  大家一起捡垃圾

下面有n个整数a[i],表示在第i点有a[i]个垃圾

我们在起点0处 没前进一步需要1秒,一次只能捡一个垃圾并且耗时1秒

问你最快需要多少时间能够捡完

输入:

多实例 n,m (0<n<1000)

下面n个整数表示在i位置有多少个垃圾

输出:

最小的耗时

样例输入:

6 2

1 1 1 1 1 1

6 1

1 1 1 1 1 1

样例输出:

8

12

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 1006
int n,m,a[N],w[N];
int q(int xx)
{
    int mm=m;
    for(int i=1; i<=n; i++)
        a[i]=w[i];
    while(mm--)
    {
        int x=xx;
        int ans=0;
        for(int i=n; i>=1&&x; i--)
        {
            if(a[i]==0) continue;
            if(ans)
            {
                if(a[i]&&x>=a[i])
                {
                    x=x-a[i];
                    a[i]=0;
                }
                else if(a[i])
                {
                    a[i]=a[i]-x;
                    x=0;
                }
            }
            if(!ans)
            {
                if(a[i]&&x>=a[i]+i)
                {
                    x=x-a[i]-i;
                    a[i]=0;
                }
                else if(a[i]&&x>i)
                {
                    a[i]=a[i]-(x-i);
                    x=0;
                }
                ans=1;
            }
        }
    }

    for(int i=1; i<=n; i++)
    {
        if(a[i])
            return 1;
    }
    return 0;
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(int i=1; i<=n; i++)
            scanf("%d",&w[i]);
        int l=1,r=INF;
        while(l<r)
        {
            int mid=(l+r)/2;
            if(q(mid))
                l=mid+1;
            else r=mid;
        }
        printf("%d\n",l);
    }
    return 0;
}
时间: 2024-08-23 02:28:46

我不管,这就是水题《2》的相关文章

我不管,这就是水题《1》

每个人都想要更多的财富,谁都不例外. 输入两个整数n,m,往后是n个整数a[i],表示每个点上的财富为a[i] m表示可以进行m次交换,每两个数交换位置,财富也随之变化 最多进行m次交换,问连续最大的财富为多少 输入: 一个整数T,表示T组实例 (T<100) 每组实例有n,和m (0<n<200)(m<1e9); 然后n个整数 输出: 最多交换m次的最大连续和  占一行 样例 输入 2 10 2 2 -10 2 2 2 2 2 2 -10 2 10 0 2 -10 2 2 2 2

UPC 2959: Caoshen like math 这就是个水题

http://acm.upc.edu.cn/problem.php?id=2959 这就是个水题,之所以要写这个题是感觉很有纪念意义 用力看就是盲……23333333333333333 这个题就是最小交换几次使数组有序,首先想到的竟然是逆序数 但是逆序数是冒泡排序用的,怎么可能最小……!!!! 具体题解是: 先用结构体标记每个元素的位置和内容,然后进行排序 跟原来的数组进行比较,位置不符合,将原数组 元素 跟 本该排好序在这个位置的元素交换 然后 二分查找 结构体数组里面 该 元素 将 坐标更新

poj水题-3062 超级水题的深层理解——代码简化

题目很简单,要求输入什么样输出什么样.以回车结束 这就是我用的C代码 #include <stdio.h> int main (){char p;for(;gets(&p);)puts(&p);return 0;} 使用了代码简化方案,我简化到了75B.有大神简化到31B,真想看看他们的源代码.我估计他们比我个能够了解语言规则. 这里不得不说一本叫<短码之美>的书.介绍了这道题.但我试过了,没用.可能系统升级了吧,必须要求C99. ,还听说不用#include也行,

CodeForces 444C. DZY Loves Physics(枚举+水题)

转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207 题目链接:http://codeforces.com/contest/445/problem/C DZY Loves Physics DZY loves Physics, and he enjoys calculating density. Almost everything has density, even a graph. We define the densi

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b

sdut 2841 Bit Problem (水题)

题目 贴这个题是因为看题解有更简单的方法, 我做的时候是直接算的, 也很简单. 贴一下题解吧: 如果一个整数不等于 0,那么该整数的二进制表示中至少有一位是 1. 这个题结果可以直接输出 x - (x&(x-1)); 因为x-1 之后二进制下,就是最右边的1变成了0, 最右边的1的 右边所有的0变成了1, 不影响最左边. 我的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4

sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst

杭电(hdu)2053 Switch Game 水题

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13113    Accepted Submission(s): 7970 Problem Description There are many lamps in a line. All of them are off at first. A series of o

4.7-4.9补题+水题+高维前缀和

题目链接:51nod 1718 Cos的多项式  [数学] 题解: 2cosx=2cosx 2cos2x=(2cosx)^2-2 2cos3x=(2cosx)^3-3*(2cosx) 数归证明2cos(nx)能表示成关于2cosx的多项式,设为f(n) f(1)=x,f(2)=x^2-2(其中的x就是2cosx) 假设n=1~k时均成立(k>=3) 当n=k+1时 由cos((k+1)x)=cos(kx)cos(x)-sin(kx)sin(x) cos((k-1)x)=cos(kx)cos(x)