当前位置:牛竞技 > 牛竞技网页版 > U.S.男生中50万却被告知彩票印错,女孩在阿妈救

U.S.男生中50万却被告知彩票印错,女孩在阿妈救

文章作者:牛竞技网页版 上传时间:2019-05-12

图片 1围观关切少儿日语微信

图片 2资料图

Problem Statement

In most states, gamblers can choose from a wide variety of different lottery games. The rules of a lottery are defined by two integers (choices and blanks) and two boolean variables (sorted and unique). choices represents the highest valid number that you may use on your lottery ticket. (All integers between 1 and choices, inclusive, are valid and can appear on your ticket.) blanks represents the number of spots on your ticket where numbers can be written.

The sorted and unique variables indicate restrictions on the tickets you can create. If sorted is set to true, then the numbers on your ticket must be written in non-descending order. If sorted is set to false, then the numbers may be written in any order. Likewise, if unique is set to true, then each number you write on your ticket must be distinct. If unique is set to false, then repeats are allowed.

Here are some example lottery tickets, where choices = 15 and blanks = 4:
{3, 7, 12, 14} -- this ticket is unconditionally valid.
{13, 4, 1, 9} -- because the numbers are not in nondescending order, this ticket is valid only if sorted = false.
{8, 8, 8, 15} -- because there are repeated numbers, this ticket is valid only if unique = false.
{11, 6, 2, 6} -- this ticket is valid only if sorted = false and unique = false.

Given a list of lotteries and their corresponding rules, return a list of lottery names sorted by how easy they are to win. The probability that you will win a lottery is equal to (1 / (number of valid lottery tickets for that game)). The easiest lottery to win should appear at the front of the list. Ties should be broken alphabetically (see example 1).

  • 双语:《年代》封面登3周岁男小孩子吃母乳
  • 学习笔记之看《绝望主妇》学克罗地亚共和国语(组图)
  • 双语:duang为何能刚强全网
  • 大不列颠及英格兰联合王国幼园各样孩子都有特地“课程”
  • 双语:各圣上子公主上学第1天(组图)
  • 英壹虚岁男儿童被语言学习机带坏整天飙脏话

If it weren’t for the help of her loving mother, 19-year-old Imari Shelton wouldn’t have even known how to buy a lottery ticket, let alone figure out if she’d won。 But now Shelton is Michigan’s latest million-dollar Powerball winner。

Definition

Class: Lottery
Method: sortByOdds
Parameters: String[]
Returns: String[]
Method signature: String[] sortByOdds(String[] rules)
(be sure your method is public)

图片 3美须眉中50万却被告知彩票印错

密西西比最新一期的强力球彩票开奖,十7虚岁的Hilton成为了流行的百万法郎得主。但假诺未有她阿娘的支援,她以致都不掌握怎么购买彩票,更别说中奖了。

Limits

Time limit (s): 2.000
Memory limit (MB): 64

A New Mexico man has spoken of his anger after buying what appeared to be a winning lottery ticket worth more than $500,000 - only for officials to claim it was a misprint and refuse to honor it.

“When I saw the jackpot had climbed so high, I decided I should take a chance and play,” said Shelton, according to a Monday press release from Michigan Lottery Connect。 “I wasn’t even sure how to play, so I had to ask my mom for help。”

Constraints

  • rules will contain between 0 and 50 elements, inclusive.
  • Each element of rules will contain between 11 and 50 characters, inclusive.
  • Each element of rules will be in the format "<NAME>:<CHOICES><BLANKS><SORTED><UNIQUE>" (quotes for clarity). The underscore character represents exactly one space. The string will have no leading or trailing spaces.
  • <NAME> will contain between 1 and 40 characters, inclusive, and will consist of only uppercase letters ('A'-'Z') and spaces (' '), with no leading or trailing spaces.
  • <CHOICES> will be an integer between 10 and 100, inclusive, with no leading zeroes.
  • <BLANKS> will be an integer between 1 and 8, inclusive, with no leading zeroes.
  • <SORTED> will be either 'T' (true) or 'F' (false).
  • <UNIQUE> will be either 'T' (true) or 'F' (false).
  • No two elements in rules will have the same name.

