牛客 - 排序(模拟)
生活随笔
收集整理的這篇文章主要介紹了
牛客 - 排序(模拟)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:點擊查看
題目大意:模擬ACM賽制下每個隊伍的排名,中文題面,不多贅述,規則在原題中講的很清楚了
題目分析:直接模擬即可。。一點坑都沒有,我是因為sort忘記調用cmp函數然后WA了一晚上,哭了,細節決定成敗嗚嗚嗚
代碼:
#include<iostream> #include<cstdlib> #include<string> #include<cstring> #include<cstdio> #include<algorithm> #include<climits> #include<cmath> #include<cctype> #include<stack> #include<queue> #include<list> #include<vector> #include<set> #include<map> #include<sstream> #include<unordered_map> using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=110;struct Problem {bool AC;//是否ACint waste;//罰時int cnt_waste;//錯誤次數int time;//AC時間void cal()//AC后計算內部的數值{cnt_waste++;AC=true;waste+=time;} };struct Node {string name;//姓名(其實賦個值當構造函數用了,不然怕map里不給存)Problem problem[20];//每個題目int time;//總罰時int cnt_AC;//AC數int rank;//排名bool operator<(const Node& a)const//重載小于號用于排序{if(cnt_AC!=a.cnt_AC)return cnt_AC>a.cnt_AC;return time<a.time;}bool operator==(const Node& a)const//重載等于號用于排序和rank更新{return cnt_AC==a.cnt_AC&&time==a.time;} };unordered_map<string,Node>mp;//維護整體的容器bool cmp(pair<string,Node>a,pair<string,Node>b)//排序 {if(a.second==b.second)return a.first<b.first;return a.second<b.second; }int main() { // freopen("input.txt","r",stdin); // ios::sync_with_stdio(false);int w;cin>>w;while(w--){mp.clear();//記得初始化int n,m;cin>>n>>m;for(int i=1;i<=m;i++)//讀入姓名,當初始化了{string s;cin>>s;mp[s].name=s;}int t;cin>>t;while(t--){string name;//姓名int time;//提交時間string pos;//題目string state;//狀態cin>>name>>time>>pos>>state;if(state=="Compilation-Error"||mp[name].problem[pos[0]-'A'].AC)//編譯錯誤或者已經ACcontinue;else if(state=="Accepted")//AC{mp[name].problem[pos[0]-'A'].time=time;mp[name].problem[pos[0]-'A'].cal();mp[name].time+=mp[name].problem[pos[0]-'A'].waste;mp[name].cnt_AC++;}else//WA{mp[name].problem[pos[0]-'A'].waste+=20;mp[name].problem[pos[0]-'A'].cnt_waste++;}}vector<pair<string,Node>>v;copy(mp.begin(),mp.end(),back_inserter(v));//把map扔進vector里方便排序sort(v.begin(),v.end(),cmp);//排序v[0].second.rank=1;for(int i=1;i<v.size();i++)//更新rank{if(v[i].second==v[i-1].second)v[i].second.rank=v[i-1].second.rank;elsev[i].second.rank=i+1;}for(int i=0;i<v.size();i++)//輸出答案{printf("%d %s %d %d",v[i].second.rank,v[i].first.c_str(),v[i].second.cnt_AC,v[i].second.time);for(int j=0;j<n;j++){printf(" %c%d",v[i].second.problem[j].AC?'+':'-',v[i].second.problem[j].cnt_waste);if(v[i].second.problem[j].AC)printf("(%d)",v[i].second.problem[j].time);}printf("\n");}if(w)printf("\n");}return 0; }?
總結
以上是生活随笔為你收集整理的牛客 - 排序(模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牛客 - lglg说要有题,于是便有了题
- 下一篇: 牛客 - 捡金币(思维+二维前缀和+构造