题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2217

题目解释:起始位置在原点,给你固定的时间,让你左右跑,求在规定的时间内你最多能跑多少个点;

解决本题,一个是要统计经过的点的个数,一个是全局只有一个拐,所以枚举所有的拐点即可解决;

五个小时卡到一组数据上:

8 9

-5 -4 -3 -2 2 2 2 2

答案应该是:8

AC代码:

 #include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int N = ;
const int M = ;
int lefT[N],righT[N];
int LL[M],RR[M];
int main()
{
int n,L,R,T,le,ri,ans,x,y;
while(scanf("%d %d",&n,&T)!=EOF)
{
L =;R=;le =;ri = ;ans = -;
memset(LL,,sizeof(LL));
memset(RR,,sizeof(RR));
for(int i =; i<=n; i++)
{
scanf("%d",&x);
if(x<)
{
x = abs(x);
lefT[L++] = x;
LL[x]++;
}
else
{
righT[R++] = x;
RR[x]++;
}
}
lefT[] = ;
righT[] = ;
sort(lefT+,lefT+L+);
sort(righT+,righT+R+);
//预处理到达当前位置时共找到的点数,仔细退一下就出来了
for(int i = ; i<=T; i++)
{
LL[i] =LL[i-]+LL[i];
RR[i] = RR[i-]+RR[i];
}
//下面是模拟首先向左跑
int xx = ;
while(*lefT[xx]<=T && xx<L)
{
ans = max(ans,LL[lefT[xx]]+RR[T - *lefT[xx]]);
xx++;
}
//下面模拟首先向右跑
xx = ;
while(*righT[xx]<=T && xx<R)
{
ans = max(ans,RR[righT[xx]]+LL[T - *righT[xx]]);
xx++;
}
printf("%d\n",ans);
}
return ;
}
 

hdu 2217 Visit的更多相关文章

  1. 【HDOJ】2217 Visit

    挺好的一道DP. /* 2217 */ #include <iostream> #include <cstdio> #include <cstring> #incl ...

  2. HDU 2217 Data Structure?

    C - Data Structure? Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  3. hdu 4612 Warm up(缩点+树上最长链)

    本来就是自己负责图论,结果水了= = 题目其实很裸,就是求桥的数量,只是要新加上一条边罢了.做法:先缩点.再在树上搜最长链(第一场多校的hdu 4607Park Visit就考了最长链,小样,套个马甲 ...

  4. hdu 4607 Park Visit 求树的直径

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4607 题目大意:给你n个点,n-1条边,将图连成一棵生成树,问你从任意点为起点,走k(k<=n) ...

  5. hdu 4607 Park Visit

    http://acm.hdu.edu.cn/showproblem.php?pid=4607 先求树的直径 方法:两遍bfs ,任选一点 a  求到a点最远的一点b ,然后 求到b点最远点 c 这样 ...

  6. hdu 4607 Park Visit (dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4607 首先如果k小于等于直径长度,那么答案为k−1.如果k大于直径长度,设直径长度为r,那么答案为r− ...

  7. HDU 4607 Park Visit (树的最长链)

    Park Visit Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. 题解报告:hdu 4607 Park Visit(最长链)

    Problem Description Claire and her little friend, ykwd, are travelling in Shevchenko's Park! The par ...

  9. HDU 4607 Park Visit 两次DFS求树直径

    两次DFS求树直径方法见 这里. 这里的直径是指最长链包含的节点个数,而上一题是指最长链的路径权值之和,注意区分. K <= R: ans = K − 1; K > R:   ans = ...

随机推荐

  1. 【强联通分量缩点】【搜索】bzoj2208 [Jsoi2010]连通数

    两次dfs缩点,然后n次dfs暴搜. #include<cstdio> #include<vector> #include<cstring> using names ...

  2. Problem D: 零起点学算法24——判断奇偶数

    #include<stdio.h> int main() { int a; while(scanf("%d",&a)!=EOF) ==) printf(&quo ...

  3. pythonGUI编程用Canvas模拟画板

    代码如下: from tkinter import * import webbrowser root = Tk() w = Canvas(root,width=400,height=200) w.pa ...

  4. iOS开发——随机数的使用

    1).arc4random() 比较精确不需要生成随即种子        使用方法 :                  通过arc4random() 获取0到x-1之间的整数的代码如下:       ...

  5. iOS数据库操作(使用FMDB)

    iOS中原生的SQLite API在使用上相当不友好,在使用时,非常不便.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB.PlausibleDatabase.sqlitepers ...

  6. Chrome插件在页面上直接绑定JavaScript事件提示Refused to execute inline event handler because it violates the following Co

    Chrome插件问了安全是不提倡在页面上直接写JavaScript的,如果出现了这个提示,其实也没有什么,同样可以运行. 从Chrome Extenstion V2开始,不允许执行任何inline j ...

  7. How can I create a dump of SQL Server?

    https://blogs.msdn.microsoft.com/askjay/2009/12/29/basic-debugging-concepts-and-setup/ You can creat ...

  8. WCF服务全局统一异常处理机制

    转载:http://www.csframework.com/archive/1/arc-1-20150109-2193.htm 服务端增加WCF服务全局异常处理机制,任一WCF服务或接口方式出现异常, ...

  9. 连接sqlexpress

    sqlexpress在visualstudio安装时可选择安装. 数据源添加 localhost\sqlexpress window身份认证即可.

  10. 【mybatis】mybatis使用java实体中定义的常量,或静态方法

    mybatis使用java实体中定义的常量 示例代码: <select id="findDealerInfo" parameterType="com.pisen.c ...