美利哥新墨西哥州一名男子买了一张彩票并且中了50多万日元,可结果却是兑奖方说那张彩票印错了,拒绝为其兑换。

“当自家见状头奖升到这么高的时候,作者说了算尝试一下,”希尔顿周1在马萨诸塞彩票中央的消息公布会上说,“可自己连怎么玩都不晓得,所以本人必须向本人阿妈求助。”

Examples

0)
{"PICK ANY TWO: 10 2 F F"
,"PICK TWO IN ORDER: 10 2 T F"
,"PICK TWO DIFFERENT: 10 2 F T"
,"PICK TWO LIMITED: 10 2 T T"}

Returns: 
{ "PICK TWO LIMITED",
  "PICK TWO IN ORDER",
  "PICK TWO DIFFERENT",
  "PICK ANY TWO" }

The "PICK ANY TWO" game lets either blank be a number from 1 to 10. Therefore, there are 10 * 10 = 100 possible tickets, and your odds of winning are 1/100.
The "PICK TWO IN ORDER" game means that the first number cannot be greater than the second number. This eliminates 45 possible tickets, leaving us with 55 valid ones. The odds of winning are 1/55.
The "PICK TWO DIFFERENT" game only disallows tickets where the first and second numbers are the same. There are 10 such tickets, leaving the odds of winning at 1/90.
Finally, the "PICK TWO LIMITED" game disallows an additional 10 tickets from the 45 disallowed in "PICK TWO IN ORDER". The odds of winning this game are 1/45.

1)
{"INDIGO: 93 8 T F",
 "ORANGE: 29 8 F T",
 "VIOLET: 76 6 F F",
 "BLUE: 100 8 T T",
 "RED: 99 8 T T",
 "GREEN: 78 6 F T",
 "YELLOW: 75 6 F F"}

Returns: { "RED",  "ORANGE",  "YELLOW",  "GREEN",  "BLUE",  "INDIGO",  "VIOLET" }

Note that INDIGO and BLUE both have the exact same odds (1/186087894300). BLUE is listed first because it comes before INDIGO alphabetically.

2)
{}

Returns: { }

Empty case

John Wines, who has recently retired, bought the New Mexico Lottery scratcher - featuring the winning numbers '1' and '2' - from a Shell gas station in Roswell, Chaves County, in December。

Shelton then purchased five tickets at a local Speedway store in Holland, Mich。, about five hours before Saturday night’s drawing。 The Powerball payout had reached $900 million by that time, but since she didn’t really expect to win, she went to bed and put it out of her mind。

分析

现已退休的John·瓦恩斯于二零一八年11月在新墨西哥州罗斯韦尔的壳牌加油站买了一张彩票,展现号码上有得奖数字1和二。。

接下来礼拜2晚间在距彩票抽取奖金还有四个钟头的时候,希尔顿在马里温州荷兰王国小镇的贰个高速公路集团中买到了五张奖券。这时彩票的奖金已经高达了9亿英镑,但实际上她并没悟出会真的中奖,所以随后她便上床睡觉,不去想那件事儿了。

(1)例题剖析(以Example 0为例)

(壹)对于“PICK ANY TWO: 10 二 F F”来说,数字不排序可再一次,总共有10 ^ 二种彩票组合。你抽到的那张奖券,获奖可能率是百分之100。

(二)对于"PICK TWO DIFFERENT: 10 ② F T",数字不排序不另行,总共有A(十, 二) = 90种彩票组合。你抽到的那张奖券,获奖可能率是九分之一0。

(3)对于"PICK TWO LIMITED: 十 二 T T",数字非降序不重复(即升序),总共的彩票组合数为C(10, 二) = 4五。
瞩目,这里只是数目上也正是组合数,意义大概有所不相同的。因为C(10, 二)是代表从10个里不分顺序任取四个,举个例子(10,九)和(九,十)是大同小异种组成。而升序排列的话,(10,玖)是不符合需要的,(9,拾)才具算壹种。
由此升序排序只是数额上相当于组合数,意义并区别。

