【PAT甲级】1080 Graduate Admission (30 分)
题意:
输入三个正整数N,M,K(N<=40000,M<=100,K<=5)分别表示学生人数,可供报考学校总数,学生可填志愿总数。接着输入一行M个正整数表示从0到M-1每所学校招生人数,N行数据分别包括两个成绩和K个志愿。输出M行依照平行志愿原则输出每所学校录取的学生序号,如果成绩相同,可以突破计划招生人数。
trick:
不是很懂为什么当我输出的时候采用if(i>0)cout<<"\n";会导致测试点2和4格式错误。。。。。
发现最后一行必须要换行。。。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct student{
int x,y;
int id;
int c[];
};
student d[];
int a[];
int b[];
vector<int>ans[];
bool cmp(student a,student b){
if(a.x+a.y!=b.x+b.y)
return a.x+a.y>b.x+b.y;
return a.x>b.x;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m,k;
cin>>n>>m>>k;
for(int i=;i<m;++i)
cin>>a[i];
for(int i=;i<n;++i){
cin>>d[i].x>>d[i].y;
for(int j=;j<=k;++j)
cin>>d[i].c[j];
d[i].id=i;
}
sort(d,d+n,cmp);
int tamp=-;
for(int i=;i<n;++i){
if(i>&&d[i].x+d[i].y<d[i-].x+d[i-].y)
tamp=-;
for(int j=;j<=k;++j){
if(a[d[i].c[j]]){
--a[d[i].c[j]];
ans[d[i].c[j]].push_back(d[i].id);
tamp=d[i].c[j];
break;
}
else if(d[i].c[j]==tamp&&d[i].y==d[i-].y&&d[i].x==d[i-].x){
ans[tamp].push_back(d[i].id);
break;
}
}
}
for(int i=;i<m;++i)
sort(ans[i].begin(),ans[i].end());
for(int j=;j<ans[].size();++j){
if(j>)
cout<<" ";
cout<<ans[][j];
}
for(int i=;i<m;++i){
cout<<"\n";
for(int j=;j<ans[i].size();++j){
if(j>)
cout<<" ";
cout<<ans[i][j];
}
}
cout<<endl;
return ;
}
【PAT甲级】1080 Graduate Admission (30 分)的更多相关文章
- PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)
1080 Graduate Admission (30 分) It is said that in 2011, there are about 100 graduate schools ready ...
- pat 甲级 1080. Graduate Admission (30)
1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- PAT甲级1080 Graduate Admission【模拟】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805387268571136 题意: 模拟高考志愿录取. 考生根据总 ...
- PAT 甲级 1072 Gas Station (30 分)(dijstra)
1072 Gas Station (30 分) A gas station has to be built at such a location that the minimum distance ...
- PAT 甲级 1049 Counting Ones (30 分)(找规律,较难,想到了一点但没有深入考虑嫌麻烦)***
1049 Counting Ones (30 分) The task is simple: given any positive integer N, you are supposed to co ...
- PAT 甲级 1030 Travel Plan (30 分)(dijstra,较简单,但要注意是从0到n-1)
1030 Travel Plan (30 分) A traveler's map gives the distances between cities along the highways, to ...
- PAT 甲级 1026 Table Tennis (30 分)(坑点很多,逻辑较复杂,做了1天)
1026 Table Tennis (30 分) A table tennis club has N tables available to the public. The tables are ...
- PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
- PAT 1080. Graduate Admission (30)
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...
随机推荐
- DTU DeepLearning: exercise 6
Does batch_size have any affects in results quality? how to set the optimal batch size and number ...
- pygame 浅解
import pygame from first_pygame.plane_spirit import * # 调用重载的精灵类 # 初始化 pygame.init() # 初始化所有所需游戏模块 s ...
- 剑指offer 面试题. 按之字形顺序打印二叉树
题目描述 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推. 方法1: 正常层次遍历,利用普通队列.逢 ...
- Json.Net的介绍与简单实用(兼容2.0/3.0/3.5/4.5/RT)
本文的前提是你已经熟悉Json,如果您还不知道什么是Json是什么,请自行查看维基百科. 一.Json.Net是什么? Json.Net是一个读写Json效率比较高的.Net框架.Json.Net 使 ...
- js加密(二)文书获取
时间原因直接上代码,有空再解释. js代码: //var tm=new Array(1) //tm[0]=e; ////tm[1]="%u5e72%u82e5%u4f5c%u5de5%u88 ...
- 如何查看mac多少位的操作系统?
1.点击工具栏左上角点击 (苹果Logo)标志,关于本机 --> 更多信息 --> 系统报告 -->(左侧栏中)软件 (有的电脑是没有的例如第一张图) 2. 输入命令 una ...
- 微信环境中如何实现跳转到手机默认外部浏览器下载apk文件
由于微信的限制,应用文件在内置浏览器中下载全部被屏蔽掉,造成很多人用微信扫描二维码下载时点击下载按钮没反应,我想到的是做一个提示用户在浏览器中打开下载.其实原来很简单,就是判断当前是在微信内置浏览器中 ...
- JavaScript错误-throw、try和catch
try 语句测试代码块的错误. catch 语句处理错误. throw 语句创建自定义错误. finally 语句在 try 和 catch 语句之后,无论是否有触发异常,该语句都会执行. JavaS ...
- MaxM2引擎各种人物触发脚本
捡起物品触发@PickUpItem[@PickUpItem]#if#actSENDMSG 5 [%s]在[%m(%x,%y)]捡起物品[<$STR(E2)>] 精炼成功触发@REFINEM ...
- MyBatis Generator 超详细配置
想快速开始,请直接拉到最后,看整体配置. MyBatis Generator 是 MyBatis 提供的一个代码生成工具.可以帮我们生成 表对应的持久化对象(po).操作数据库的接口(dao).CRU ...