HDU 2217 Visit

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.