B1075 PAT Judge(模拟PAT排名)

B1075 PAT Judge (25分)

//debug调好久。。。

  • 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分两种情况

  • 一是提交了代码得不到分数算0分
  • 二是编译不通过-1显示0分

所以不能以总分为0分去判断是否要显示,因为有可能都是编译不通过,但只要提交过一次>=0的分数就能显示。


每个人的每道题的提交情况都单独拿出,从中取每道题的最高成绩

  • If a user has submitted several solutions to solve one problem, then the highest score will be counted.
    如果用户提交了多个解决方案来解决一个问题,则将计算最高分数。

排序避开了这个问题。
最后一个测试样例是有一个人一开始得到了分数,后来提交了一次没有通过编译器的,不能产生覆盖

  • For those who have the same rank, users must be sorted in nonincreasing order according to the number of perfectly solved problems.

排序也比避开了这个问题
同一道题的完美解决数不会随多交几次AC的次数变多。

#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;
}
20882701-9a34810b5fa66467.png
解决了就好

大佬的学习代码

#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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值