【问题标题】:Algorithm / working approach to get a random list of data获取随机数据列表的算法/工作方法
【发布时间】:2014-03-31 18:14:25
【问题描述】:

我正在开发一个 android 计划应用程序,但这没关系,问题是算法/方法,所以欢迎您编写 pusdo 代码来回答。

数据是这样的

Place 
=============
Name
lat 
lng
duration
isBookMark
type

Note: There are **only** two type: Shop , Park ,
duration is the time base on hour e.g. 1 => 1hour, 0.5 hour etc.... 
lat lng are the location unit

所以,我想根据以下标准生成一个随机地点列表:

1.) There are 2 duration limit

if short limit, then I need to get exactly 1 Park and some Shop  , based on the hour 3 - 5 is given
if medium limit, I need to get exactly 2 Park and some Shop, based on the hour 6 -8 is given
if long limit, then I need to get exactly 3 Park and some Shop  , based on the hour 9 - 11 is given

2. ) The user can select whether the bookmarked item is higher priority, so it may need to handle bookmark higher priority when select the item. 

3. ) Also, the next place chosen must be the nearest place. You can assume there is already a `calcuateDistanceDiff()` function aviliable 

那么,如何在上述情况下生成一个列表:

我试图简单地喜欢“硬编码”来一一处理持续时间限制,例如 先获得一个 Park,然后通过逐个检查优先级/距离来获得下一个,但应该有一些更明智的方法来创建更通用的“方法”来处理这个问题,以更好的性能和优雅。

感谢您的帮助

【问题讨论】:

    标签: android performance algorithm


    【解决方案1】:

    为什么不在初始化时为每个公园添加几个最近的商店??

    但是你必须改变一些东西来实现类继承:

    class Place {
        string name;
        LatLng latLng
        double dur;
        bool isBookMark;
    }
    class Park extends Place {
        ArrayList<Shop> nearestParks;
    }
    class Shop extends Place {
    }
    

    当您创建商店时,您会查看所有公园,如果足够多,则将其添加到列表中。

    【讨论】:

      猜你喜欢
      • 2018-02-12
      • 2010-12-21
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      相关资源
      最近更新 更多