标签:efi char turn ota for == clear else target
题意:有各种操作,模拟这个程序并输出每次操作的信息
分析:恶心模拟题。。。用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里。因为n很小,其他就暴力模拟了。
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #define ll long long #define ull unsigned long long //#define LOCAL using namespace std; const int maxn=5000+10; const int inf=0x3f3f3f3f; const int mod=1e9+7; map<int,ll> C;
//flag标记always on top,T为其优先值 int x,T,A[maxn],N,flag; int find(int a){ for(int i=0;i<N;i++) if(A[i]==a) return i; return N; } void add(){ scanf("%d",&x); if(C.count(x)) printf("same priority"); else{ A[N++]=x; C[x]=0; printf("success"); } } void close(){ scanf("%d",&x); if(C.count(x)){ printf("close %d with %I64d",x,C[x]); C.erase(x); if(flag&&T==x) flag=0; int pos=find(x); for(int i=pos;i<N;i++) A[i]=A[i+1]; N--; } else printf("invalid priority"); } void chat(){ scanf("%d",&x); if(N==0) printf("empty"); else{ if(flag) C[T]+=x; else C[A[0]]+=x; printf("success"); } } void roate(){ scanf("%d",&x); if(x>N||x<1) printf("out of range"); else{ int t=A[x-1]; for(int i=x-1;i;i--) A[i]=A[i-1]; A[0]=t; printf("success"); } } void prior(){ if(N==0) printf("empty"); else{ int pos=0,maxx=A[0]; for(int i=1; i<N; i++){ if(A[i]>maxx){ maxx=A[i]; pos=i; } } int t=A[pos]; for(int i=pos;i;i--) A[i]=A[i-1]; A[0]=t; printf("success"); } } void choose(){ scanf("%d",&x); if(C.count(x)){ int pos=find(x); int t=A[pos]; for(int i=pos;i;i--) A[i]=A[i-1]; A[0]=t; printf("success"); } else printf("invalid priority"); } void top1(){ scanf("%d",&x); if(C.count(x)){ T=x; flag=1; printf("success"); } else printf("invalid priority"); } void untop(){ if(flag){ flag=0; printf("success"); } else printf("no such person"); } void bye(){ if(N==0) return; if(flag&& C[T]) printf("Bye %d: %I64d\n",T,C[T]); for(int i=0;i<N;i++){ if(flag&& A[i]==T) continue; if(C[A[i]]) printf("Bye %d: %I64d\n",A[i],C[A[i]]); } } int main(){ //ios::sync_with_stdio(false); #ifdef LOCAL freopen("in.txt","r",stdin); #endif int t,n; cin>>t; while(t--) { N=T=flag=0; C.clear(); scanf("%d",&n); char s[10]; for(int i=1; i<=n; i++){ scanf("%s",s); printf("Operation #%d: ",i); if(strcmp(s,"Add")==0) add(); else if(strcmp(s,"Chat")==0) chat(); else if(strcmp(s,"Close")==0) close(); else if(strcmp(s,"Rotate")==0) roate(); else if(strcmp(s,"Prior")==0) prior(); else if(strcmp(s,"Choose")==0) choose(); else if(strcmp(s,"Top")==0) top1(); else if(strcmp(s,"Untop")==0) untop(); printf(".\n"); } bye(); } return 0; }
标签:efi char turn ota for == clear else target
原文地址:http://www.cnblogs.com/fht-litost/p/7257878.html