程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> HDU 5089 Assignment(rmq+二分 或 單調隊列)

HDU 5089 Assignment(rmq+二分 或 單調隊列)

編輯:關於C++

 

Assignment

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 557 Accepted Submission(s): 280



Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to some staffs who were in the same group. In a group, the difference of the ability of any two staff is less than k, and their numbers are continuous. Tom want to know the number of groups like this.
Input In the first line a number T indicates the number of test cases. Then for each case the first line contain 2 numbers n, k (1<=n<=100000, 0 Output For each test,output the number of groups.
Sample Input
2
4 2
3 1 2 4
10 5
0 3 4 5 2 1 6 7 8 9

Sample Output
5
28
HintFirst Sample, the satisfied groups include:[1,1]、[2,2]、[3,3]、[4,4] 、[2,3]  

Author FZUACM
Source 2015 Multi-University Training Contest 1
Recommend We have carefully selected several similar problems for you: 5299 5298 5297 5296 5295

 

 

 

rmq+二分

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;
const int mod=1e9+7;

using namespace std;

#define N 100007

int a[N],n;
int dpmin[N][25],dpmax[N][25];
int k;

inline bool judge(int le,int ri)
{
    int kk=log2((ri-le+1)*1.0);
    int mi=min(dpmin[le][kk],dpmin[ri-(1<>1;
                 if(judge(i,mid))
                 {
                     p=mid;
                     le=mid+1;
                 }
                 else
                    ri=mid-1;
             }
             ans+=p-i+1;
         }
         printf(%I64d
,ans);
    }
    return 0;
}

 

 

單調隊列
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8

using namespace std;
const int mod=1e9+7;

#define INF 0x3f3f3f3f

const int N=100005;

int mique[N],maque[N],mihead,mahead,mitail,matail;
int n,a[N],k;

int pre,now;
__int64 ans;

inline void miinque(int i)
{
    while(mihead=1)
            ans-=(__int64)(prelen+1)*(prelen)/2;
           pre=n-1;
        }

        printf(%I64d
,ans+n);
    }
    return 0;
}


 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved