Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:参考《数据结构编程实验》 吴永辉In Reply To:参考《数据结构编程实验》 吴永辉 Posted by:yzzxliuchao at 2016-12-21 14:43:05 > #include <iostream> > #include <cstdio> > #include <cstring> > > using namespace std; > > const int maxn = 10000 + 10; > int cnt[maxn]; //耗费为k的进程数 > bool print[maxn]; > > int main() > { > //freopen("manager.in","r",stdin); > //freopen("manager.out","w",stdout); > > int minp = 1; //进程的最小耗费值 > int maxp; //进程的最大耗费值 > int plen; //删除的进程数 > int condition;//管理者的删除策略 > > while(cin >> maxp) //整个输入以测试数据组的首个整数为0(maxp==0)为止 > { > condition = 1; //管理者的删除策略默认为1 > memset(print,false,sizeof(print)); > memset(cnt,0,sizeof(cnt)); > > cin >> plen; > int x; > for(int i = 1; i <= plen; i++) //将删除列表中的进程标志设为true > { > cin >> x; > print[x] = true; > } > getchar(); //跳过删除列表后的换行符 > > int np = 0; //当前被删除的进程数设为0 > char req; //命令类型 > while(cin >> req && req != 'e') //输入请求类别 > { > if(req == 'a') > { > cin >> x; //读进程的花费;相同耗费进程不止一个 > cnt[x]++; > } > else if(req == 'r') > { > bool flag = true; //假设队列为空 > if(condition == 1) //删除最小耗费 > { > for(int k = minp; k <= maxp; k++) > { > if(cnt[k] != 0) > { > cnt[k]--; > np++; //累计被删除的进程 > if(print[np] == true) cout << k << endl; //该进程在被删计划之列 > flag = false; > break; > } > } > } > else if(condition == 2) //删除最大耗费 > { > for(int k = maxp; k >= minp; k--) > { > if(cnt[k] != 0) > { > cnt[k]--; > np++; //累计被删除的进程 > if(print[np] == true) cout << k << endl; //该进程在被删计划之列 > flag = false; > break; > } > } > } > if(flag) cout << "-1" << endl; //队列为空,输出-1 > } > else if(req == 'p') > { > cin >> condition; > } > } > cout << endl; //用空行输出不同测试用例的结果 > } > > //fclose(stdin); > //fclose(stdout); > > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator