zoukankan      html  css  js  c++  java
  • HDOJ 3486 Interviewe

    人生中第一次写RMQ。。。。
    一看就知道 RMQ+2分
    但是题目文不对题。。。。不知道到底在问什么东西。。。。
    各种WA,TLE,,RE。。。后就过了
    果然无论错成什么样都可以过的,就是 上层的样例HDOJ 3486 Interviewe - qhn999 - 码代码的猿猿 

    Interviewe

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 3865    Accepted Submission(s): 956


    Problem Description
    YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there are n people coming for the interview. However, YaoYao is so busy that he has no time to interview them by himself. So he decides to select exact m interviewers for this task.
    YaoYao decides to make the interview as follows. First he queues the interviewees according to their coming order. Then he cuts the queue into m segments. The length of each segment isHDOJ 3486 Interviewe - qhn999 - 码代码的猿猿 , which means he ignores the rest interviewees (poor guys because they comes late). Then, each segment is assigned to an interviewer and the interviewer chooses the best one from them as the employee.
    YaoYao’s idea seems to be wonderful, but he meets another problem. He values the ability of the ith arrived interviewee as a number from 0 to 1000. Of course, the better one is, the higher ability value one has. He wants his employees good enough, so the sum of the ability values of his employees must exceed his target k (exceed means strictly large than). On the other hand, he wants to employ as less people as possible because of the high salary nowadays. Could you help him to find the smallest m?
     

    Input
    The input consists of multiple cases.
    In the first line of each case, there are two numbers n and k, indicating the number of the original people and the sum of the ability values of employees YaoYao wants to hire (n≤200000, k≤1000000000). In the second line, there are n numbers v1, v2, …, vn (each number is between 0 and 1000), indicating the ability value of each arrived interviewee respectively.
    The input ends up with two negative numbers, which should not be processed as a case.
     

    Output
    For each test case, print only one number indicating the smallest m you can find. If you can’t find any, output -1 instead.
     

    Sample Input
    11 300
    7 100 7 101 100 100 9 100 100 110 110
    -1 -1
     

    Sample Output
    3
    Hint
    We need 3 interviewers to help YaoYao. The first one interviews people from 1 to 3, the second interviews people from 4 to 6, and the third interviews people from 7 to 9. And the people left will be ignored. And the total value you can get is 100+101+100=301>300.
     

    Source
     

    Recommend
    zhengfeng
     



    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    int n,k;
    int m;
    int v[200020];
    int dp[200020][33];
    int ans=-1;

    void RMQ_init()
    {
        for(int i=1;i<=n;i++) dp[0]=v;
        for(int j=1;(1<<j)<=n;j++)
        {
            for(int i=1;i+(1<<j)-1<=n;i++)
            {
                int m=i+(1<<(j-1));
                dp[j]=max(dp[j-1],dp
    [j-1]);
            }
        }
    }

    int RMQ(int L,int R)
    {
        int k=0;
        while((1<<(k+1))<=R-L+1) k++;
        return max(dp[L][k],dp[R-(1<<k)+1][k]);
    }

    int isOK(int m)
    {
        int sum=0;
        int len=n/m;
        for(int i=1;i<=m;i++)
        {
            sum+=RMQ(len*(i-1)+1,i*len);
         //   if(sum>k) ans=i/m;
     //       cout<<"("<<i<<","<<i+m-1<<")     ";
        }
     //   cout<<"---->"<<sum<<endl;
        if(sum>k) return 1;
        else return 0;
    }

    int main()
    {
    while(cin>>n>>k)
    {
        ans=-1;
        if(n<0&&k<0) break;
        memset(v,0,sizeof(v));
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
            cin>>v;
        int mi=1;
        int ma=n;
        RMQ_init();
        while(mi<=ma)
        {
     //       cout<<mi<<","<<ma<<"=:";
            int md=mi+(ma-mi)/2;
     //       cout<<isOK(md)<<endl;
            if(isOK(md))
            {
                ans=md;
                ma=md-1;
            }
            else
            {
                mi=md+1;
            }
        }
        cout<<ans<<endl;
    /*
       for(int i=0;i<=n+1;i++)
       {
           for(int j=0;(1<<j)<=n;j++)
            cout<<dp[j]<<" ";
           cout<<endl;
       }

       int a,b;
       while(cin>>a>>b)
       {
           cout<<RMQ(a,b)<<endl;
       }
    */
    }

        return 0;
    }


  • 相关阅读:
    【剑指offer】判断二叉树是否为平衡二叉树
    【剑指offer】数字在排序数组中出现的次数
    八大排序方法汇总(选择排序,插入排序-简单插入排序、shell排序,交换排序-冒泡排序、快速排序、堆排序,归并排序,计数排序)
    约瑟夫环问题-循环链表VS数组
    告别2014,你是否感谢这一年的自己?
    浅谈WEB页面提速(前端向)
    HTML5- Canvas入门(七)
    浅谈WEB安全性(前端向)
    是时候搁置Grunt,耍一耍gulp了
    前端神器avalonJS入门(二)
  • 原文地址:https://www.cnblogs.com/CKboss/p/3351010.html
Copyright © 2011-2022 走看看