这道题卡了两天了,请大佬们帮忙看看
查看原帖
这道题卡了两天了,请大佬们帮忙看看
749318
xuchenran楼主2024/9/28 20:57

rt,代码(二十分),第二个样例挂了,谢谢:

提交记录

//luogu.com.cn P8874
#include<bits/stdc++.h>
using namespace std;
int n,m,q,l,c[105][105],add[105],a[105],be[105],mon[2],d[105],op,opr,k,pos[2],cnt;
string s[2]{"Renko","Merry"};
int main(){
	cin>>n>>m>>q>>l;
	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++){
			cin>>c[i][j];
		}
	}
	for(int i=0;i<n;i++){
		cin>>d[i];
	}
	mon[0]=mon[1]=m;
	opr=-1; 
	pos[0]=pos[1]=0;
//	cout<<"-----------------------round-----------------------"<<endl;
	while(cin>>op>>k){
		if(cnt==2){
//			cout<<"-----------------------round-----------------------"<<endl;
			mon[0]+=add[0];
			mon[1]+=add[1];
			cnt=0; 
		}
		if(op==1){
			cnt++;
			if(mon[0]<0){
				cout<<s[0];
				return 0;
			}
			if(mon[1]<0){
				cout<<s[1];
				return 0;
			}
			if(opr==-1){
				opr=1;
			}
			opr^=1;
			pos[opr]=(pos[opr]+k)%n;
//			cout<<"//"<<s[opr]<<" on"<<"//:"<<pos[opr]<<endl; 
			if(a[pos[opr]]!=0){
				int t=a[pos[opr]]*(opr*2-1);
				if(t>=0){
//					cout<<"//"<<s[opr]<<" added//:"<<t<<endl;
					mon[opr]+=t; 
				}
				else{
//					cout<<"//"<<s[opr]<<" transfered to "<<s[opr^1]<<"//:"<<t<<endl;
					if(t<0)t=-t;
					mon[opr]-=t;
					mon[opr^1]+=t;
				}
			}
			if(mon[0]<0){
				cout<<s[0];
				return 0;
			}
			if(mon[1]<0){
				cout<<s[1];
				return 0;
			}
		}
		if(op==2){
			if(a[pos[opr]]&&(abs(a[pos[opr]])/a[pos[opr]]!=(opr*2-1))){
//				cout<<"//filled by other on//:"<<pos[opr]<<endl;
				continue;
			}
			if(a[pos[opr]]==0){
				add[opr]+=d[pos[opr]];
			}
			while(k--){
				if(abs(be[pos[opr]])==l){
//					cout<<"//full level on//"<<pos[opr]<<endl;
					break;
				}
				if(mon[opr]-c[pos[opr]][abs(be[pos[opr]])]<0){
//					cout<<"//lack of money on//:"<<pos[opr]<<' '<<be[pos[opr]]+(opr*2-1)<<endl;
					break;
				}
				mon[opr]-=c[pos[opr]][abs(be[pos[opr]])];
				int tp=c[pos[opr]][abs(be[pos[opr]])]*(opr*2-1);
//				cout<<"//"<<tp<<"//"<<endl;
				a[pos[opr]]+=tp;
				be[pos[opr]]++;
//				cout<<"//added//: "<<pos[opr]<<' '<<be[pos[opr]]<<endl;
			}
		}
		if(mon[0]<0){
			cout<<s[0];
			return 0;
		}
		if(mon[1]<0){
			cout<<s[1];
			return 0;
		}
//		cout<<"//"<<mon[0]<<' '<<mon[1]<<"//"<<endl;
	}
	cout<<mon[0]+add[0]<<' '<<mon[1]+add[1];
} 
2024/9/28 20:57
加载中...