跳到正文

科技·工程

此地无雷 301 个(QZOI 菜单生成器 2.0)

glass_goldfish约 11 分钟
原文
文章信息与版本

文章信息

发布
2025年12月24日
收录
2025年12月24日
更新
2026年11月14日
篇幅
约 11 分钟

版本

  1. v4当前
  2. v3
  3. v2
  4. v1

警告:请务必每次使用时点击【更新内容】,等待 5s 并重新运行程序,因为先前代码可能会有 bug 有可能会暗改更新埋新的雷。

程序(.exe)下载地址:https://www.luogu.com.cn/problem/U561734(这里也会更新,如果程序更新了)

哎果然是石山。

由于一些原因,本程序无法实现直接读写 xls 文件(表格),需要手动添加(因为要安装库什么的十分麻烦 awa)。嫌麻烦就叫 Author 帮忙手搓也行

使用方法

  • 新建 QZ_cds1.txt,QZ_cds2.txt,QZ_cds3.txt,QZ_cds4.txt,QZ_auto.txt,QZ_fruits.txt(如果有则无需重新创建)。
  • 在 QZ_auto.txt 中写入
代码
周一
周二
周三
周四
周五
周六
午餐
晚餐
  • 在 QZ_fruits.txt 中写入
代码
香蕉
苹果
梨
小番茄
草莓
西瓜
哈密瓜
桃子
葡萄
橘子
冬枣
桂圆
红枣酸奶
原味酸奶
小罐蓝莓酸奶
纯牛奶
  • 在 QZ_cds1.txt 中写入大荤,格式如:每个菜一行,第一个为字符串(可以是中文),代表菜品名称;第二个是浮点数,代表价格(每人)。无需给出个数,程序能够自动获取。
  • 相似地,在 QZ_cds2.txt 中写入小荤,QZ_cds3.txt 写入素菜,QZ_cds4.txt 写入汤品。
  • 运行文末给出的代码,打开 QZ_cds.txt 查看菜单。仅生成一周的菜单。

注意:由于代码过于石山,水果和酸奶、牛奶不支持修改。这些东西学校都出现过,所以大概没有问题;Author 按照自己的想法分成了春夏秋冬对应的水果。

