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
当然这和算法无关。
考虑爬山缺陷,会陷入局部解,考虑让他跳出最优解。
定义退火函数
为了跳出局部解,要有一定概率接受不优的解。
设
本地交互:
重点科技:管道
普通管道没有办法双向,考虑管道文件。
用 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)"); }
注意要把先输出的放到前面
夙愿达成
本文来自博客园,作者:5k_sync_closer,转载请注明原文链接:https://www.cnblogs.com/xrlong/p/18372524
版权声明:本作品采用 「署名-非商业性使用-相同方式共享 4.0 国际」许可协议(CC BY-NC-SA 4.0) 进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了