Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2217
Title Explanation: The starting position at the origin, give you a fixed time, let you run around, ask in the specified time you can run the maximum number of points;
Solve the problem, one is to count the number of points passed, one is the global only one turn, so enumerate all the inflection point can be resolved;
Five-hour card to a set of data:
8 9
-5-4-3-2 2 2 2 2
The answer should be: 8
AC Code:
1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdio>5#include <cmath>6 using namespacestd;7 Const intN = .;8 Const intM =200100;9 intLeft[n],right[n];Ten intLl[m],rr[m]; One intMain () A { - intn,l,r,t,le,ri,ans,x,y; - while(SCANF ("%d%d", &n,&t)! =EOF) the { -L =1; R=1; le =0; ri =0; ans =-1; -memset (LL,0,sizeof(LL)); -memset (RR,0,sizeof(RR)); + for(inti =1; i<=n; i++) - { +scanf"%d",&x); A if(x<0) at { -x =ABS (x); -left[l++] =x; -ll[x]++; - } - Else in { -right[r++] =x; torr[x]++; + } - } theleft[0] =0; *right[0] =0; $Sort (left+1, left+l+1);Panax NotoginsengSort (right+1, right+r+1); - //The number of points that were found when preprocessing arrived at the current position, and a careful retreat would come out. the for(inti =1; i<=t; i++) + { ALl[i] =ll[i-1]+Ll[i]; theRr[i] = rr[i-1]+Rr[i]; + } - //here is the simulation first run to the left $ intxx =0; $ while(2*left[xx]<=t && xx<L) - { -ans = max (Ans,ll[left[xx]]+rr[t-2*Left[xx]]); thexx++; - }Wuyi //The following simulation first run to the right thexx =0; - while(2*right[xx]<=t && xx<R) Wu { -ans = max (Ans,rr[right[xx]]+ll[t-2*Right[xx]]); Aboutxx++; $ } -printf"%d\n", ans); - } - return 0; A}
HDU 2217 Visit