简单题。。。 但要注意理解题意,每次都从都选离原点最近的未访问过的点走。。

思路: 将-100,000 ≤ xi ≤ 100,000范围 转换成 0 ~ 200,000   OFFSET(偏移量) 100000 ,由于我是用bool visit[N]。。。虽然代码有点长。。但跑出来的效率比较高。。

//376K  63MS
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <climits>
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
#define N  200005
#define OFFSET 100000       //作为偏移量
using namespace std ;bool visit[N] ;void Exploration ( const double t )
{double count_time ;count_time = 0 ;int ans ;           //记录参观的景点数ans = 0 ;int index ;index = OFFSET ;while ( count_time <= t ){int mark1 , mark2 ;     //每次从100000向左,右搜索第一个未遍历过的点int i , k ;for (  i = OFFSET , k = OFFSET ; i < N || k >= 0 ; i ++ , k -- ){if ( visit[i] ){mark1 = i ;break ;}if ( visit[k] ){mark2 = k ;break ;}}double dis1 , dis2 ;dis1 = fabs ( (double)OFFSET - (double)mark1 ) ;dis2 = fabs ( (double)OFFSET - (double)mark2 ) ;int min ;if ( dis1 < dis2 ){min = mark1 ;}else{min = mark2 ;}if ( count_time + fabs( (double)min - index ) > t ){break ;}ans ++ ;count_time  += fabs ( (double)min - index ) ;       //记录时间index = min ;                       //新参观的landmarkvisit[index] = false ;mark1 = mark2 = INT_MAX ;               //注意重置}printf ("%d\n" , ans ) ;
}int
main ( )
{double t ;int n ;while ( EOF != scanf ("%lf%d" , & t , & n  ) ){memset ( visit , 0 , sizeof ( visit ) ) ;for ( int i = 1 ; i <= n ; i ++ ){int index ;scanf ("%d" , & index ) ;index += OFFSET ;visit[index] = true ;}Exploration ( t ) ;}return 0 ;
}

POJ 3618 Exploration相关推荐

  1. POJ 3618 - Exploration 不一样的排序解决办法

    Description Bessie is traveling on a road teeming with interesting landmarks. The road is labeled ju ...

  2. POJ Treasure Exploration 【DAG交叉最小路径覆盖】

    传送门:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K To ...

  3. POJ 3618 Best Cow Line(贪心算法)

    Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30454   Accepted: 8126 De ...

  4. 基础省选+NOI 第9部分 网络流

    1.二分图匹配 算法竞赛入门经典训练指南+陈锋+ch5.5_二分图的匹配 算法竞赛入门经典训练指南+陈锋+ch5.5_二分图的匹配_哔哩哔哩_bilibili SWPU-ACM每周算法讲堂-匈牙利算法 ...

  5. 省选+NOI 第四部分 图论

    二分图匹配 算法竞赛入门经典训练指南+陈锋+ch5.5_二分图的匹配 算法竞赛入门经典训练指南+陈锋+ch5.5_二分图的匹配_哔哩哔哩_bilibili SWPU-ACM每周算法讲堂-匈牙利算法 S ...

  6. NOI图论算法:网络流

    网络流 https://www.bilibili.com/video/BV15p4y1C7zW https://www.bilibili.com/video/BV1HE411Y7sM https:// ...

  7. poj 2594 Treasure Exploration

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 6284   Accepted: 2 ...

  8. 【POJ - 2594】Treasure Exploration(floyd传递闭包 + 最小路径覆盖,图论)

    题干: Have you ever read any book about treasure exploration? Have you ever see any film about treasur ...

  9. poj 2594 Treasure Exploration 最小路径覆盖

    题目链接:http://poj.org/problem?id=2594 建图很重要!!! 大致题意: 给出一个由n个顶点m条边组成的有向无环图.求最少可以同时存在多少路径,使得这些路径可以覆盖所有的点 ...

最新文章

  1. rust狗阳玩的什么游戏_微博搜索
  2. 22:00直播|当加班男程序猿 被美女主播~ 捕到后...
  3. 正确的 zip 压缩与解压代码
  4. python科学数据分析_python数据分析-科学计数法
  5. JSP中动态includ与静态includ的区别
  6. request.setAttribute()用法
  7. CCF202112-1 序列查询
  8. linux nginx php7,linux nginx配置php7
  9. vue+webpack+mint-ui 示例 (如何使用mint-ui组件)
  10. ASP.NET MVC - 使用Post, Redirect, Get (PRG)模式
  11. flutter混编ios打包生成ipa文件
  12. MES管理系统这5个模块,可保障板式定制家具的生产需求
  13. vue实现table课程表
  14. 动图gif怎么制作?制作方法你学会了吗?
  15. revel MySQL_Go-Revel:Gorp连接MySQL
  16. linux、ubuntu如何查看网速
  17. FPGA电源设计总结
  18. 2005冬季转会名单-PS
  19. 三星量子计算机,全球首款量子手机来了,某厂商是秀肌肉还是蹭流量?
  20. java导入Excel中数据查重的方法

热门文章

  1. Qt 中获取字体的像素高度和宽度
  2. Butter Knife 黄油刀
  3. 成交量指标OBV详解及应用
  4. 服务器租用和托管有什么不一样
  5. 网页中调用matlab,在C#的Web项目中调用Matlab代码的步骤
  6. asp.net 中计算某月总共有多少天 最后一日是几号。
  7. RPG游戏《黑暗之光》流程介绍与代码分析之(二):角色创建界面的实现
  8. DC/DC电源输入输出要隔离还是要保证短距离回路?
  9. 如何在媒体发布消息,个人怎样往网上发布新闻​
  10. 用acos(-1)求π