(四)对于"PICK TWO IN O智跑DEMurano: 10 二 T F”,数字非降序可另行。
因为数字可再一次,所以非降序不表示升序。比方(玖,玖)就适合题意,但并不是升序。
原理:设非降序可重新的模拟为Get(n, k),设则Get(n, k) = C(n k - 一, k)。
所以这里共有Get(10,2) = C(十 二 - 壹, 2) = 55种彩票组合。你抽到的那张奖券,获奖可能率是伍分一五。

上边用数字直观说惠氏下Get(n, k) = C(n k - 一, k)的道理。
例1:从整数1~第10中学取五个数,取法为非降序可重新。求总共有个别许种模拟

10 10
9 10
9 9
8 10
8 9
8 8
…… ……

例2:从整数1~1第11中学取八个数,取法为升序(升序表明不可重复)。求总共有些许种模拟

10 11
9 11
9 10
8 11
8 10
8 9
…… ……

注意:
从例一和例二的报表能够观测到,那两种的效仿总的数量是同样的。
例2的效仿数在多少上等于C(1一, 2)
例1的上行下效总量Get(10, 2) = C(1一, 二) = C(10 贰 - 一, 二)

例3:从整数1~三中取多个数,取法为非降序可重新。求总共有些许种模拟

3 3 3
2 3 3
2 2 3
2 2 2
1 3 3
1 2 3
1 2 2
1 1 3
1 1 2
1 1 1

例4:从整数1~4中取八个数,取法为升序(升序表达不可重复)。求总共某些许种模拟

3 4 5
2 4 5
2 3 5
2 3 4
1 4 5
1 3 5
1 3 4
1 2 5
1 2 4
1 2 3

注意:
从例1和例二的报表能够洞察到,那三种的模仿总量是同样的。
例4的效仿在数据上等于C(伍, 三)
例三的上行下效总量Get(三, 三) = C(伍, 3) = C(三 3-一, 三)

As he started scratching, he was stunned to come across two '1s' - both of which were worth $250,000. He later uncovered another '1' ($75) and two further '2s' ($500 and $50 respectively)。

“When I woke up on Sunday, my mom told me that someone who had bought a Powerball ticket at the Speedway had won $1 million,” she said。 “As soon as I heard that, I grabbed my ticket and started checking the numbers。 When I saw I matched five numbers, I started shaking。”

(二)数据类型采取

(一)choices取值范围为[10, 100]
Java语言byte类型的取值范围为[-2 ^ 7, 2 ^ 7 - 1],即[-128, 127]。所以若使用java,choices定义成byte就行。
C 里未有byte类型,只好定义成int型。

(二)blanks的取值范围为[1, 8]
若使用Java,blanks定义为byte类型;
若使用C ,blanks定义为int类型。

(三)彩票组合数totalTickets
choices的最大值为拾0,blanks的最大值为捌,彩票组合数的或是的最大数:从九1九个数里有再一次地取伍个人,有⑩0 ^ 八 = 10 ^ 1陆种组成。

Java中,int类型为4字节,long类型为八字节。int类型的取值范围为[-2 ^ 31, 2 ^ 31 - 1],即[-2147483648, 2147483647],放不下10 ^ 16。
long类型的取值范围为[-2 ^ 63, 2 ^ 63 - 1],即[-9223372036854775808, 9223372036854775807],约为[-2 ^ 19, 2 ^ 19],放得下10 ^ 16。
因而Java中需求把totalTickets定义为long类型。

C 中,int和long都是4字节,放不下10 ^ 16。long long为8 个字节,放得下10 ^ 16。
于是C 中须求把totalTickets定义为long long类型

当他早先刮的时候,瓦恩斯看到号码上有五个一,每种一都能领到二四千0澳元的奖金。他接着刮的时候又刮开了另贰个1(奖金7五英镑),以及三个二(奖金各自是500与50英镑)。

“当自个儿礼拜陆清醒的时候,笔者老妈告诉本身,多个在高速公路公司买强力球彩票的人中了一百万日元,”她说,“听到这几个本身当时抓起作者的票,然后开首对数码。当自己来看有四个号码对上的时候,作者开端激动。”

