彩票事情又上热搜
本来今天不打算更新闻的了,中午的时候看到「花10万中2.2亿彩票事件调查进展」上热搜。
原以为总算和"融创"来了点不一样的了。

结果调查结果是暂无结果,调查进展是没有进展。
一则报道,没有实际的信息增量,但有广泛的群众记忆和讨论基础。
使得报道发出之后,话题稳坐热搜榜的第二名。

只要能骂能喷,能对外输出情绪,群众从不在意这是新闻还是旧闻,有意义还是没意义。
如果你问我,如何理解彩票事件。
能问出这样的问题,那么大概率你对福利彩票的认识存在较大盲区。
嗯,是盲区,而不是误区。
我这里简单列举一些基本信息:
- 彩票中心的博彩专营权是由国务院给予的,主要目的是通过发售彩票,来增加财政收入
- 目前福利彩票的开奖过程,都是有公证人在场的
- 公证人来自于公证机构,公证机构的公证权是由国家直接下放,即不存在自由经济市场产生的公证企业,必须是国家司法证明机构,才能行使公证权
看到这里,一切正常,逻辑闭环。
也符合普罗大众对彩票事业的理解。
可能大家印象中的细节没有这么足,但结论肯定是大差不差:彩票的公平性由国家直接或间接保证。
但稍微深究就可以发现当中的不合理关系,我补充一些大家可能不知道的信息:
- 公证机构虽然是由国家直接下放公证权,但不属于公务员体系,是自收自支的事业单位
- 开奖过程的公证人在场,并非规定的条例,而是彩票中心为了自身形象,多卖彩票,花钱从公证机构请的。主要作用不得而知,但个人猜想,如果现场有公证人,那么开奖过程中,增加一个公证人宣誓的环节,会在观众心理上增加许多正面作用
现场公证员的拿着背靠国家的公证权,但位于自收自支的事业单位,可能会有对权力进行变现的局部压力,彩票中心作为现场公证人的甲方,可能也会影响公证人员的立场。
这里也有必要声明一下,上述只是基于现有规则进行的动机猜测,不代表事实本身。
任何有独立思考能力的人都会有自己的想法。
但彩票的本质终归不是数学。
搞清楚这些之后,你可能要推翻以前对福利彩票的认识了。
但普通人接受到这些信息之后,可能只够在一段时间内,认识到「彩票不是一个概率游戏」,长期还是会落入「用数量对抗随机性」的不切实际幻想中。
归根到底,是这些利害关系不足以产生画面感。
无法与报道刊登的「xxx 中 xxxx 万元」形成对立效果。
因此,我有必要提供一个具体的场景,断了大家通过彩票致富的念想。
你可以把这游戏看作是一场特殊「剪刀石头布」:赢了得 500w,输了赔 2 元,但永远是对方先出。如果对方一时间头脑发热出错了,他有权判定无效,重开一盘。
好,现在我已经将一个画面深深植入你的脑海。
大概率足够你对现有的体制下的游戏产生免疫效果。
...
回到主线,听说阿里最近在往 Lazada 动手了,那就做一道 Shopee 的题目。
题目描述
平台:LeetCode
题号:556
给你一个正整数 <math xmlns="http://www.w3.org/1998/Math/MathML"> n n </math>n,请你找出符合条件的最小整数,其由重新排列 <math xmlns="http://www.w3.org/1998/Math/MathML"> n n </math>n 中存在的每位数字组成,并且其值大于 <math xmlns="http://www.w3.org/1998/Math/MathML"> n n </math>n。
如果不存在这样的正整数,则返回 <math xmlns="http://www.w3.org/1998/Math/MathML"> − 1 -1 </math>−1 。
注意 ,返回的整数应当是一个 <math xmlns="http://www.w3.org/1998/Math/MathML"> 32 32 </math>32 位整数 ,如果存在满足题意的答案,但不是 <math xmlns="http://www.w3.org/1998/Math/MathML"> 32 32 </math>32 位整数 ,同样返回 <math xmlns="http://www.w3.org/1998/Math/MathML"> − 1 -1 </math>−1。
示例 1:
Java
输入:n = 12
输出:21
示例 2:
Java
输入:n = 21
输出:-1
提示:
- <math xmlns="http://www.w3.org/1998/Math/MathML"> 1 < = n < = 2 31 − 1 1 <= n <= 2^{31} - 1 </math>1<=n<=231−1
模拟
根据题意,只有给定数字 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x 本身从高位到低位是「非严格降序」时,我们无法找到一个合法值。
首先,我们可以先对 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x 诸位取出,存成 nums
数组(数组的首位元素为原数 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x 的最低位)。
然后尝试找到第一个能够交换的位置 idx
(若无法找到,说明不存在合法值,返回 <math xmlns="http://www.w3.org/1998/Math/MathML"> − 1 -1 </math>−1),即从 <math xmlns="http://www.w3.org/1998/Math/MathML"> n u m s [ 0 ] nums[0] </math>nums[0](原始 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x 的最低位)开始找,找到第一个「降序」的位置 idx
,然后从 <math xmlns="http://www.w3.org/1998/Math/MathML"> [ 0 , i d x ) [0, idx) </math>[0,idx) 范围内找一个比 <math xmlns="http://www.w3.org/1998/Math/MathML"> n u m s [ i d x ] nums[idx] </math>nums[idx] 要大的最小数与其进行互换,也是从 <math xmlns="http://www.w3.org/1998/Math/MathML"> n u m s [ 0 ] nums[0] </math>nums[0] 开始找,找到第一个满足比 <math xmlns="http://www.w3.org/1998/Math/MathML"> n u m s [ i d x ] nums[idx] </math>nums[idx] 大的数。
当互换完成后,此时比 <math xmlns="http://www.w3.org/1998/Math/MathML"> x x </math>x 要大这一目标已由第 idx
位所保证(后续的排序应该按照从小到大放置),同时互换结束后的 <math xmlns="http://www.w3.org/1998/Math/MathML"> [ 0 , i d x ) [0, idx) </math>[0,idx) 仍然满足「非严格升序」特性,因此我们可以对其运用「双指针」进行翻转。
Java 代码:
Java
class Solution {
public int nextGreaterElement(int x) {
List<Integer> nums = new ArrayList<>();
while (x != 0) {
nums.add(x % 10);
x /= 10;
}
int n = nums.size(), idx = -1;
for (int i = 0; i < n - 1 && idx == -1; i++) {
if (nums.get(i + 1) < nums.get(i)) idx = i + 1;
}
if (idx == -1) return -1;
for (int i = 0; i < idx; i++) {
if (nums.get(i) > nums.get(idx)) {
swap(nums, i, idx);
break;
}
}
for (int l = 0, r = idx - 1; l < r; l++, r--) swap(nums, l, r);
long ans = 0;
for (int i = n - 1; i >= 0; i--) ans = ans * 10 + nums.get(i);
return ans > Integer.MAX_VALUE ? -1 : (int)ans;
}
void swap(List<Integer> nums, int a, int b) {
int c = nums.get(a);
nums.set(a, nums.get(b));
nums.set(b, c);
}
}
C++ 代码:
C++
class Solution {
public:
int nextGreaterElement(int x) {
vector<int> nums;
while (x != 0) {
nums.push_back(x % 10);
x /= 10;
}
int n = nums.size(), idx = -1;
for (int i = 0; i < n - 1 && idx == -1; i++) {
if (nums[i + 1] < nums[i]) idx = i + 1;
}
if (idx == -1) return -1;
for (int i = 0; i < idx; i++) {
if (nums[i] > nums[idx]) {
swap(nums[i], nums[idx]);
break;
}
}
reverse(nums.begin(), nums.begin() + idx);
long long ans = 0;
for (int i = n - 1; i >= 0; i--) ans = ans * 10 + nums[i];
return ans > INT_MAX ? -1 : static_cast<int>(ans);
}
};
Python 代码:
Python
class Solution:
def nextGreaterElement(self, x: int) -> int:
nums = []
while x != 0:
nums.append(x % 10)
x //= 10
n, idx = len(nums), -1
for i in range(n - 1):
if nums[i + 1] < nums[i]:
idx = i + 1
break
if idx == -1: return -1
for i in range(idx):
if nums[i] > nums[idx]:
nums[i], nums[idx] = nums[idx], nums[i]
break
l, r = 0, idx - 1
while l < r:
nums[l], nums[r] = nums[r], nums[l]
l, r = l + 1, r - 1
ans = 0
for num in nums[::-1]: ans = ans * 10 + num
return -1 if ans > 2**31 - 1 else ans
TypeScript 代码:
TypeScript
function nextGreaterElement(x: number): number {
const nums = [];
while (x !== 0) {
nums.push(x % 10);
x = Math.floor(x / 10);
}
const n = nums.length;
let idx = -1;
for (let i = 0; i < n - 1 && idx == -1; i++) {
if (nums[i + 1] < nums[i]) idx = i + 1;
}
if (idx == -1) return -1;
for (let i = 0; i < idx; i++) {
if (nums[i] > nums[idx]) {
[nums[i], nums[idx]] = [nums[idx], nums[i]];
break;
}
}
for (let l = 0, r = idx - 1; l < r; l++, r--) [nums[l], nums[r]] = [nums[r], nums[l]];
let ans = 0;
for (let i = n - 1; i >= 0; i--) ans = ans * 10 + nums[i];
return ans > 2**31 - 1 ? -1 : ans;
};
- 时间复杂度: <math xmlns="http://www.w3.org/1998/Math/MathML"> O ( log n ) O(\log{n}) </math>O(logn)
- 空间复杂度: <math xmlns="http://www.w3.org/1998/Math/MathML"> O ( log n ) O(\log{n}) </math>O(logn)
我是宫水三叶,每天都会分享算法题解,并和大家聊聊近期的所见所闻。
欢迎关注,明天见。
更多更全更热门的「笔试/面试」相关资料可访问排版精美的 合集新基地 🎉🎉