【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 ...
随机推荐
- 终极教程【zhong】
just for a better future! 资源教程 aiim 综合类 前端知识体系 前端知识结构 Web前端开发大系概览 We ...
- layui表单之单选框提交
<div class="layui-form-item"> <label class="layui-form-label">状态< ...
- SQL中 select count(1) count中的1 到底是什么意思呢?和count(*)的区别
count(1),其实就是计算一共有多少符合条件的行. 1并不是表示第一个字段,而是表示一个固定值.其实就可以想成表中有这么一个字段,这个字段就是固定值1,count(1),就是计算一共有多少个1.同 ...
- php设计模式之简单工厂模式代码实例
<?php header("Content-type:text/html;charset=utf-8"); /** * 共同接口 */ interface db { func ...
- php设计模式之多态实例代码
<?php header("Content-type:text/html;charset=utf-8"); /** * 虎 */ abstract class Tiger { ...
- Flink流处理(四)- 时间语义
4. 时间语义(Time Semantics) 这章我们会介绍时间语义,以及在流中,对于时间的各种不同的概念的描述.同时我们也会讨论一个流处理器在事件乱序的情况下,如何能提供精准的结果,以及如何使用流 ...
- 阻塞队列BlockingQueue之LinkedBlokingQueue
1.简介 LinkedBlokingQueue 是链表实现的有界阻塞队列,此队列的默认和最大长度为 Integer.MAX_VALUE.此队列按照先进先出的原则对元素进行排序.ArrayList和Ar ...
- 隐藏wordpress版本信息
在主题中的functions.php中添加如下代码: remove_action( 'wp_head', 'wp_generator');
- 小程序websocket用法
// socket已经连接成功 var socketOpen = false // socket已经调用关闭function var socketClose = false // socket发送的消 ...
- 【vue】 router.beforeEach
import store from '@/store' const Vue = require('vue') const Router = require('vue-router') Vue.use( ...