Posted on 2010-08-07 17:33
MiYu 閱讀(1096)
評(píng)論(2) 編輯 收藏 引用 所屬分類(lèi):
ACM ( 串 ) 、
ACM ( 雜題 )
MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋
題目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=2093
題目描述:
Problem Description
C++編程考試使用的實(shí)時(shí)提交系統(tǒng),具有即時(shí)獲得成績(jī)排名的特點(diǎn)。它的功能是怎么實(shí)現(xiàn)的呢?
我們做好了題目的解答,提交之后,要么“AC”,要么錯(cuò)誤,不管怎樣錯(cuò)法,總是給你記上一筆,表明你曾經(jīng)有過(guò)一次錯(cuò)誤提交,因而當(dāng)你一旦提交該題“AC”后,就要與你算一算帳了,總共該題錯(cuò)誤提交了幾回。雖然你在題數(shù)上,大步地躍上了一個(gè)臺(tái)階,但是在耗時(shí)上要攤上你共花去的時(shí)間。特別是,曾經(jīng)有過(guò)的錯(cuò)誤提交,每次都要攤上一定的單位時(shí)間分。這樣一來(lái),你在做出的題數(shù)上,可能領(lǐng)先別人很多,但是,在做出同樣題數(shù)的人群中,你可能會(huì)在耗時(shí)上處于排名的劣勢(shì)。
例如:某次考試一共8題(A,B,C,D,E,F(xiàn),G,H),每個(gè)人做的題都在對(duì)應(yīng)的題號(hào)下有個(gè)數(shù)量標(biāo)記,負(fù)數(shù)表示該學(xué)生在該題上有過(guò)的錯(cuò)誤提交次數(shù),但到現(xiàn)在還沒(méi)有AC,正數(shù)表示AC所耗的時(shí)間,如果正數(shù)a跟上一對(duì)括號(hào),里面有個(gè)整數(shù)b,那就表示該學(xué)生提交該題AC了,耗去了時(shí)間a,同時(shí),曾經(jīng)錯(cuò)誤提交了b次,因此對(duì)于下述輸入數(shù)據(jù):
若每次錯(cuò)誤提交的罰分為20分,則其排名從高到低應(yīng)該是這樣的:
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0
Input
輸入數(shù)據(jù)的第一行是考試題數(shù)n(1≤n≤12)以及單位罰分?jǐn)?shù)m(10≤m≤20),每行數(shù)據(jù)描述一個(gè)學(xué)生的用戶(hù)名(不多于10個(gè)字符的字串)以及對(duì)所有n道題的答題現(xiàn)狀,其描述采用問(wèn)題描述中的數(shù)量標(biāo)記的格式,見(jiàn)上面的表格,提交次數(shù)總是小于100,AC所耗時(shí)間總是小于1000。
Output
將這些學(xué)生的考試現(xiàn)狀,輸出一個(gè)實(shí)時(shí)排名。實(shí)時(shí)排名顯然先按AC題數(shù)的多少排,多的在前,再按時(shí)間分的多少排,少的在前,如果湊巧前兩者都相等,則按名字的字典序排,小的在前。每個(gè)學(xué)生占一行,輸出名字(10個(gè)字符寬),做出的題數(shù)(2個(gè)字符寬,右對(duì)齊)和時(shí)間分(4個(gè)字符寬,右對(duì)齊)。名字、題數(shù)和時(shí)間分相互之間有一個(gè)空格。
Sample Input
8 20
Smith -1 -16 8 0 0 120 39 0
John 116 -2 11 0 0 82 55(1) 0
Josephus 72(3) 126 10 -3 0 47 21(2) -2
Bush 0 -1 -8 0 0 0 0 0
Alice -2 67(2) 13 -1 0 133 79(1) -1
Bob 0 0 57(5) 0 0 168 -7 0
Sample Output
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0
題目分析 :
純粹考驗(yàn)編程能力的題, 就交給自己隊(duì)里的代碼牛人解決吧 , 主要是使用 sscanf () 用于判斷 有沒(méi)有括號(hào).
代碼如下:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAX 1000
typedef struct
{
char name[11];
int sum;
int total;
}credit;
int cmp(const void *a, const void *b)
{
if ((*(credit *)a).total != (*(credit *)b).total)
return (*(credit *)a).total - (*(credit *)b).total;
else if ((*(credit *)b).sum != (*(credit *)a).sum)
return (*(credit *)b).sum - (*(credit *)a).sum;
else
return strcmp((*(credit *)b).name, (*(credit *)a).name);
}
int main()
{
int res, t, f;
int i, n, m, j;
char style[10];
credit c[MAX] = {0};
scanf ( "%d%d", &n, &m );
for ( i = 0; scanf("%s", c[i].name) != EOF; i++ )
{
for ( j = 0; j < n; j++ )
{
scanf ( "%s", style );
res = sscanf(style, "%d(%d)", &t, &f );
if ( res == 2 )
{
c[i].total++;
c[i].sum += t + f * m;
}
else if (res == 1 && t > 0)
{
c[i].total++;
c[i].sum += t;
}
}
}
qsort(c, i, sizeof(credit), cmp);
for ( i--; i >= 0; i-- )
{
printf("%-10s %2d %4d\n", c[i].name, c[i].total, c[i].sum);
}
return 0;
}