POJ 3618 Exploration
来源:互联网 发布:无人机图像追踪算法 编辑:程序博客网 时间:2024/05/18 00:02
简单题。。。 但要注意理解题意,每次都从都选离原点最近的未访问过的点走。。
思路: 将-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 ; //新参观的landmark visit[index] = false ; mark1 = mark2 = INT_MAX ; //注意重置 } printf ("%d\n" , ans ) ;}intmain ( ){ 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
- Exploration poj
- POJ 3618 - Exploration 不一样的排序解决办法
- poj 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- poj 2595 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- 细说Android开发环境的搭建
- poj 2752 Seek the Name, Seek the Fame(KMP需转换下思想)
- tslib移植问题
- postgreSQL-安装配置
- cocos2d-x的A*寻路
- POJ 3618 Exploration
- [Android View] 判断是否点中一个动态可旋转、可缩放、可移动的图片
- 字符编码笔记:ASCII,Unicode和UTF-8
- toj3071 Number Game
- join命令
- 子数组最大和问题
- IEEE 802.1d协议
- MySQL中关于日期、时间的数据类型和函数
- 名词王国里的死刑(java 面向对象的思考)