Java程序

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Lottery {
    public String[] sortByOdds(String[] rules) {
        List<Rule> listOfRules = new ArrayList<Rule>();
        for(String ruleDesc: rules) {
            listOfRules.add(new Rule(ruleDesc));
        }

        // 按正序(升序)排序,会调用Rule的compareTo方法
        Collections.sort(listOfRules);

        // 把排序后的名字放到sortedRules,即是最终所求的结果
        String[] sortedRules = new String[rules.length];
        int i = 0;
        for(Rule rule : listOfRules) {
            sortedRules[i  ] = rule.name;
        }

        return sortedRules;
    }

    // 内部类
    class Rule implements Comparable<Rule> {
        // Java四种访问权限:public, protected, private, default
        // 如果不显式写出,则为default,同一个包内都可以访问
        // 又因为这是个内部类,所以下面的属性只有Lottery才能访问
        String name;
        byte choices;
        byte blanks;
        boolean sorted;         // 是否排序
        boolean unique;         // 是否不重复
        long totalTickets;      // 有多少种票
        double winningOdds;     // 中奖的概率

        // 构造函数
        Rule (String description) {
            String[] nameAndRules = description.split(": ");
            name = nameAndRules[0];
            String[] rules = nameAndRules[1].split(" ");
            choices = (byte)Integer.parseInt(rules[0]);
            blanks = (byte)Integer.parseInt(rules[1]);
            sorted = rules[2].equals("T") ? true : false;
            unique = rules[3].equals("T") ? true : false;
            totalTickets =  getTotalTickets();
            winningOdds = 1.0 / totalTickets;
        }

        // 共有多少种票
        private long getTotalTickets() {
            if(!sorted) {
                if(unique) {
                    return permutation(choices, blanks);
                } else {
                    return (long)Math.pow(choices, blanks);
                }
            } else {
                if(unique) {
                    return combination(choices, blanks);
                } else {
                    return combination(choices   blanks - 1, blanks);
                }
            }
        }

        // 递归求排列数
        private long permutation(int n, int k) {
            if(0 == k) {
                return 1;
            } else {
                return permutation(n, k - 1) * (n - k   1);
            }
        }

        // 递归求组合数
        private long combination(int n, int k) {
            if(0 == k) {
                return 1;
            } else {
                return combination(n, k - 1) * (n - k   1) / k;
            } 
        }

        // 题目要求,赢率大(总票数小)的排在前,赢率小(总票数大)的排在后
        // 相同赢率,按字母升序排列(见例1)
        public int compareTo(Rule that) {
            if(this.totalTickets < that.totalTickets) {
                return -1;
            } else if(this.totalTickets > that.totalTickets) {
                return 1;
            } else {
                return this.name.compareTo(that.name);
            }
        }
    }

    // 测试结果,可不提交到TopCoder Arena中
    public static void main(String[] args) {
        Lottery lot = new Lottery();
        String[] rules ={"PICK ANY TWO: 10 2 F F", 
                        "PICK TWO IN ORDER: 10 2 T F", 
                        "PICK TWO DIFFERENT: 10 2 F T", 
                        "PICK TWO LIMITED: 10 2 T T"};
        // String[] rules = {"INDIGO: 93 8 T F",
                        // "ORANGE: 29 8 F T",
                        // "VIOLET: 76 6 F F",
                        // "BLUE: 100 8 T T",
                        // "RED: 99 8 T T",
                        // "GREEN: 78 6 F T",
                        // "YELLOW: 75 6 F F"};
        // String[] rules = {};
        String[] result = lot.sortByOdds(rules);

        for(int i = 0; i < result.length; i  ) {
            System.out.println(result[i]);
        }
    }
}

运作结果:

图片 4

result.png

先后解释:
(一)这里Rule是个里面类。在Java中,若是3个类只被另贰个类应用,那么能够把那些类定义为另叁个类的内部类。
(二)求排列和组合的算法,能够参见
小儿学算法(7):求排列数和组合数
(三)compareTo方法是Comparable接口提供的唯1办法
(4)因为Lottery中的注释部分应用汉语写,编码格式为UTF-八,所以Windows下要用“javac -encoding UTF-八 Lottery.java”。若用“javac Lottery.java”会报错。

越来越多内容请关切微信公众号

图片 5

wechat.jpg

