hdu2093考試排名解題報告---基本演算法(模擬)
考試排名
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19617 Accepted Submission(s): 6788
Problem Description
C++程式設計考試使用的實時提交系統,具有即時獲得成績排名的特點。它的功能是怎麼實現的呢?
我們做好了題目的解答,提交之後,要麼“AC”,要麼錯誤,不管怎樣錯法,總是給你記上一筆,表明你曾經有過一次錯誤提交,因而當你一旦提交該題“AC”後,就要與你算一算帳了,總共該題錯誤提交了幾回。雖然你在題數上,大步地躍上了一個臺階,但是在耗時上要攤上你共花去的時間。特別是,曾經有過的錯誤提交,每次都要攤上一定的單位時間分。這樣一來,你在做出的題數上,可能領先別人很多,但是,在做出同樣題數的人群中,你可能會在耗時上處於排名的劣勢。
例如:某次考試一共8題(A,B,C,D,E,F,G,H),每個人做的題都在對應的題號下有個數量標記,負數表示該學生在該題上有過的錯誤提交次數,但到現在還沒有AC,正數表示AC所耗的時間,如果正數a跟上一對括號,裡面有個整數b,那就表示該學生提交該題AC了,耗去了時間a,同時,曾經錯誤提交了b次,因此對於下述輸入資料:
若每次錯誤提交的罰分為20分,則其排名從高到低應該是這樣的:
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0
Input
輸入資料的第一行是考試題數n(1≤n≤12)以及單位罰分數m(10≤m≤20),每行資料描述一個學生的使用者名稱(不多於10個字元的字串)以及對所有n道題的答題現狀,其描述採用問題描述中的數量標記的格式,見上面的表格,提交次數總是小於100,AC所耗時間總是小於1000。
Output
將這些學生的考試現狀,輸出一個實時排名。實時排名顯然先按AC題數的多少排,多的在前,再按時間分的多少排,少的在前,如果湊巧前兩者都相等,則按名字的字典序排,小的在前。每個學生佔一行,輸出名字(10個字元寬),做出的題數(2個字元寬,右對齊)和時間分(4個字元寬,右對齊)。名字、題數和時間分相互之間有一個空格。
題意:模擬ACM比賽實時排名,優先順序為:解題數 > 所耗時間 > 字典序
雖然是水題,但還是考驗了一下字元處理能力和優先順序定義能力的,最終結果需要重定向檔案讀入才能看。
AC Code:
#include<iostream> #include<sstream> #include<cstdlib> #include<cmath> #include<cctype> #include<algorithm> #include<cstring> #include<cstdio> #include<map> #include<vector> #include<stack> #include<queue> #include<set> #include<list> #define mod 998244353 #define Max 0x3f3f3f3f #define Min 0xc0c0c0c0 #define mst(a) memset(a,0,sizeof(a)) #define f(i,a,b) for(int i=a;i<b;i++) using namespace std; typedef long long ll; const int maxn = 1e6 + 5; int indegree[1005]; struct Node{ char name[15]; int solve, times; }G[1005]; bool cmp(Node a, Node b){ if(a.solve == b.solve){ if(a.times == b.times){ return strcmp(a.name, b.name) < 0; } return a.times < b.times; } return a.solve > b.solve; } int main(){ //ios::sync_with_stdio(false); int n, m; int index = 0; //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); scanf("%d%d", &n, &m); while(scanf("%s", G[index].name) != EOF){ for(int i = 0; i < n; i++){ int v; scanf("%d", &v); if(v > 0){ G[index].times += v; G[index].solve++; char ch = getchar(); if(ch == '('){ scanf("%d", &v); G[index].times += v * m; getchar(); } } } index++; } sort(G, G + index, cmp); for(int i = 0; i < index; i++){ printf("%-10s %2d %4d\n", G[i].name, G[i].solve, G[i].times); } //system("pause"); return 0; }