816-Ambiguous Coordinates

标签: 算法 数据结构
14人阅读 评论(0) 收藏 举报
分类:

Description:
We had some 2-dimensional coordinates, like “(1, 3)” or “(2, 0.5)”. Then, we removed all commas, decimal points, and spaces, and ended up with the string S. Return a list of strings representing all possibilities for what our original coordinates could have been.

Our original representation never had extraneous zeroes, so we never started with numbers like “00”, “0.0”, “0.00”, “1.0”, “001”, “00.01”, or any other number that can be represented with less digits. Also, a decimal point within a number never occurs without at least one digit occuring before it, so we never started with numbers like “.1”.

The final answer list can be returned in any order. Also note that all coordinates in the final answer have exactly one space between them (occurring after the comma.)


Example 1:
Input: "(123)"
Output: ["(1, 23)", "(12, 3)", "(1.2, 3)", "(1, 2.3)"]

Example 2:
Input: "(00011)"
Output:  ["(0.001, 1)", "(0, 0.011)"]
Explanation: 
0.0, 00, 0001 or 00.01 are not allowed.

Example 3:
Input: "(0123)"
Output: ["(0, 123)", "(0, 12.3)", "(0, 1.23)", "(0.1, 23)", "(0.1, 2.3)", "(0.12, 3)"]

Example 4:
Input: "(100)"
Output: [(10, 0)]
Explanation: 
1.0 is not allowed.

Note:

  • 4 <= S.length <= 12.
  • S[0] = “(“, S[S.length - 1] = “)”, and the other elements in S are digits.

问题描述

二维坐标,形如”(1, 3)”或者”(2, 0.5)”,我们将逗号,小数点,以及空白符移除后得到字符串S。

返回字符串列表,代表我们原本的二维坐标的所有可能性。

原来的表示形式不会有额外的0,所以不会以类似”00”, “0.0”, “0.00”开头或者所有本可以用更少数字表示的数。另外,小数点前至少有一个数,因此绝不会出现”.1”

答案可以由任意次序返回。注意,在逗号之后,坐标间有一个空格


问题分析

将字符串分为两端,分别处理

若S = “”,返回空
若S = “0”, 返回”0”
若形如”0xxx0”,则返回空
若形如”0xxx”,则返回”0.xxx”
若形如”xxx0”,则返回”xxx0”
返回”x.xxx,”xx.x”

最后将两边字符串得到的列表作笛卡尔集


解法

class Solution {
    public List<String> ambiguousCoordinates(String S) {
        int n = S.length();
        List<String> res = new ArrayList();
        for (int i = 1; i < n - 2; ++i) {
            List<String> A = f(S.substring(1, i + 1)), B = f(S.substring(i + 1, n - 1));
            for (String a : A) for (String b : B) res.add("(" + a + ", " + b + ")");
        }
        return res;
    }
    public List<String> f(String S) {
        int n = S.length();
        List<String> res = new ArrayList();

        if (n == 0 || (n > 1 && S.charAt(0) == '0' && S.charAt(n - 1) == '0')) return res;

        if (n > 1 && S.charAt(0) == '0') {
            res.add("0." + S.substring(1));
            return res;
        }

        res.add(S);

        if (n == 1 || S.charAt(n - 1) == '0') return res;

        for (int i = 1; i < n; ++i) res.add(S.substring(0, i) + '.' + S.substring(i));

        return res;
    }
}
查看评论

spatial adjustment工具失败(The coordinates or measures are out of bounds)

将mdb中的featureclass 导出为shapefile
  • xiezhongkai08
  • xiezhongkai08
  • 2017-05-05 21:40:57
  • 372

mean value coordinates

paper source:http://128.148.32.110/courses/cs224/papers/mean_value.pdf expanding proces...
  • seamanj
  • seamanj
  • 2016-03-18 06:45:51
  • 897

[译文]Homogeneous Coordinates---齐次坐标

这篇译文是转载别人的翻译,翻译的很不错。 原译文链接:http://blog.csdn.net/janestar/article/details/44244849 下边的链接是原文章的链接 ...
  • qq_16551373
  • qq_16551373
  • 2017-10-17 15:12:46
  • 431

关于矢量图层校准时的“The Coordinates Or Measures Are Out Of Bounds”的问题

前段时间课题组里有个师姐用CAD结合SketchUp8.0做了个3维园区建模,做的很精细,老板让我把模型导出成ArcGIS能用的数据。由于建模时没有选择投影坐标系,无法用sketchup导出成ArcG...
  • aijingyi
  • aijingyi
  • 2012-05-14 17:06:31
  • 2149

Generalized Barycentric Coordinates in Computer Graphics and 无水印原版pdf

  • 2018年01月18日 21:11
  • 114.87MB
  • 下载

Maven: Maven Coordinates

Maven Coordinates
  • wwq518
  • wwq518
  • 2016-05-05 17:19:31
  • 185

Homogeneous Coordinates(齐次坐标)

OpenGPU原帖 英文原帖 问题: 两条平行线会相交    铁轨在无限远处相交于一点 在欧几里得几何空间里,两条平行线永远都不会相交。但是在投影空间中,如右图中的两条铁轨在地平线处却是会相交...
  • fangchuawei
  • fangchuawei
  • 2015-01-18 23:21:35
  • 1356

Coordinates

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Give you two integers P and Q. Let all divisors of P be X...
  • u012319493
  • u012319493
  • 2016-03-06 19:33:56
  • 230

关于appium+python TouchAction提示错误:The coordinates provided to an interactions operation are invalid

今天做自动化解锁9宫格,发现swipe不能满足需求,于是用TouchAction去实现手势滑动,这里先给出我写的代码: TouchAction(self.driver).press(x=299, y...
  • qqtMJK
  • qqtMJK
  • 2017-09-04 16:22:04
  • 732

Homogeneous Coordinates(齐次坐标学习记录)

转自:http://www.songho.ca/math/homogeneous/homogeneous.htmlHomogeneous CoordinatesProblem: Two paralle...
  • Halsey_
  • Halsey_
  • 2018-03-27 17:08:42
  • 23
    个人资料
    专栏达人 持之以恒
    等级:
    访问量: 2万+
    积分: 6529
    排名: 4582
    博客专栏
    文章存档
    最新评论