题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3704
试了试用类去写题;
方案是用函数递归查找最终的等级;
提示:注意Peasant没法直接升级到User只能满足条件升到Power_User;
AC代码:
#include<iostream> #include<cstdio> #include<string> using namespace std; class oneuser { public: friend istream & operator <<(istream &, oneuser &);//友元重载<<运算符,用于输入 //用于初始化rb(上传与下载的比例)和edge(表示对应的等级) void setrb() { rb=up/down; if(ed=="Peasant")edge=0; else if(ed=="User")edge=1; else if(ed=="Power_User")edge=2; else if(ed=="Elite_User")edge=3; else if(ed=="Crazy_User")edge=4; else if(ed=="Insane_User")edge=5; else if(ed=="Veteran_User")edge=6; else if(ed=="Extreme_User")edge=7; else if(ed=="Ultimate_User")edge=8; else if(ed=="Nexus_Master")edge=9; } //递归主体,基于当前等级满足降级条件降级,满足升级条件升级,如果不能升降等级即为答案输出即可 void setedge() { if(edge==1) { if(down>=50&&rb<0.4||down>=100&&rb<0.5||down>=200&&rb<0.6||down>=400&&rb<0.7||down>=800&&rb<0.8) { edge--; setedge(); } else if(week>=4&&down>=50&&rb>=1.05) { edge++; setedge(); } else { cout<<"User"<<endl; } } else if(edge==0) { if(week>=4&&down>=50&&rb>=1.05) { edge+=2; setedge(); } else { cout<<"Peasant"<<endl; } } else if(edge==2) { if(rb<0.95) { edge--; setedge(); } else if(week>=8&&down>=120&&rb>=1.55) { edge++; setedge(); } else { cout<<"Power_User"<<endl; } } else if(edge==3) { if(rb<1.45) { edge--; setedge(); } else if(week>=15&&down>=300&&rb>=2.05) { edge++; setedge(); } else { cout<<"Elite_User"<<endl; } } else if(edge==4) { if(rb<1.95) { edge--; setedge(); } else if(week>=25&&down>=500&&rb>=2.55) { edge++; setedge(); } else { cout<<"Crazy_User"<<endl; } } else if(edge==5) { if(rb<2.45) { edge--; setedge(); } else if(week>=40&&down>=750&&rb>=3.05) { edge++; setedge(); } else { cout<<"Insane_User"<<endl; } } else if(edge==6) { if(rb<2.95) { edge--; setedge(); } else if(week>=60&&down>=1024&&rb>=3.55) { edge++; setedge(); } else { cout<<"Veteran_User"<<endl; } } else if(edge==7) { if(rb<3.45) { edge--; setedge(); } else if(week>=80&&down>=1.5*1024&&rb>=4.05) { edge++; setedge(); } else { cout<<"Extreme_User"<<endl; } } else if(edge==8) { if(rb<3.95) { edge--; setedge(); } else if(week>=100&&down>=3*1024&&rb>=4.55) { edge++; setedge(); } else { cout<<"Ultimate_User"<<endl; } } else if(edge==9) { if(rb<4.45) { edge--; setedge(); } else { cout<<"Nexus_Master"<<endl; } } } string ed; double down,up,rb; int week,edge; }; istream & operator >>(istream & in , oneuser & p) { in>>p.ed>>p.week>>p.down>>p.up; return in; } int main() { int t; cin>>t; while(t--) { oneuser o; cin>>o; o.setrb(); o.setedge(); } }
评论