当前位置:网站首页>[acnoi2022] guess numbers
[acnoi2022] guess numbers
2022-07-03 13:56:00 【OneInDark】
subject
Background
“ Ah, here ,” O U Y E \sf OUYE OUYE Suddenly said ,“ Let's be brothers ! That's it. , As an extension of the condition . Because a weak person like me , It's very suspicious not to report to the group for warmth ……”
D D ( X Y X ) \sf DD(XYX) DD(XYX) Quite surprised . He didn't expect things to go so smoothly .
“ Good. , On the way home, drop in and say goodbye !”
“ As long as the inner volume is more than .” O U Y E \sf OUYE OUYE Want to .
“ As long as the red stone is not finished .” D D ( X Y X ) \sf DD(XYX) DD(XYX) Want to .
—— “ Will never be separated !” The two said in unison .
Title Description
Interactive questions . There is one x ∈ [ 10 , 2 64 − 10 ) x\in[10,\;2^{64}{-}10) x∈[10,264−10) Unknown , You guess. . Several intervals can be given each time :
- if x x x In the union of these intervals , Then the interactive library has p = 0.8 p=0.8 p=0.8 Probability return of 1 1 1, Yes ( 1 − p ) (1{-}p) (1−p) Probability return 0 0 0 .
- otherwise , The interactive library must return 0 0 0 .
Please use the least expected number of times to determine x x x .
Data range and tips
Conduct T = 3000 T=3000 T=3000 After the first test , Your average number of inquiries should not exceed 107 107 107 .
Ideas
I hope you have too O U Y E \sf OUYE OUYE The same insight , Enough to see that the key message is The probability that each number will become the answer .
We use it E n t r o p y \rm Entropy Entropy Measure it , The symbol is H H H .—— You don't know information entropy ? Then you certainly haven't seen 3 b 1 b \rm 3b1b 3b1b Teach you to play w o r d l e \rm wordle wordle
Suddenly found that I can't information entropy , I'm a clown .
Definition
H = − ∑ x ∈ U Pr ( x ) log 2 Pr ( x ) H=-\sum_{x\in\Bbb U}\Pr(x)\log_2\Pr(x) H=−x∈U∑Pr(x)log2Pr(x)
among U \Bbb U U It's the sample space . The following is a brief description ω ( x ) = − x log 2 x \omega(x)=-x\log_2 x ω(x)=−xlog2x .
This definition is very consistent with our intuition : be aware ω ( a b ) = b ω ( a ) + a ω ( b ) \omega(ab)=b\omega(a)+a\omega(b) ω(ab)=bω(a)+aω(b), So there is
H = ∑ x ∈ U ω ( Pr [ x ∣ A ] Pr ( A ) ) + ∑ x ∈ U ω ( Pr [ x ∣ ¬ A ] Pr ( ¬ A ) ) = Pr ( A ) H [ A ] + Pr ( ¬ A ) H [ ¬ A ] + ω ( Pr ( A ) ) + ω ( Pr ( ¬ A ) ) \begin{aligned} H&=\sum_{x\in\Bbb U}\omega(\Pr[x\;|\;A]\Pr(A))+\sum_{x\in\Bbb U}\omega(\Pr[x\;|\;\neg A]\Pr(\neg A))\\ &=\Pr(A)H[A]+\Pr(\neg A)H[\neg A]+\omega(\Pr(A))+\omega(\Pr(\neg A)) \end{aligned} H=x∈U∑ω(Pr[x∣A]Pr(A))+x∈U∑ω(Pr[x∣¬A]Pr(¬A))=Pr(A)H[A]+Pr(¬A)H[¬A]+ω(Pr(A))+ω(Pr(¬A))
among H [ A ] H[A] H[A] by A A A Entropy under conditions , namely ∑ x ∈ U ω ( Pr [ x ∣ A ] ) \sum_{x\in\Bbb U}\omega(\Pr[x\;|\;A]) ∑x∈Uω(Pr[x∣A]) .
in other words , use Pr ( A ) \Pr(A) Pr(A) Corresponding entropy ( The amount of information ) know A A A Is it true , Then recurse down .
Consider asking a set T T T Satisfy Pr [ x ∈ T ] = q , H [ x ∈ T ] = h 1 , H [ x ∉ T ] = h 0 \Pr[x\in T]=q,\;H[x\in T]=h_1,\;H[x\notin T]=h_0 Pr[x∈T]=q,H[x∈T]=h1,H[x∈/T]=h0 . After asking :
- Yes p q pq pq The probability of 1 1 1, then Pr [ x ∈ T ] = 1 \Pr[x\in T]=1 Pr[x∈T]=1, New entropy H = h 1 H=h_1 H=h1 .
- Yes ( 1 − p q ) (1-pq) (1−pq) The probability of 0 0 0, By Bayesian formula Pr [ x ∈ T ∣ 0 ] = Pr [ 0 ∣ x ∈ T ] Pr [ x ∈ T ] Pr [ 0 ] = q − p q 1 − p q \Pr[x\in T\;|\;0]=\frac{\Pr[0\;|\;x\in T]\Pr[x\in T]}{\Pr[0]}=\frac{q-pq}{1-pq} Pr[x∈T∣0]=Pr[0]Pr[0∣x∈T]Pr[x∈T]=1−pqq−pq, New entropy H = q − p q 1 − p q h 1 + 1 − q 1 − p q h 2 + ω ( q − p q 1 − p q ) + ω ( 1 − q 1 − p q ) H=\frac{q-pq}{1-pq}h_1+\frac{1-q}{1-pq}h_2+\omega({q-pq\over 1-pq})+\omega({1-q\over 1-pq}) H=1−pqq−pqh1+1−pq1−qh2+ω(1−pqq−pq)+ω(1−pq1−q) .
The original entropy is q h 1 + ( 1 − q ) h 2 + ω ( q ) + ω ( 1 − q ) qh_1+(1{-}q)h_2+\omega(q)+\omega(1{-}q) qh1+(1−q)h2+ω(q)+ω(1−q) . therefore , The expected amount of information is
Δ H = q h 1 + ( 1 − q ) h 2 + ω ( q ) + ω ( 1 − q ) − p q h 1 − ( 1 − p q ) [ q − p q 1 − p q h 1 + 1 − q 1 − p q h 2 + ω ( q − p q 1 − p q ) + ω ( 1 − q 1 − p q ) ] = ω ( q ) + ω ( 1 − q ) − ( 1 − p q ) [ ω ( q − p q 1 − p q ) + ω ( 1 − q 1 − p q ) ] \begin{aligned} \Delta H&=qh_1+(1{-}q)h_2+\omega(q)+\omega(1{-}q)-pqh_1\\ &-(1{-}pq)\left[\frac{q-pq}{1-pq}h_1+\frac{1-q}{1-pq}h_2+\omega\left(\frac{q-pq}{1-pq}\right)+\omega\left(\frac{1-q}{1-pq}\right)\right]\\ &=\omega(q)+\omega(1{-}q)-(1{-}pq)\left[\omega\left(\frac{q-pq}{1-pq}\right)+\omega\left(\frac{1-q}{1-pq}\right)\right] \end{aligned} ΔH=qh1+(1−q)h2+ω(q)+ω(1−q)−pqh1−(1−pq)[1−pqq−pqh1+1−pq1−qh2+ω(1−pqq−pq)+ω(1−pq1−q)]=ω(q)+ω(1−q)−(1−pq)[ω(1−pqq−pq)+ω(1−pq1−q)]
This is also in line with our intuitive feelings —— Internal elements are not distinguished , Therefore, the internal entropy does not interfere with the amount of information .
Use online math tools ( In the examination room, it is suggested to type the table and take the best value ) We know the best
q = 5 ( 5 4000 + 3381 5 − 100 5 − 64 ) 2869 q=\frac{5\left(5\sqrt{4000+3381\sqrt{5}}-100\sqrt{5}-64\right)}{2869} q=28695(54000+33815−1005−64)
It's about equal to
q ≈ 0.4356636377796835808889 q\approx 0.4356636377796835808889 q≈0.4356636377796835808889
take q = 0.435 q=0.435 q=0.435 Calculation , expect Δ H ≈ 0.618 \Delta H\approx 0.618 ΔH≈0.618 . What a beautiful number . So I hope to pass 64 Δ H ≈ 103.56 \frac{64}{\Delta H}\approx 103.56 ΔH64≈103.56 After times of inquiry, it can be solved .
Code
- Because it is the expected number of inquiries , Cannot exhaust 107 107 107 Just ask once , But the solution is r e t u r n \tt return return .
- As many as 2 64 2^{64} 264 individual , The real answer in the process Pr \Pr Pr It may be very low , Please don't give it up !
- The time complexity is not easy to calculate . But what you can think of is : The number of intervals is relatively small , about 64 64 64 individual .
#include "guess.h"
#include <cstdio>
#include <algorithm> // Almighty XJX yyds!!!
#include <cstring> // oracle: ZXY yydBUS!!!
#include <cctype> // Huge Egg Dog eats me!!!
#include <vector>
#include <utility>
#include <cmath>
using llong = long long;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
# define rep0(i,a,b) for(int i=(a); i!=(b); ++i)
inline int readint(){
int a = 0, c = getchar(), f = 1;
for(; !isdigit(c); c=getchar()) if(c == '-') f = -f;
for(; isdigit(c); c=getchar()) a = a*10+(c^48);
return a*f;
}
using ullong = unsigned long long;
using PUU = std::pair<ullong,ullong>;
extern bool Query(std::vector<PUU> v);
bool query(std::vector<PUU> v){
for(PUU &rg : v) -- rg.second;
return Query(v); // close range
}
using ldb = long double;
using NODE = std::pair<PUU,ldb>;
bool cmp(const NODE &a, const NODE &b){
return a.second/(a.first.second-a.first.first)
> b.second/(b.first.second-b.first.first);
}
ullong Guess(){
static const ullong MAXX = 18446744073709551606ull;
std::vector<NODE> v; v.resize(1);
v[0] = NODE{
PUU{
10,MAXX},1};
const long double q = 0.435, p = 0.8, notp = 0.2;
while(true){
if(v[0].first.second == v[0].first.first+1
&& int(v.size()) == 1) return v[0].first.first;
std::vector<PUU> ask; ask.clear();
long double nowq = 0;
for(const NODE &rg : v){
if(nowq >= q) break; // enough
if(nowq+rg.second <= q){
nowq += rg.second; // good
ask.push_back(rg.first); continue;
}
ullong len = rg.first.second-rg.first.first;
ullong cnt = ullong(floor((q-nowq)*len/rg.second));
if(nowq == 0 && cnt == 0) cnt = 1;
if(!cnt) continue; // length = 0
nowq += cnt*rg.second/len; ask.push_back(
PUU{
rg.first.first,rg.first.first+cnt});
}
if(query(ask)){
const int lenask = int(ask.size());
for(int i=0,j=0,k=0; true; ++i){
if(j == lenask){
v.resize(k); break; }
if(ask[j] == v[i].first) // covered
v[k] = v[i], v[k++].second /= nowq, ++ j;
else if(ask[j].first == v[i].first.first){
ullong nxt = ask[j].second-ask[j].first;
ullong now = v[i].first.second-v[i].first.first;
v[k++] = NODE{
ask[j++],v[i].second/nowq*nxt/now};
}
}
}
else{
long double wxk = 1-p*nowq;
const int lenask = int(ask.size()), lenv = int(v.size());
for(int i=0,j=0; i!=lenv; ++i){
v[i].second /= wxk;
if(j == lenask) continue;
if(ask[j] == v[i].first)
v[i].second *= notp, ++ j;
else if(ask[j].first == v[i].first.first){
ullong nxt = ask[j].second-ask[j].first;
ullong now = v[i].first.second-v[i].first.first;
v.push_back(NODE{
ask[j],v[i].second*notp*nxt/now});
v[i].first.first = ask[j++].second; // outside
v[i].second = v[i].second*(now-nxt)/now;
}
}
}
if(true){
// will this be slow?
std::sort(v.begin(),v.end(),cmp);
long double tot = 0;
for(const NODE &rg : v) tot += rg.second;
for(NODE &rg : v) rg.second /= tot;
}
}
}
边栏推荐
猜你喜欢
There is nothing new under the sun. Can the meta universe go higher?
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
双向链表(我们只需要关注插入和删除函数)
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
Resource Cost Optimization Practice of R & D team
Using registered classes to realize specific type matching function template
SQL Injection (POST/Search)
Qt学习25 布局管理器(四)
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
随机推荐
MySQL 数据增删改查综合案例
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
Flutter dynamic | fair 2.5.0 new version features
[combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
Brief analysis of tensorboard visual processing cases
PHP maze game
3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
Golang — 命令行工具cobra
Students who do not understand the code can also send their own token, which is easy to learn BSC
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
php 迷宫游戏
使用vscode查看Hex或UTF-8编码
Qt学习18 登录对话框实例分析
掌握Cypress命令行选项,是真正掌握Cypress的基础
Go language web development series 30: gin: grouping by version for routing
[technology development-24]: characteristics of existing IOT communication technology
GoLand 2021.1.1: configure the multi line display of the tab of the open file
RichView TRVStyle ListStyle 列表样式(项目符号编号)
软件测试工作那么难找,只有外包offer,我该去么?
Summary of common error reporting problems and positioning methods of thrift