PAT(A) - 1080. Graduate Admission (30)


It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.

Each applicant will have to provide two grades: the national entrance exam grade GE, and the interview grade GI. The final grade of an applicant is (GE + GI) / 2. The admission rules are:

  • The applicants are ranked according to their final grades, and will be admitted one by one from the top of the rank list.
  • If there is a tied final grade, the applicants will be ranked according to their national entrance exam grade GE. If still tied, their ranks must be the same.
  • Each applicant may have K choices and the admission will be done according to his/her choices: if according to the rank list, it is one's turn to be admitted; and if the quota of one's most preferred shcool is not exceeded, then one will be admitted to this school, or one's other choices will be considered one by one in order. If one gets rejected by all of preferred schools, then this unfortunate applicant will be rejected.
  • If there is a tied rank, and if the corresponding applicants are applying to the same school, then that school must admit all the applicants with the same rank, even if its quota will be exceeded.

Input Specification:

Each input file contains one test case. Each case starts with a line containing three positive integers: N (<=40,000), the total number of applicants; M (<=100), the total number of graduate schools; and K (<=5), the number of choices an applicant may have.

In the next line, separated by a space, there are M positive integers. The i-th integer is the quota of the i-th graduate school respectively.

Then N lines follow, each contains 2+K integers separated by a space. The first 2 integers are the applicant's GE and GI, respectively. The next K integers represent the preferred schools. For the sake of simplicity, we assume that the schools are numbered from 0 to M-1, and the applicants are numbered from 0 to N-1.

Output Specification:

For each test case you should output the admission results for all the graduate schools. The results of each school must occupy a line, which contains the applicants' numbers that school admits. The numbers must be in increasing order and be separated by a space. There must be no extra space at the end of each line. If no applicant is admitted by a school, you must output an empty line correspondingly.

Sample Input:
11 6 3
2 1 2 2 2 3
100 100 0 1 2
60 60 2 3 5
100 90 0 3 4
90 100 1 2 0
90 90 5 1 3
80 90 1 0 2
80 80 0 1 2
80 80 0 1 2
80 70 1 3 2
70 80 1 2 3
100 100 0 2 4
Sample Output:
0 10
3
5 6 7
2 8

1 4

思路分析:一个关于学生录取学校的模拟问题。


#include <cstdio>
#include <vector>
#include <algorithm>

#define MAX 40000

using namespace std;

typedef struct {
    int id;
    int rank;
    int sum;
    int G;
    int E;
    vector<int> choice;
} STU;

typedef struct {
    int id;
    int sum;
    vector<int> student;
    int minRank;
} SCHOOL;

STU stu[MAX];
SCHOOL school[MAX / 400];

int cmp( STU a, STU b ) {
    if( a.sum != b.sum ) {
        return a.sum > b.sum ? 1 : 0;
    }
    if( a.E != b.E ) {
        return a.E > b.E ? 1 : 0;
    }
    return a.id > b.id ? 0 : 1;
}


int main() {
    //freopen( "123.txt", "r", stdin );
    int n, m, k;
    scanf( "%d%d%d", &n, &m, &k );

    for( int i = 0; i < m; i++ ) {
        scanf( "%d", &school[i].sum );
        school[i].id = i;
        school[i].minRank = -1;
    }

    int G, E, c;
    for( int i = 0; i < n; i++ ) {
        scanf( "%d%d", &E, &G );
        stu[i].id = i;
        stu[i].G = G;
        stu[i].E = E;
        stu[i].sum = ( G + E ) / 2;
        for( int j = 0; j < k; j++ ) {
            scanf( "%d", &c );
            stu[i].choice.push_back( c );
        }
    }

    sort( stu, stu + n, cmp );

    int curRank = 1;
    stu[0].rank = curRank;
    for( int i = 1; i < n; i++ ) {
        if( stu[i].sum < stu[i - 1].sum ) {
            curRank = i + 1;
        }
        else if( stu[i].E < stu[i - 1].E ) {
            curRank = i + 1;
        }
        stu[i].rank = curRank;
    }
/*
    for( int i = 0; i < n; i++ ) {
        printf( "id: %d  %d  %d --- rank: %d\n", stu[i].id, stu[i].sum, stu[i].E, stu[i].rank );
    }
*/
    STU curStu;
    for( int i = 0; i < n; i++ ) {
        curStu = stu[i];
        for( int j = 0; j < k; j++ ) {
            int curSelect = curStu.choice[j];
            if( school[curSelect].student.size() >= school[curSelect].sum ) {
                if( school[curSelect].minRank >= curStu.rank ) {
                    school[curSelect].student.push_back( curStu.id );
                    school[curSelect].minRank = curStu.rank;
                    //printf( "%d被school-%d录取\n", stu[i].id, school[curSelect].id );
                    break;
                }
            }
            else {
                school[curSelect].student.push_back( curStu.id );
                school[curSelect].minRank = curStu.rank;
                //printf( "%d被school-%d录取\n", stu[i].id, school[curSelect].id );
                break;
            }
        }
    }

    for( int i = 0; i < m; i++ ) {
        //printf( "%d:", school[i].student.size() );
        sort( school[i].student.begin(), school[i].student.end() );
        for( int j = 0; j < school[i].student.size(); j++ ) {
            if( j == 0 )
                printf( "%d", school[i].student[j] );
            else
                printf( " %d", school[i].student[j] );
        }
        printf( "\n" );
    }

    return 0;
}


