【模拟】【set】hdu 4789 ICPC Ranking

写了一晚上,TLE到死,我选择GG

喵的好像还是前几年我校出的题,这整场都……tm……

改日在战

/*TLE代码*/

#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
int e;
using namespace std;
map<string,int>ma;
struct data{
	vector<int>lasts;
	int solved,penalty;
	string name;/*
	data(const int &_solved,const int &_penalty,const vector<int> & _lasts,const string &_name){
		solved=_solved;
		penalty=_penalty;
		lasts=_lasts;
		name=_name;
	}*/
	data(const string &_name){
		solved=penalty=0;
		name=_name;
		lasts.clear();
	}
	data(){}
};
bool operator < (const data &a,const data &b){
	if(a.solved!=b.solved){
		return a.solved>b.solved;
	}
	if(a.penalty!=b.penalty){
		return a.penalty<b.penalty;
	}
	for(int i=a.lasts.size()-1,j=b.lasts.size()-1;i>=0 && j>=0;--i,--j){
		if(a.lasts[i]!=b.lasts[j]){
			return a.lasts[i]<b.lasts[j];
		}
	}
	return a.name>b.name;
}
typedef set<data>::iterator set_ITER;
struct Query{
	string name;
	char pro;
	int t,type;
}Q[50010];
bool operator < (const Query &a,const Query &b){
	if(a.t!=b.t){
		return a.t<b.t;
	}
	return a.type<b.type;
}
set<data>S;
data A[50010],output[50010];
int p;
int B[50010][26]/*,D[50010][26]*/,aftersubs[50010][26];
int C[50010][26],E[50010][26];
int n,m,T,t,ZU;
int main(){
//	freopen("i.in","r",stdin);
	char tmp1[10],tmp2[10];
	scanf("%d",&ZU);
	for(int zu=1;zu<=ZU;++zu){
		printf("Case #%d:\n",zu);
//		memset(aftersubs,0,sizeof(int)*(e+1)*26);
//		memset(B,0,sizeof(int)*(e+1)*26);
//		memset(C,0,sizeof(int)*(e+1)*26);
//		memset(D,0,sizeof(int)*(e+1)*26);
//		memset(E,0,sizeof(int)*(e+1)*26);
		ma.clear();
		e=0;
		S.clear();
		p=0;
		S.insert(data(""));
		scanf("%d%d%d%d",&n,&m,&T,&t);
		for(int i=1;i<=n;++i){
			cin>>Q[i].name;
			if(!ma[Q[i].name]){
				ma[Q[i].name]=++e;
				A[e]=data(Q[i].name);
				S.insert(A[e]);
			}
			scanf("%s%d%s",tmp1,&Q[i].t,tmp2);
			Q[i].pro=tmp1[0];
			if(tmp2[0]==‘E‘){
				Q[i].type=0;
			}
			if(tmp2[0]==‘N‘){
				Q[i].type=1;
			}
			else{
				Q[i].type=2;
			}
		}
		sort(Q+1,Q+n+1);
		for(int i=1;i<=n;++i){
			int id=ma[Q[i].name];
			if(Q[i].t>=t){
				++aftersubs[id][Q[i].pro-‘A‘];
				continue;
			}
			if(Q[i].type==0 || (Q[i].type==2 && C[id][Q[i].pro-‘A‘])){
				continue;
			}
			if(Q[i].type==1){
				++B[id][Q[i].pro-‘A‘];
//				++D[id][Q[i].pro-‘A‘];
			}
			else{
				S.erase(A[id]);
				C[id][Q[i].pro-‘A‘]=Q[i].t;
				E[id][Q[i].pro-‘A‘]=Q[i].t;
				++A[id].solved;
				A[id].penalty+=(Q[i].t+B[id][Q[i].pro-‘A‘]*20);
				A[id].lasts.push_back(Q[i].t);
				S.insert(A[id]);
			}
		}
		int rank=1;
		set_ITER jt=S.begin(); ++jt;
		for(set_ITER it=S.begin();;++it,++rank,++jt){
			if(jt==S.end()){
				break;
			}
			cout<<(*it).name<<‘ ‘<<rank<<‘ ‘<<(*it).solved<<‘ ‘<<(*it).penalty;
			int id=ma[(*it).name];
			for(int i=0;i<m;++i){
				putchar(‘ ‘);
				if(C[id][i]){
					putchar(‘+‘);
					if(B[id][i]){
						printf("%d",B[id][i]);
					}
				}
				else{
					if(aftersubs[id][i]){
						if(B[id][i]){
							printf("-%d",B[id][i]);
						}
						else{
							putchar(‘0‘);
						}
						putchar(‘/‘);
						printf("%d",aftersubs[id][i]);
					}
					else{
						if(B[id][i]){
							printf("-%d",B[id][i]);
						}
						else{
							putchar(‘.‘);
						}
					}
				}
			}
			puts("");
		}
		int From;
		for(int i=1;i<=n;++i){
			if(Q[i].t>=t){
				From=i;
				break;
			}
		}
		for(int i=From;i<=n;++i){
			int id=ma[Q[i].name];
			if(Q[i].type==0 || (Q[i].type==2 && C[id][Q[i].pro-‘A‘])){
				continue;
			}
			else if(Q[i].type==1){
				++B[id][Q[i].pro-‘A‘];
			}
			else{
				C[id][Q[i].pro-‘A‘]=Q[i].t;
				++A[id].solved;
			}
		}
		set_ITER it=S.end(); --it; --it;
		while(1){
			bool allsolved=0;
			while((*it).solved==A[ma[(*it).name]].solved){
				if(it==S.begin()){
					allsolved=1;
					break;
				}
				jt=it; --jt;
				output[++p]=(*it);
				S.erase(it);
				it=jt;
			}
			if(allsolved){
				output[++p]=(*S.begin());
				break;
			}
			data nextFrom;
			if(it!=S.begin()){
				--it;
				nextFrom=(*it);
				++it;
			}
			int id=ma[(*it).name];
			for(int i=0;i<m;++i){
				if(C[id][i]!=E[id][i]){
					E[id][i]=C[id][i];
					data tmp=(*it);
					set_ITER jt=it;
					data __next=*(++jt);
					++tmp.solved;
					tmp.penalty+=(C[id][i]+B[id][i]*20);
					tmp.lasts.push_back(C[id][i]);
					S.erase(it);
					S.insert(tmp);
					it=S.find(tmp);
					++it;
					if((*it).name!=__next.name){
						cout<<tmp.name<<‘ ‘<<(*it).name<<‘ ‘<<tmp.solved<<‘ ‘<<tmp.penalty<<endl;
						it=S.find(nextFrom);
					}
					else{
						--it;
					}
					break;
				}
			}
		}
		for(int i=p,rank=1;i>=1;--i,++rank){
			int id=ma[output[i].name];
			cout<<output[i].name<<‘ ‘<<rank<<‘ ‘<<output[i].solved<<‘ ‘<<output[i].penalty;
			for(int j=0;j<m;++j){
				putchar(‘ ‘);
				if(C[id][j]){
					putchar(‘+‘);
					if(B[id][j]){
						printf("%d",B[id][j]);
					}
				}
				else{
					if(B[id][j]){
						printf("-%d",B[id][j]);
					}
					else{
						putchar(‘.‘);
					}
				}
			}
			puts("");
		}
		for(int i=1;i<=n;++i){
			int id=ma[Q[i].name];
			aftersubs[id][Q[i].pro-‘A‘]=
			B[id][Q[i].pro-‘A‘]=
			C[id][Q[i].pro-‘A‘]=
			E[id][Q[i].pro-‘A‘]=0;
		}
	}
	return 0;
}
时间: 2024-10-13 22:19:45

