1025

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive number N (<=100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (<=300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

Output Specification:

For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

registration_number final_rank location_number local_rank

The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.
Sample Input:

2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85

Sample Output:

9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4

亮点代码:

for(int j=1;j<k;j++)
{
    temp[j].lrank = (temp[j].score == temp[j-1].score) ? temp[j-1].lrank : j+1;
    all.push_back(temp[j]);
}

题解:

#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

struct testee
{
    long long int reg;
    int score;
    int rank;
    int local;
    int lrank;
};


int n,k;
vector<testee> all;

bool cmp(testee c1, testee c2)
{
    return (c1.score != c2.score) ? (c1.score > c2.score) : (c1.reg < c2.reg);
}


int main()
{
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> k;
        vector<testee> temp(k);
        for(int j=0;j<k;j++)
        {
            scanf("%lld %d", &temp[j].reg, &temp[j].score);
            temp[j].local = i+1;
        }
        sort(temp.begin(),temp.end(),cmp);
        temp[0].lrank = 1;
        all.push_back(temp[0]);
        for(int j=1;j<k;j++)
        {
            temp[j].lrank = (temp[j].score == temp[j-1].score) ? temp[j-1].lrank : j+1;
            all.push_back(temp[j]);
        }
    }

    sort(all.begin(),all.end(),cmp);
    all[0].rank = 1;
    for(int i=1;i<all.size();i++)
    {
        all[i].rank = (all[i].score == all[i-1].score) ? all[i-1].rank : i+1;
    }

    cout << all.size() << endl;
    for(int i=0;i<all.size();i++)
    {
        printf("%013lld %d %d %d\n", all[i].reg, all[i].rank, all[i].local, all[i].lrank);
    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL错误1025通常表示出现了死锁问题,也就是多个事务同时请求相同资源导致互相等待。这种情况下,一个事务被阻塞,直到其他事务释放资源。常见的错误信息是 "LOCK wait timeout exceeded"。 解决这个问题的方法可以通过以下步骤来进行: 1. 首先,可以使用以下命令检查当前正在使用的表:`show OPEN TABLES where In_use > 0;`,以及查看当前的进程列表:`show processlist;`。这些命令可以帮助你确定是否有其他的进程正在使用相同的表或资源。 2. 如果第一步没有找到问题所在,可以使用以下命令查询InnoDB锁和等待信息:`SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;`和`SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;`。这些命令可以帮助你查看当前的锁定情况和等待情况。 3. 如果以上步骤还没有找到问题所在,可以参考这篇文章中的方法,使用`select * from information_schema.innodb_trx`命令找到未提交的事务,并通过`kill`命令终止该事务。 通过以上的方法,你应该能够解决MySQL错误1025的问题。如果问题仍然存在,你可能需要进一步检查你的数据库配置和应用程序代码,以确保没有其他潜在的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [MySQL ERROR 1025 - Error on rename of ‘...‘ 和1005 - Can‘t create table ...中可能存在的问题](https://blog.csdn.net/impact_factor/article/details/119843261)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [mysql 1025 LOCK 死锁 解决](https://blog.csdn.net/opopopwqwqwq/article/details/79585010)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值