题意:
给i c p c比赛的队伍排名。题数高的在前,相同题数用时少的在前,相同题数用时相同的比较a c最后一题的时间、倒数第二题的时间……如果比较完后还是相同,两者排名相同。
输出前n k名的信息。
思路:
存一个结构体里模拟即可,注意不足n k的情况
代码:
#pragma GCC optimize(1) #pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline") #include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<list> #include<unordered_map> //#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll>PLL; typedef pair<int, int>PII; typedef pair<double, double>PDD; #define I_int ll inline ll read(){ll x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;} inline void write(ll x){if (x < 0) x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');} #define read read() #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define multiCase int T;cin>>T;for(int t=1;t<=T;t++) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i<(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define perr(i,a,b) for(int i=(a);i>(b);i--) ll ksm(ll a, ll b,ll mod){ll res = 1;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;} const int maxn=2e5+100,inf=0x3f3f3f3f; struct node{ int id,cnt,time; int cost[25]; int sub[25]; }a[110]; bool vis[110][25]; int wa[110][25]; int main(){ #ifdef LOCAL freopen("in.in","r",stdin); freopen("out.out","w",stdout); #endif int nt=read,np=read,ns=read,nk=read; rep(i,1,nt) a[i].id=i; while(ns--){ int teamid=read,pid=read,subtime=read,op=read; if(vis[teamid][pid]){ continue; } else{ if(op==1){ a[teamid].cnt++; int t=a[teamid].cnt; a[teamid].sub[t]=subtime; a[teamid].cost[t]= wa[teamid][pid]*20+subtime;//a[teamid].sub[t]-a[teamid].sub[t-1]; vis[teamid][pid]=1; a[teamid].time+=wa[teamid][pid]*20+subtime; } else wa[teamid][pid]++; } } for(int i=1;i<=nt;i++){ for(int j=i+1;j<=nt;j++){ if(a[i].cnt<a[j].cnt) swap(a[i],a[j]); else if(a[i].cnt==a[j].cnt){ if(a[i].time>a[j].time) swap(a[i],a[j]); else if(a[i].time==a[j].time){ bool flag=1; for(int k=a[i].cnt;k>=1;k--){ if(a[i].cost[k]<a[j].cost[k]){ flag=0;break; } else if(a[i].cost[k]>a[j].cost[k]){ flag=0;swap(a[i],a[j]);break; } } if(flag){ if(a[i].id>a[j].id) swap(a[i],a[j]); } } } } } /*for(int j=1;j<=nt;j++){ cout<<a[j].id<<" "<<a[j].cnt<<" "<<a[j].time<<endl; for(int i=1;i<=a[j].cnt;i++) cout<<a[j].cost[i]<<" "; puts(""); }*/ int now=1,cnt=0; while(cnt<=nk){ int tmp=1; for(int i=now+1;i<=nt;i++){ if(a[i].cnt==a[now].cnt&&a[i].time==a[now].time){ bool flag=1; for(int j=a[i].cnt;j;j--) if(a[i].cost[j]!=a[now].cost[j]){ flag=0;break; } if(!flag) break; tmp++; } } for(int i=1,j=now;i<=tmp;i++,j++){ //cout<<cnt+1<<" "<<a[j].id<<" "<<a[j].cnt<<" "<<a[j].time<<endl; printf("%-4d%-4d%3d%5d\n",cnt+1,a[j].id,a[j].cnt,a[j].time); // printf("%-4d%-4d%3d%5d\n",cnt+1,a[j].id,a[j],cnt,a[j].time); } now=now+tmp; cnt+=tmp; // cout<<cnt<<endl; if(cnt>=nk) break; } return 0; }