trpit

Down

测试新东西

你现在是一棵树,你需要活过若干天:

你每天都有一定量的 【养料】 和 【阳光】,你需要这两种物品才能进行行动

行动

【生长根系】:消耗一定 【养料】【阳光】,使根系获得生长,大小增加 \(1\)

【增高】:消耗一定 【养料】【阳光】,增长茎干,高度增加 \(1\)

【生长树叶】:消耗一定 【养料】【阳光】,生长树叶,叶子数量增加 \(1\)(由于生长叶子需要一定空间,叶子数量不能超过高度)

【生长果实】:消耗一定 【养料】【阳光】,生长果实,果实数量增加 \(1\)(由于生长果实需要一定空间,果实(含已成熟果实)数量不能超过高度)

【成熟果实】:消耗一定 【养料】【阳光】,选择一个未成熟果实,使其成熟

资源取得

在新的一天开始时,将获得 1+根系大小 的养料

在新的一天开始时,将获得 1+叶子大小 的养料

存活目标

由于你生活在一片农场里,因此你需要尽可能生长果实,否则就会被农场主铲掉

你在第 \(i\) 天需要至少生长 \(a_i\)已成熟 的果实,否则就会失败

源码

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int tot_days;
int day=0;
vector<int>req;
int minyl,minyg;
struct{
	int remainyf;
	int remainyg;
}self;
struct{
	int cnt;
	int costyf;
	int costyg;
}root;
struct{
	int cnt;
	int costyf;
	int costyg;
}high;
struct{
	int cnt;
	int costyf;
	int costyg;
}leaf;
struct{
	int cnt;
	int costyf;
	int costyg;
}wcgz;
struct{
	int cnt;
	int costyf;
	int costyg;
}csgz;
void clear(){
	day=0;
	self.remainyf=self.remainyg=0;
	root.cnt=0;root.costyf=root.costyg=1;
	high.cnt=0;high.costyf=high.costyg=1;
	leaf.cnt=0;leaf.costyf=leaf.costyg=1;
	wcgz.cnt=0;wcgz.costyf=wcgz.costyg=1;
	csgz.cnt=0;wcgz.costyf=wcgz.costyg=1;
}
void print(){
	cout<<"[ Day "<<day<<"/"<<tot_days<<" ]"<<endl<<endl;
	cout<<"[Now Height: "<<high.cnt<<" m ]"<<endl;
	cout<<"[Have]"<<endl;
	cout<<"Fertilizer: "<<self.remainyf<<endl;
	cout<<"Sunlights: "<<self.remainyg<<endl<<endl;
	cout<<"[Status]"<<endl;
	cout<<"Root "<<root.cnt<<endl;
	cout<<"Leaf "<<leaf.cnt<<endl;
	cout<<"Apple "<<wcgz.cnt<<endl;
	cout<<"Heavested apple "<<csgz.cnt<<endl<<endl;
	cout<<"[Action Cost]"<<endl;
	cout<<"[1] new Root : "<<root.costyf<<" Fertilizer & "<<root.costyg<<" Sunlights"<<endl;
	cout<<"[2] new Leaf : ";
	if(high.cnt<=leaf.cnt) cout<<" { Lacking Height: Need at least "<<leaf.cnt+1<<" m }"<<endl;
	else cout<<leaf.costyf<<" Fertilizer & "<<leaf.costyg<<" Sunlights"<<endl;
	cout<<"[3] new Apple : ";
	if(high.cnt<=wcgz.cnt+csgz.cnt) cout<<" { Lacking Height: Need at least "<<wcgz.cnt+csgz.cnt+1<<" m }"<<endl;
	else cout<<wcgz.costyf<<" Fertilizer & "<<wcgz.costyg<<" Sunlights"<<endl;
	cout<<"[4] Heavest an apple : ";
	if(wcgz.cnt==0) cout<<" { Lacking Apple: Need at least 1 apple }"<<endl;
	else cout<<csgz.costyf<<" Fertilizer & "<<csgz.costyg<<" Sunlights"<<endl;
	cout<<"[5] Add height : "<<high.costyf<<" Fertilizer & "<<high.costyg<<" Sunlights"<<endl;
	cout<<"[6] Goto next day : You will Get "<<1+root.cnt<<" Fertilizer & "<<1+leaf.cnt<<" Sunlights ";
	if(csgz.cnt<req[day]) cout<<" [you will lost if you goto next day, need to add "<<req[day]-csgz.cnt<<" heavest apple]";
	cout<<endl<<endl;
	cout<<"[Farmer Request]"<<endl;
	for(int i=day;i<=min(tot_days,day+2);++i){
		cout<<"[Day "<<i<<" request] "<<req[i]<<endl;
	}
}