Assuming that the scratcher's stated maximum prize of $250,000 was wrong, a delighted Mr Wines returned to the gas station to collect his winnings. However, he was told he had not won anything。

“I asked my mom what it meant if I matched five numbers, and she thought I was joking。 After she looked at my ticket with me, we both started screaming。”

那让瓦恩斯还感到新墨西哥州的最高奖金不只是2四千0日元,于是兴冲冲地跑到加油站去兑换本人的大奖。但她被告知她平生什么都没中。

“我问作者阿娘假使中了四个号码意味着什么样,她感到本人在开玩笑。然则当他看了自家的票后,大家俩都从头尖叫。”

Instead, the female cashier explained that the 'winning' numbers were, in fact, double-figure numbers that had seen their right-hand-side numbers omitted as a result of a misprint by the lottery。

Matching five numbers sans the Powerball number wins the ticket holder a $1 million prize。 At this level, there is no cash buyout, and winners are given the full $1 million。 But 25 percent ($250,000) of the winnings are withheld for federal taxes and another 4.25 percent ($42,500) are withheld for state taxes。 That means Shelton takes home just over $700,000。

那边的女收银员解释说那1个所谓的中奖数字只可是是彩票公司一点都不小心印错了,在彩票的动手仍可以收看未有完全印出来的数字。

伍个号码相符意味着彩票持有人得到了一百万韩元的奖金。那一个品级上,未有现金收购,中奖人将收获全套的一百万卢比。可是联邦将从奖金中扣二5%(二伍仟0美金)的税,州政坛还将从中扣除四.2五%(42500美元)的税。那代表希尔顿只好带回家七十多万加元。

'I took it back in and she told me that is not a winner,' Mr WInes told KOB 4 News. 'They told me that it was a misprint and they don't pay off for misprints.'

So what will she do with all that cash?

瓦恩斯说:“笔者把彩票拿去兑奖的时候,她告诉小编小编不是中奖者。他们说那只是是印错了,他们不会落到实处印错了的彩票。”

那正是说他将会用这笔钱来做如何吗?

Indeed, if you look closely at Mr Wines's ticket, you can see part of several numbers that are supposed to be next to the 1s and 2s. However, it is unclear what figures they are meant to be。

“I am a student working and eventually want to earn a law degree and become a lawyer,” said Shelton。 “This money will help make that dream a reality for me。”

实在,假诺条分缕析看瓦恩斯先生的彩票,能见到一和二边沿如同应该还有数字。可是看不清那几个数字原本应该是何许。

“作者是一名上学的小孩子,正在上学并愿意最终能够获得农学学位,然后改成一名律师,”希尔顿说,“那笔钱将帮扶小编实现自己的冀望。”

(沪江塞尔维亚共和国语)

But she’s also going to put a little aside to play again。 “Winning $1 million feels unreal, and I don’t know how to describe it, but winning $1.3 billion would be mind-blowing,” she said。

可是她也希图分出来点钱再玩一把。她说:“中了一百万让自家有壹种不安分守己的认为到,小编也不知情怎么形容它,但是假如能够再中十三亿,笔者将会越来越高兴。”

Since no winning tickets were sold for Saturday night’s $949.8 million jackpot, the payout for Wednesday night’s drawing currently stands at a record-setting $1.3 billion, with an $868 million cash value, and that total will doubtless rise before Wednesday’s drawing。

因为未有人获得星期四夜晚949700000欧元的头奖,所以近些日子礼拜陆晚间的奖金已经高达创纪录的壹3亿美金,包罗86七千000美金的新一款价值,而在周天抽取奖品前这些数字鲜明还会上升。

Even though Shelton has already won a million dollars, her chances of winning the $1.3 billion jackpot are just the same as everyone else’s: 1 in 292.2 million。

尽管希尔顿已经收获了一百万比索,然则她得到一3亿头奖的可能率跟别的人却是一样的都是百分之五十92三千00。(评释:本文为爱语吧原创翻译,转发请注解来源,否则追究法律义务!)

本文由牛竞技发布于牛竞技网页版,转载请注明出处:U.S.男生中50万却被告知彩票印错,女孩在阿妈救

关键词: 牛竞技 牛竞技网页版