C++
#include<bits/stdc++.h>
#include<windows.h>
#define int long long
#define INF 1145141919810
using namespace std;
/*
技术指导:
SetConsoleOutputCP(65001); 设置 UTF-8【正确】
cin.clear(); 在多个 freopen 之间炸东西【正确】
同 cout.clear();【需要验证】

预设方案:
通过 QZ_cds(1or2or3).txt 进行读入

每一行:
第一个为编号
第二个为菜品名称
第三个为价格

QZ_cds1.txt 大荤
QZ_cds2.txt 小荤
QZ_cds3.txt 素菜
QZ_cds4.txt 汤
标配:2大 1小 2素 1汤
*/
int ccd[301][301];
int year,month,day,wky;
int cnt1,cnt2,cnt3,cnt4;
int vel11,vel12;
int vel21;
int vel31,vel32;
int vel41;
int vel5;
string vel5s[1201];
//水果/酸奶,水果前 12 种,酸奶等后 4 种(13,14,15,16)
int vel51[1201]={0,1,2,3,4,5};
int vel52[1201]={0,1,2,3,4,6,7,8};
int vel53[1201]={0,1,2,3,4,8,9,10,11,12};
int vel54[1201]={0,1,2,3,4,9,10,11,12};
int cnt51=5,cnt52=7,cnt53=9,cnt54=8;
string autol[1201];
struct veal{
//	string bihl;//编号
	string micl;//名称
	double pril;//价格
}vel1[1201],vel2[1201],vel3[1201],vel4[1201];
void first_print();
void get_date();//获取当前日期
void get_vel(){//找出合适的菜编号 #11r
	vel11=rand()%cnt1+1;
	vel12=rand()%cnt1+1;
	while(vel12==vel11)vel12=rand()%cnt1+1;
	vel21=rand()%cnt2+1;
	vel31=rand()%cnt3+1;
	vel32=rand()%cnt3+1;
	while(vel31==vel32)vel32=rand()%cnt3+1;
	//初步随机化选择
	int pr1=vel1[vel11].pril+vel1[vel12].pril;
	int pr2=vel2[vel21].pril;
	int pr3=vel3[vel31].pril+vel3[vel32].pril;
	//初步计算价格
	if(pr1+pr2+pr3<=11)return;
	if(pr1>6){//大荤安排 6 元
		if(vel1[vel11].pril<vel1[vel12].pril)
			swap(vel11,vel12);//从大的开刀
		while(vel1[vel11].pril+vel1[vel12].pril>6)
			vel11=rand()%cnt1+1;//重新选择
		pr1=vel1[vel11].pril+vel1[vel12].pril;
		if(pr1+pr2+pr3<=11)return;
	}
	if(pr2>2){//小荤安排 2 元
		while(vel2[vel21].pril>2)
			vel21=rand()%cnt2+1;//重新选择
		pr2=vel2[vel21].pril;
		if(pr1+pr2+pr3<=11)return;
	}
	if(pr3>3){//素菜安排 3 元
		if(vel3[vel31].pril<vel3[vel32].pril)
			swap(vel31,vel32);//从大的开刀
		while(vel3[vel31].pril+vel3[vel32].pril>3)
			vel31=rand()%cnt3+1;//重新选择
		pr3=vel3[vel31].pril+vel3[vel32].pril;
		if(pr1+pr2+pr3<=11)return;
	}
}
void get_sp(){//汤品,纯随机
	vel41=rand()%cnt4+1;
}
void get_frt(){//水果/酸奶,按照季节
	if(wky==1)vel5=13+rand()%2;
	else if(wky==3)vel5=16;
	else if(wky==5)vel5=15;
	else{
		if(3<=month&&month<=5)
			vel5=vel51[rand()%cnt51+1];
		else if(6<=month&&month<=8)
			vel5=vel52[rand()%cnt52+1];
		else if(9<=month&&month<=11)
			vel5=vel53[rand()%cnt53+1];
		else vel5=vel54[rand()%cnt54+1];
	}
	wky++;
}
signed main(){
//	SetConsoleOutputCP(65001);
	SetConsoleCP(65001);
	srand(time(0));
	first_print();
	get_date();//获取当前日期
	freopen("QZ_cds1.txt","r",stdin);
	while(cin>>vel1[++cnt1].micl){
		cin>>vel1[cnt1].pril;
		//读入大荤菜品
	}
	cnt1--;
	cin.clear();
	freopen("QZ_cds2.txt","r",stdin);
	while(cin>>vel2[++cnt2].micl){
		cin>>vel2[cnt2].pril;
		//读入小荤菜品
	}
	cnt2--;
	cin.clear();
	freopen("QZ_cds3.txt","r",stdin);
	while(cin>>vel3[++cnt3].micl){
		cin>>vel3[cnt3].pril;
		//读入素菜
	}
	cnt3--;
	cin.clear();
	freopen("QZ_cds4.txt","r",stdin);
	while(cin>>vel4[++cnt4].micl){
		cin>>vel4[cnt4].pril;
		//读入汤品
	}
	cnt4--;
	cin.clear();
	freopen("QZ_fruits.txt","r",stdin);
	for(int i=1;i<=16;i++)
		cin>>vel5s[i];
	cin.clear();
	freopen("QZ_auto.txt","r",stdin);
	for(int i=1;i<=8;i++)
		cin>>autol[i];
	/*
	以上为输入部分
	以下为处理部分
	*/
	for(int dy=1;dy<=6;dy++){
		get_vel();
		get_sp();
		get_frt();
		ccd[1][dy]=vel11;
		ccd[2][dy]=vel12;
		ccd[3][dy]=vel21;
		ccd[4][dy]=vel31;
		ccd[5][dy]=vel32;
		ccd[6][dy]=vel41;
		ccd[7][dy]=vel5;
		get_vel();
		get_sp();
//		get_frt();
		ccd[8][dy]=vel11;
		ccd[9][dy]=vel12;
		ccd[10][dy]=vel21;
		ccd[11][dy]=vel31;
		ccd[12][dy]=vel32;
		ccd[13][dy]=vel41;
	}
	/*
	以上为处理部分
	以下为输出部分
	*/
	freopen("QZ_cds.txt","w",stdout);
	cout<<"\xEF\xBB\xBF";//? UTF-8 发力了
	for(int i=1;i<=6;i++){
		cout<<autol[i]<<": ";
		cout<<"\n  "<<autol[7]<<": ";
		cout<<vel1[ccd[1][i]].micl<<","<<vel1[ccd[2][i]].micl<<","<<vel2[ccd[3][i]].micl<<","<<vel3[ccd[4][i]].micl<<","<<vel3[ccd[5][i]].micl<<","<<vel4[ccd[6][i]].micl<<","<<vel5s[ccd[7][i]]<<"\n";
		if(i!=6){
			cout<<"  "<<autol[8]<<": ";
			cout<<vel1[ccd[8][i]].micl<<","<<vel1[ccd[9][i]].micl<<","<<vel2[ccd[10][i]].micl<<","<<vel3[ccd[11][i]].micl<<","<<vel3[ccd[12][i]].micl<<","<<vel4[ccd[13][i]].micl<<"\n";
		}
	}
	cerr<<"Menu printed(*Only this week).Please open QZ_cds.txt to see it.";
	return 0;
}
void first_print(){
	cerr<<"----------------QZOI Menu Printer----------------\n";
	cerr<<"                                  Author:glass_goldfish\n\n";
	cerr<<"*More information on https://luogu.me/article/0q98n59a\n\n";
}
void get_date(){
	auto nowt=chrono::system_clock::now();
	time_t nt=chrono::system_clock::to_time_t(nowt);
	tm* loct=localtime(&nt);
	year=loct->tm_year+1900;
	month=loct->tm_mon+1;
	day=loct->tm_mday;
//	wky=loct->tm_wday;
	wky=1;
}
原文