【PAT甲级】1109 Group Photo (25分)(模拟)
题意:
输入两个整数N和K(N<=1e4,K<=10),分别表示人数和行数,接着输入N行每行包括学生的姓名(八位无空格字母且唯一)和身高(【30,300】的整数)。按照身高逆序,姓名字典序升序将学生从高到矮排列,将学生均分为N行输出,最先输出的一行人数包括除不尽的余数学生,每行中间(如果这一行学生人数为偶数则靠右的为中间)的学生最高,然后依次左边一位学生最高,右边一位学生最高,例如190, 188, 186, 175, 170->175, 188, 190, 186, 170。
trick:
把K看成了每行的学生个数而不是行数(竟然能过前三个数据点)。。。。。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
pair<int,string>pr[];
bool cmp(pair<int,string>a,pair<int,string>b){
if(a.first!=b.first)
return a.first<b.first;
return a.second>b.second;
}
string ans[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k;
cin>>n>>k;
for(int i=;i<=n;++i)
cin>>pr[i].second>>pr[i].first;
sort(pr+,pr++n,cmp);
int m=n;
int x=n-n/k*k+n/k;
int cnt=x;
int temp=;
int t=;
int flag=-;
while(cnt--){
ans[x/++temp]=pr[m--].second;
if(flag<)
++t;
temp=t*flag;
flag=-flag;
}
int num=x;
for(int i=;i<k;++i){
int cnt=n/k;
int temp=;
int t=;
int flag=-;
while(cnt--){
ans[num+n/k/++temp]=pr[m--].second;
if(flag<)
++t;
temp=t*flag;
flag=-flag;
}
num+=n/k;
}
for(int i=;i<=x;++i){
cout<<ans[i];
if(i<x)
cout<<" ";
else
cout<<"\n";
}
for(int i=x+;i<=n;++i){
cout<<ans[i];
if((i-x)%(n/k))
cout<<" ";
else if(i<n)
cout<<"\n";
}
return ;
}
【PAT甲级】1109 Group Photo (25分)(模拟)的更多相关文章
- 1109 Group Photo (25分)
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- PAT甲题题解-1109. Group Photo (25)-(模拟拍照排队)
题意:n个人,要拍成k行排队,每行 n/k人,多余的都在最后一排. 从第一排到最后一排个子是逐渐增高的,即后一排最低的个子要>=前一排的所有人 每排排列规则如下: 1.中间m/2+1为该排最高: ...
- PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ord ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- PAT甲级——A1109 Group Photo【25】
Formation is very important when taking a group photo. Given the rules of forming K rows with Npeopl ...
- 1109. Group Photo (25)
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
随机推荐
- 网络编程UDP、TCP详解
网络编程 网络编程主要用于解决计算机与计算机(手机.平板-)之间的数据传输问题. 1.InetAddress(IP类) 方法: 方法 描述 getLocalHost() 获取本机的IP地址对象 ...
- 白面系列 kafka
kafka是一个分布式发布订阅消息系统,也可叫做MQ系统,MQ是Message Queue,消息队列. 通俗点,生产者往队列里写消息,消费者从队列里读.专业点,Producer通过TCP协议发送消息到 ...
- Keep-Alive 以及服务器心跳
Keep-Alive 来源 :http://www.nowamagic.net/academy/detail/23350305 服务器心跳 来源 :http://www.cnblogs.com/lw ...
- 跨站点请求伪造(CSRF、XSRF)
相关文章: 1. http://www.cnblogs.com/xiaoqian1993/p/5816085.html 深入解析跨站请求伪造漏洞:原理剖析 2 .http://blog.csdn.n ...
- [JSOI2016]最佳团体 DFS序/树形DP
题目 洛谷 P4322 [JSOI2016]最佳团体 Description 茜茜的舞蹈团队一共有\(N\)名候选人,这些候选人从\(1\)到\(N\)编号.方便起见,茜茜的编号是\(0\)号.每个候 ...
- 使用acme.sh签发Let's Encrypt的免费数字证书
--------------安装----------------curl https://get.acme.sh | sh#让alias生效source ~/.bashrc ------------- ...
- IE浏览器复选框遍历不兼容问题
obj = document.getElementsByName("userIdCheckbox"); ids = []; for(var k=0;k<obj.length; ...
- FPM 0.08不能运行破解办法……
FPM_0.080.rar 破解办法:用UltraEdit打开FPM.exe,查找"33 C0 E9 F2"(注意中间有空格)将33改为8B,F2改为00
- 从原理到方案,一步步讲解web移动端实现自适应等比缩放
前言 在移动端做自适应,我们常用的有媒体查询,rem ,em,宽度百分比这几种方案.但是都各有其缺点. 首先拿媒体查询来说,在某一个宽度区间内只能使用一种样式,为了适应不同屏幕要,css的代码量就会增 ...
- spring bean 的作用域
spring bean 的作用域: 1.单例(singleton):默认是单例模式,也就是说不管给定的bean被注入到其他bean多少次,注入的都是同一个实例. 2.原型(prototype):每次注 ...