题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5493 题目大意: N个人,每个人有一个唯一的高度h,还有一个排名r,表示它前面或后面比它高的人的个数,求按身高字典序最小同时满足排名的身高排列. 题目思路: [线段树] 首先可以知道,一个人前面或后面有r个人比他高,那么他是第r+1高或第n-i-r+1高,i为这个人是第几高的. 所以先将人按照身高从小到大排序,接下来,把当前这个人放在第k=min(r+1,n-i-r+1)高的位置. 用线段树维护包…
按身高排序,每个人前面最高的人数有上限,如果超出上限说明impossible, 每次考虑最小的人,把他放在在当前的从左往右第k+1个空位 因为要求字典序最小,所以每次k和(上限-k)取min值. 没有修改操作,只有删除,可用线段树维护空位数量s,每次类似名次树判断一下第k个空位在哪颗子树上(原来这叫划分树 到达叶子返回位置编号并减少空位数量,push_up的时候维护一下空位数量. #include<bits/stdc++.h> using namespace std; ; struct Nd…
http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2061    Accepted Submission(s): 711 Problem Description Jack likes to travel around the wo…
http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 939    Accepted Submission(s): 520 Problem Description Elves are very peculiar crea…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4031 Problem Description Today is the 10th Annual of “September 11 attacks”, the Al Qaeda is about to attack American again. However, American is protected by a high wall this time, which can be treating…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 738    Accepted Submission(s): 591 Problem Description In Land waterless, w…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间),使得剩余的数最长上升子序列(LIS)最长. 题目思路: [二分][最长上升子序列] 首先,假设去掉[i,i+m-1]这L个数,剩余的LIS长度为max(i左端最后一个不大于a[i+m]的LIS长度+a[i+m]开始到最后的LIS长度). 所以,我们从n到1逆向先求最长下降子序列的长度f[i],就可以知…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5492 题目大意: 一个N*M的矩阵,一个人从(1,1)走到(N,M),每次只能向下或向右走.求(N+M-1)ΣN+M-1(Ai-Aavg)2最小.Aavg为平均值. (N,M<=30,矩阵里的元素0<=C<=30) 题目思路: [动态规划] 首先化简式子,得原式=(N+M-1)ΣN+M-1(Ai2)-(ΣN+M-1Ai)2 f[i][j][k]表示走到A[i][j]格子上,此时前i+j-1…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5491 题目大意: 一个数D(0<=D<231),求比D大的第一个满足:二进制下1个个数在[s1,s2]范围内.D已经满足[s1,s2]. 题目思路: [贪心][模拟] 首先将这个数转成二进制统计总共1的个数s,再求出末尾连续0和1的个数n0,n1. 如果最后一位是0: s=s2,那么为了保证s<s2且答案>D,先设ans=d+lowbit(d),此时满足了新的s<s2且答案&g…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5455 Fang Fang Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 233    Accepted Submission(s): 110 Problem Description Fang Fang says she wants to be…