2024.8.21 鮮花
Never Gonna Give You Up
We're no strangers to love
You know the rules and so do I
A full commitment's what I'm thinking of
You wouldn't get this from any other guy
I just wanna tell you how I'm feeling
Gotta make you understand
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
We've known each other for so long
Your heart's been aching but you're too shy to say it
Inside we both know what's been going on
We know the game and we're gonna play it
And if you ask me how I'm feeling
Don't tell me you're too blind to see
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
(Ooh give you up)
(Ooh give you up)
(Ooh) never gonna give, never gonna give
(give you up)
(Ooh) never gonna give, never gonna give
(give you up)
We've known each other for so long
Your heart's been aching but you're too shy to say it
Inside we both know what's been going on
We know the game and we're gonna play it
I just wanna tell you how I'm feeling
Gotta make you understand
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you

模擬退火和本地 IO 交互。
模擬退火:
退火定義,有興趣可以看看 this
當然這和算法無關。
考慮爬山缺陷,會陷入局部解,考慮讓他跳出最優解。
定義退火函數 \(T\),每次決策后下降(一般為乘 \([0.995,0.996]\))每次決策點偏移量乘上 \(T\)。
為了跳出局部解,要有一定概率接受不優的解。
設 \(\Delta\) 為這次解和上次的差,轉移概率:
\[P(x,y)=\begin{cases} 1 ,\ \Delta < 0 \\ e ^ {- \frac{\Delta}{T}} \ , \ \Delta > 0\end{cases}
\]
本地交互:
重點科技:管道
普通管道沒有辦法雙向,考慮管道文件。
用 mkfifo 創建一個管道文件,然后就可以用這個交互了。
具體就是創建兩個文件,分別用重定向讀入寫出,因為互相阻塞可以達到效果。
這里實現了一個簡單的猜數交互
猜數程序(a.cpp)
#include<bits/stdc++.h>
using namespace std;
using llt=long long;
using llf=long double;
using ull=unsigned long long;
#ifdef LOCAL
FILE *InFile=freopen("in_out/in.in","r",stdin),*OutFile=freopen("in_out/out.out","w",stdout);
#else
FILE *InFile=stdin,*OutFile=stdout;
#endif
const llt RG=1e18;
int main(){
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
llt l=1,r=RG;
while(l<=r){
llt mid=(l+r)>>1; bool fg; cout<<"? "<<mid<<endl,cin>>fg;
if(fg) r=mid-1;
else l=mid+1;
}
cout<<"! "<<l<<endl;
}
交互程序(b.cpp)
#include<bits/stdc++.h>
using namespace std;
using llt=long long;
using llf=long double;
using ull=unsigned long long;
#ifdef LOCAL
FILE *InFile=freopen("in_out/in.in","r",stdin),*OutFile=freopen("in_out/out.out","w",stdout);
#else
FILE *InFile=stdin,*OutFile=stdout;
#endif
const llt RG=1e18;
mt19937_64 rnd(ull(new char)*ull(new char));
int main(){
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
llt a=rnd()%RG+1,tot=0;
while(true){
char k; llt x; cin>>k>>x;
if(k=='?') cout<<(x>=a)<<endl,++tot;
else{
if(x!=a) return cerr<<"Sorry, you are wrong. Answer: "<<a<<' '<<x<<endl,-1;
else return cerr<<"Good, you are right. Times: "<<tot<<endl,0;
}
}
}
Run 記得先用 mkfifo 建 inpipe 和 outpipe
#include<bits/stdc++.h>
using namespace std;
int main(){
assert(!system("g++ a.cpp -o a -O2 -std=c++14"));
assert(!system("g++ b.cpp -o b -O2 -std=c++14"));
system("(./a>inpipe<outpipe)&(./b<inpipe>outpipe)");
}
注意要把先輸出的放到前面
夙愿達成

本文來自博客園,作者:xrlong,轉載請注明原文鏈接:http://www.rzrgm.cn/xrlong/p/18372524
版權聲明:本作品采用 「署名-非商業性使用-相同方式共享 4.0 國際」許可協議(CC BY-NC-SA 4.0) 進行許可。

浙公網安備 33010602011771號