POJ 3618 Exploration
简单题。。。 但要注意理解题意,每次都从都选离原点最近的未访问过的点走。。
思路: 将-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相关推荐
- POJ 3618 - Exploration 不一样的排序解决办法
Description Bessie is traveling on a road teeming with interesting landmarks. The road is labeled ju ...
- POJ Treasure Exploration 【DAG交叉最小路径覆盖】
传送门:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K To ...
- POJ 3618 Best Cow Line(贪心算法)
Best Cow Line Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30454 Accepted: 8126 De ...
- 基础省选+NOI 第9部分 网络流
1.二分图匹配 算法竞赛入门经典训练指南+陈锋+ch5.5_二分图的匹配 算法竞赛入门经典训练指南+陈锋+ch5.5_二分图的匹配_哔哩哔哩_bilibili SWPU-ACM每周算法讲堂-匈牙利算法 ...
- 省选+NOI 第四部分 图论
二分图匹配 算法竞赛入门经典训练指南+陈锋+ch5.5_二分图的匹配 算法竞赛入门经典训练指南+陈锋+ch5.5_二分图的匹配_哔哩哔哩_bilibili SWPU-ACM每周算法讲堂-匈牙利算法 S ...
- NOI图论算法:网络流
网络流 https://www.bilibili.com/video/BV15p4y1C7zW https://www.bilibili.com/video/BV1HE411Y7sM https:// ...
- poj 2594 Treasure Exploration
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6284 Accepted: 2 ...
- 【POJ - 2594】Treasure Exploration(floyd传递闭包 + 最小路径覆盖,图论)
题干: Have you ever read any book about treasure exploration? Have you ever see any film about treasur ...
- poj 2594 Treasure Exploration 最小路径覆盖
题目链接:http://poj.org/problem?id=2594 建图很重要!!! 大致题意: 给出一个由n个顶点m条边组成的有向无环图.求最少可以同时存在多少路径,使得这些路径可以覆盖所有的点 ...
最新文章
- rust狗阳玩的什么游戏_微博搜索
- 22:00直播|当加班男程序猿 被美女主播~ 捕到后...
- 正确的 zip 压缩与解压代码
- python科学数据分析_python数据分析-科学计数法
- JSP中动态includ与静态includ的区别
- request.setAttribute()用法
- CCF202112-1 序列查询
- linux nginx php7,linux nginx配置php7
- vue+webpack+mint-ui 示例 (如何使用mint-ui组件)
- ASP.NET MVC - 使用Post, Redirect, Get (PRG)模式
- flutter混编ios打包生成ipa文件
- MES管理系统这5个模块,可保障板式定制家具的生产需求
- vue实现table课程表
- 动图gif怎么制作?制作方法你学会了吗?
- revel MySQL_Go-Revel:Gorp连接MySQL
- linux、ubuntu如何查看网速
- FPGA电源设计总结
- 2005冬季转会名单-PS
- 三星量子计算机,全球首款量子手机来了,某厂商是秀肌肉还是蹭流量?
- java导入Excel中数据查重的方法