【模拟】【set】hdu 4789 ICPC Ranking的相关文章

HDU 5437 &amp; ICPC 2015 Changchun Alisha&#39;s Party(优先队列)

Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 7971    Accepted Submission(s): 1833 Description Princess Alisha invites her friends to come to her birthday party. Each of her f

HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 802    Accepted Submission(s): 309 Problem Description A mysterious country will hold a football world championships---Abnormal Cup

【贪心】【模拟】HDU 5491 The Next (2015 ACM/ICPC Asia Regional Hefei Online)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5491 题目大意: 一个数D(0<=D<231),求比D大的第一个满足:二进制下1个个数在[s1,s2]范围内.D已经满足[s1,s2]. 题目思路: [贪心][模拟] 首先将这个数转成二进制统计总共1的个数s,再求出末尾连续0和1的个数n0,n1. 如果最后一位是0: s=s2,那么为了保证s<s2且答案>D,先设ans=d+lowbit(d),此时满足了新的s<s2且答案&g

【模拟】HDU 5752 Sqrt Bo

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5752 题目大意: 定义f(n)=⌊√n⌋,fy(n)=f(fy-1(n)),求y使得fy(n)=1.如果y>5输出TAT.(n<10100) 题目思路: [模拟] 5层迭代是232,所以特判一下层数是5的,其余开根号做.注意数据有0. 队友写的. 1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h&g

【模拟】HDU 5762 Teacher Bo

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 题目大意: 给n个点,坐标范围0~m(n,m<=105),求是否存在2个点对满足哈夫曼距离相等. 题目思路: [模拟] 乍一看n2绝对T了,但是细想之下发现,坐标范围只有105,那么哈夫曼距离最多就2x105种,所以当循环超出这个范围时肯定能找到解(抽屉原理). 1 // 2 //by coolxxx 3 // 4 #include<iostream> 5 #include<a

【模拟】HDU 5774 Where Amazing Happens

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5774 题目大意: 已知1946~2015每一年赢得人是谁,给n个名字,问赢了多少次. 题目思路: [模拟] 打个表就好. 1 #include<stdio.h> 2 #include<string.h> 3 char list[100][35]= 4 {"Cleveland Cavaliers", 5 "Golden State Warriors&quo

模拟斗地主——HDU 4930

对应HDU题目:点击打开链接 Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 986    Accepted Submission(s): 360 Problem Description Fighting the Landlords is a card game which has be

HDOJ(HDU) 2309 ICPC Score Totalizer Software(求平均值)

Problem Description The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business. One of the unique features of this contest is the great number of judges that

(模拟) hdu 1698

Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18763    Accepted Submission(s): 9415 Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing f