题意:

输入两个整数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分)(模拟)的更多相关文章

  1. 1109 Group Photo (25分)

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  2. PAT甲题题解-1109. Group Photo (25)-(模拟拍照排队)

    题意:n个人,要拍成k行排队,每行 n/k人,多余的都在最后一排. 从第一排到最后一排个子是逐渐增高的,即后一排最低的个子要>=前一排的所有人 每排排列规则如下: 1.中间m/2+1为该排最高: ...

  3. 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 ...

  4. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

  5. PAT甲级——A1109 Group Photo【25】

    Formation is very important when taking a group photo. Given the rules of forming K rows with Npeopl ...

  6. 1109. Group Photo (25)

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  7. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  8. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  9. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

随机推荐

  1. Centos7安装gitlab-ce

    1.官方推荐方式安装 参考https://www.gitlab.com.cn/installation/#centos-7?version=ce sudo yum install -y curl po ...

  2. Django_发邮件

    1. 设置项

  3. (转)git学习教程

    转自:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

  4. Spring Cloud介绍

    Spring Cloud中国社区博客 Spring Cloud发展到2016年,国内关注的人越来越多,但是相应学习交流的平台和材料比较分散,不利于学习交流,因此Spring Cloud中国社区应运而生 ...

  5. WebRTC笔记(一)

    来源<WebRTC权威指南> 1 WebRTC特点 对等连接(Peer Connection):浏览器与浏览器(万维网上的任意两个通信终端)之间的连接(P2P) 信令服务器:在浏览器和对等 ...

  6. Request功能

    1.获取请求消息数据 获取请求行数据 获取请求头数据 获取请求体数据 请求空行没必要获取 1.获取请求行数据 GET /虚拟目录 /servlet路径  ?请求参数 HTTP/1.1 GET/day1 ...

  7. 堆(Heap)和栈(Stack)

    详细可以查看这篇文章:https://www.cnblogs.com/qingtianMo/p/5255121.html 栈保存代码执行(调用)的路径,堆负责保存对象(数据) 栈相当于摞盒子,进入一个 ...

  8. sql server和eclipse连接问题

    最近学习java,需要用的数据库sql sever,这就有一个连接问题需要设置 首先需要下载sql server,可查看我的博客sql sever下载教程: 连接教程:eclipse连接sql ser ...

  9. MYSQL之路练习题

    题目换成求平均薪水的等级最高的部门的部门名称

  10. AcWing 差分一维加二维

    一维 #include<bits/stdc++.h> using namespace std ; ; int n,m; int a[N],b[N]; //a为前缀和,b为差分 差分和前缀和 ...