11:10:22.921 WARNING: Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-cell-item/u-cell-item.vue' in 'D:\ideaWorkSpace\ehl-wx\applicationCenter\examine' 11:10:22.922 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-cell-item/u-cell-item.vue' in 'D:\ideaWorkSpace\ehl-wx\applicationCenter\pensionResources' 11:10:22.931 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-mask/u-mask.vue' in 'D:\ideaWorkSpace\ehl-wx\pages\service' 11:10:22.936 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-section/u-section.vue' in 'D:\ideaWorkSpace\ehl-wx\applicationCenter\examine' 11:10:22.942 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-section/u-section.vue' in 'D:\ideaWorkSpace\ehl-wx\applicationCenter\knowledgeBase' 11:10:22.946 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-section/u-section.vue' in 'D:\ideaWorkSpace\ehl-wx\pages\notice' 11:10:22.950 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-select/u-select.vue' in 'D:\ideaWorkSpace\ehl-wx\applicationCenter\examine' 11:10:22.957 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-select/u-select.vue' in 'D:\ideaWorkSpace\ehl-wx\applicationCenter\knowledgeBase' 11:10:22.962 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-select/u-select.vue' in 'D:\ideaWorkSpace\ehl-wx\pages\service' 11:10:22.968 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-select/u-select.vue' in 'D:\ideaWorkSpace\ehl-wx\subpages\assessment-admission' 11:10:22.975 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-select/u-select.vue' in 'D:\ideaWorkSpace\ehl-wx\subpages\assessment-orgHomeBed' 11:10:22.975 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-select/u-select.vue' in 'D:\ideaWorkSpace\ehl-wx\subpages\assessment-respiteCare' 11:10:22.983 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-th/u-th.vue' in 'D:\ideaWorkSpace\ehl-wx\applicationCenter\fms' 11:10:22.989 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-upload-enclosure/u-upload-enclosure.vue' in 'D:\ideaWorkSpace\ehl-wx\applicationCenter\examine' 11:10:22.999 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-waterfall/u-waterfall.vue' in 'D:\ideaWorkSpace\ehl-wx\applicationCenter\examine' 11:10:23.006 Module not found: Error: Can't resolve '@/uni_modules/uview-ui/components/u-waterfall/u-waterfall.vue' in 'D:\ideaWorkSpace\ehl-wx\applicationCenter\knowledgeBase'解决
07-14
这些错误提示表明在指定的路径中找不到相应的文件。根据错误信息,文件路径应该是 `@/uni_modules/uview-ui/components/u-cell-item/u-cell-item.vue`、`@/uni_modules/uview-ui/components/u-mask/u-mask.vue`、`@/uni_modules/uview-ui/components/u-section/u-section.vue` 等等。 要解决这个问题,你可以尝试以下几个步骤: 1. 确保你安装了uview-ui组件库,并且已经按照官方文档的要求进行了配置。你可以使用 `npm install uview-ui` 命令来安装uview-ui。 2. 检查你的文件路径是否正确。确保文件路径中的 `@` 符号是正确的,并且文件名的大小写与实际文件名匹配。 3. 确保你在项目中正确导入了需要使用的组件。检查你的代码中是否存在类似以下的导入语句: ```javascript import UCellItem from '@/uni_modules/uview-ui/components/u-cell-item/u-cell-item.vue'; import UMask from '@/uni_modules/uview-ui/components/u-mask/u-mask.vue'; import USection from '@/uni_modules/uview-ui/components/u-section/u-section.vue'; // 其他组件的导入语句... ``` 4. 如果以上步骤都没有解决问题,可以尝试检查uview-ui组件库的版本和你当前项目的版本是否兼容。有时候不同版本之间可能会有文件路径或组件名的变化,需要进行相应的调整。 如果问题仍然存在,建议查看uview-ui的官方文档或在相关社区寻求帮助,以获取更详细的解决方案。同时,提供更多关于你的项目配置和代码的信息,也有助于我提供更准确的帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值