B1075 PAT Judge (25分)
//debug調(diào)好久亩鬼。击费。蝗蛙。
- For those who has never submitted any solution that can pass the compiler, or has never submitted any solution, they must NOT be shown on the ranklist.
對于從未提交過任何可以通過編譯器的解決方案或從未提交過任何解決方案的人蚜厉,它們不能顯示在ranklist上揪漩。
ranklist里各題顯示0分兩種情況
- 一是提交了代碼得不到分數(shù)算0分
- 二是編譯不通過-1顯示0分
所以不能以總分為0分去判斷是否要顯示,因為有可能都是編譯不通過,但只要提交過一次>=0的分數(shù)就能顯示乘陪。
每個人的每道題的提交情況都單獨拿出统台,從中取每道題的最高成績
- If a user has submitted several solutions to solve one problem, then the highest score will be counted.
如果用戶提交了多個解決方案來解決一個問題,則將計算最高分數(shù)啡邑。
排序避開了這個問題贱勃。
最后一個測試樣例是有一個人一開始得到了分數(shù),后來提交了一次沒有通過編譯器的谤逼,不能產(chǎn)生覆蓋
- For those who have the same rank, users must be sorted in nonincreasing order according to the number of perfectly solved problems.
排序也比避開了這個問題
同一道題的完美解決數(shù)不會隨多交幾次AC的次數(shù)變多贵扰。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int MAX=10005;
const int INF=0x3f3f3f3f;
const int mod=1000000007;
struct nodeper
{
int userid;
int num;
int total;
int Sumbit;
int score;
int Rank;
int accept;
}temp;
int score[MAX];
int book[MAX];
int mp[MAX][11];
int idtonum[MAX][11];
int submit[MAX];
map<int,int>tol;
map<int,int>ac;
vector<nodeper>vt[MAX];
bool cmp(nodeper a,nodeper b)
{
if(a.num!=b.num)
return a.num<b.num;
else if(a.score!=b.score)
return a.score>b.score;
}
bool cmp2(nodeper a,nodeper b)
{
if(a.total!=b.total)
return a.total>b.total;
else if(a.accept!=b.accept)
return a.accept>b.accept;
else
return a.userid<b.userid;
}
int main()
{
int n,k,m;
scanf("%d%d%d",&n,&k,&m);
memset(idtonum,0,sizeof(idtonum));
memset(submit,0,sizeof(submit));
for(int i=1;i<=k;i++)
{
scanf("%d",&score[i]);
}
for(int i=0;i<m;i++)
{
int id,num,score;
scanf("%d%d%d",&id,&num,&score);
temp.num=num;
temp.score=score;
temp.userid=id;
vt[id].push_back(temp);
}
for(int i=1;i<=n;i++)
{
memset(book,0,sizeof(book));
sort(vt[i].begin(),vt[i].end(),cmp);
for(int j=0;j<vt[i].size();j++)
{
if(book[vt[i][j].num]==0)
{
if(vt[i][j].score==score[vt[i][j].num])
{
ac[vt[i][j].userid]++;
}
if(vt[i][j].score>=0)
{
submit[vt[i][j].userid]=1;
}
else if(vt[i][j].score==-1)
vt[i][j].score=0;
mp[vt[i][j].userid][vt[i][j].num]=vt[i][j].score;
tol[vt[i][j].userid]+=vt[i][j].score;
idtonum[vt[i][j].userid][vt[i][j].num]=1;
book[vt[i][j].num]=1;
}
}
}
vector<nodeper>st;
for(int i=1;i<=n;i++)
{
nodeper res;
res.userid=i;
res.Sumbit=submit[i];
res.total=tol[i];
res.accept=ac[i];
st.push_back(res);
}
sort(st.begin(),st.end(),cmp2);
for(int i=0;i<st.size();i++)
{
if(st[i].Sumbit==1)
{
if(i==0)
{
st[i].Rank=1;
cout<<"1";
}
else
{
if(st[i].total==st[i-1].total)
{
st[i].Rank=st[i-1].Rank;
cout<<st[i].Rank;
}
else
{
st[i].Rank=i+1;
cout<<i+1;
}
}
printf(" %05d",st[i].userid);
cout<<" "<<st[i].total;
for(int j=1;j<=k;j++)
{
if(idtonum[st[i].userid][j]==0)
cout<<" -";
else
cout<<" "<<mp[st[i].userid][j];
}
cout<<endl;
}
}
return 0;
}
大佬的學習代碼
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct node {
int rank, id, total = 0;
vector<int> score;
int passnum = 0;
bool isshown = false;
};
bool cmp1(node a, node b) {
if(a.total != b.total)
return a.total > b.total;
else if(a.passnum != b.passnum)
return a.passnum > b.passnum;
else
return a.id < b.id;
}
int main() {
int n, k, m, id, num, score;
scanf("%d %d %d", &n, &k, &m);
vector<node> v(n + 1);
for(int i = 1; i <= n; i++)
v[i].score.resize(k + 1, -1);
vector<int> full(k + 1);
for(int i = 1; i <= k; i++)
scanf("%d", &full[i]);
for(int i = 0; i < m; i++) {
scanf("%d %d %d", &id, &num, &score);
v[id].id = id;
v[id].score[num] = max(v[id].score[num], score);
if(score != -1)
v[id].isshown = true;
else if(v[id].score[num] == -1)
v[id].score[num] = -2;
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= k; j++) {
if(v[i].score[j] != -1 && v[i].score[j] != -2)
v[i].total += v[i].score[j];
if(v[i].score[j] == full[j])
v[i].passnum++;
}
}
sort(v.begin() + 1, v.end(), cmp1);
for(int i = 1; i <= n; i++) {
v[i].rank = i;
if(i != 1 && v[i].total == v[i - 1].total)
v[i].rank = v[i - 1].rank;
}
for(int i = 1; i <= n; i++) {
if(v[i].isshown == true) {
printf("%d %05d %d", v[i].rank, v[i].id, v[i].total);
for(int j = 1; j <= k; j++) {
if(v[i].score[j] != -1 && v[i].score[j] != -2)
printf(" %d", v[i].score[j]);
else if(v[i].score[j] == -1)
printf(" -");
else
printf(" 0");
}
printf("\n");
}
}
return 0;
}