void read(const string filein){
	minyl=0x7fffffff,minyg=0x7fffffff;
	ifstream in;in.open(filein.c_str());
	in>>tot_days>>self.remainyf>>self.remainyg;
	self.remainyf--;self.remainyg--;
	in>>root.costyf>>root.costyg;
	minyl=min(minyl,root.costyf);
	minyg=min(minyg,root.costyg);
	in>>leaf.costyf>>leaf.costyg;
	minyl=min(minyl,leaf.costyf);
	minyg=min(minyg,leaf.costyg);
	in>>wcgz.costyf>>wcgz.costyg;
	minyl=min(minyl,wcgz.costyf);
	minyg=min(minyg,wcgz.costyg);
	in>>csgz.costyf>>csgz.costyg;
	minyl=min(minyl,csgz.costyf);
	minyg=min(minyg,csgz.costyg);
	in>>high.costyf>>high.costyg;
	minyl=min(minyl,high.costyf);
	minyg=min(minyg,high.costyg);
	req.clear();req.push_back(0);
	for(int i=1;i<=tot_days;++i){
		int x;in>>x;req.push_back(x);
	}
}
bool next_day(){
	day++;
	self.remainyg+=1+leaf.cnt;
	self.remainyf+=1+root.cnt;
	if(day>tot_days) return true;
	return false;
}
int main(){
	string in;
	cout<<"Open a file >>";
	cin>>in;
	read(in);
	bool lost=false;
	while(!next_day()){
		if(csgz.cnt<req[day-1]){
			lost=true;
			break;
		}
		system("cls");
		print();
		while(1){
			if(0) if(self.remainyf<minyl or self.remainyg<minyg) break;
			int opt;cin>>opt;
			if(opt==1){
				if(self.remainyf>=root.costyf and self.remainyg>=root.costyg){
					self.remainyf-=root.costyf;
					self.remainyg-=root.costyg;
					root.cnt++;
					#if RAND_MAX==INT_MAX
					system("clear");
					#else
					system("cls");
					#endif
					print();
				}
				else cout<<"[illegal: Lacking of Fertilizer or Sunlights]"<<endl;
			}
			if(opt==2){
				if(high.cnt<=leaf.cnt){
					cout<<"[illegal: Lacking Height: Need at least "<<leaf.cnt+1<<" m ]"<<endl;
				}
				else if(self.remainyf>=leaf.costyf and self.remainyg>=leaf.costyg){
					self.remainyf-=leaf.costyf;
					self.remainyg-=leaf.costyg;
					leaf.cnt++;
					#if RAND_MAX==INT_MAX
					system("clear");
					#else
					system("cls");
					#endif
					print();
				}
				else cout<<"[illegal: Lacking of Fertilizer or Sunlights]"<<endl;
			}
			if(opt==3){
				if(high.cnt<=wcgz.cnt+csgz.cnt){
					cout<<"[illegal: Lacking Height: Need at least "<<wcgz.cnt+csgz.cnt+1<<" m ]"<<endl;
				}
				else if(self.remainyf>=wcgz.costyf and self.remainyg>=wcgz.costyg){
					self.remainyf-=wcgz.costyf;
					self.remainyg-=wcgz.costyg;
					wcgz.cnt++;
					#if RAND_MAX==INT_MAX
					system("clear");
					#else
					system("cls");
					#endif
					print();
				}
				else cout<<"[illegal: Lacking of Fertilizer or Sunlights]"<<endl;
			}
			if(opt==4){
				if(wcgz.cnt==0){
					cout<<"[illiegal: Lacking Apple: Need at least 1 apple]"<<endl;
				}
				else if(self.remainyf>=csgz.costyf and self.remainyg>=csgz.costyg){
					self.remainyf-=csgz.costyf;
					self.remainyg-=csgz.costyg;
					wcgz.cnt--;
					csgz.cnt++;
					#if RAND_MAX==INT_MAX
					system("clear");
					#else
					system("cls");
					#endif
					print();
				}
				else cout<<"[illegal: Lacking of Fertilizer or Sunlights]"<<endl;
			}
			if(opt==5){
				if(self.remainyf>=high.costyf and self.remainyg>=high.costyg){
					self.remainyf-=high.costyf;
					self.remainyg-=high.costyg;
					high.cnt++;
					#if RAND_MAX==INT_MAX
					system("clear");
					#else
					system("cls");
					#endif
					print();
				}
				else cout<<"[illegal: Lacking of Fertilizer or Sunlights]"<<endl;
			}
			if(opt==6){
				break;
			}
		}
	}
	if(csgz.cnt<req[day-1]){
		lost=true;
	}
	cout<<endl;
	if(lost) cout<<"You lost on "<<in<<endl;
	else cout<<"You win on "<<in<<endl;
}
3 3 3
1 1
1 1
1 1
1 1
1 1
0 0 1
10 2 2
1 1
1 1
1 1
1 1
1 0
0 1 1 1 2 2 2 3 4 5
posted @ 2024-10-31 17:35  HaneDaniko  阅读(23)  评论(1编辑  收藏  举报