题意:

输入两个整数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. nginx中部署前端,后端打成jar包运行

    项目是前后端分离:前端用vue开发,后端用的是springboot开发 会产生跨域问题,故在前端里用了代理 1.本前端项目是用vue开发: 1.1打包:终端 vscode快捷键:crtl+~  然后n ...

  2. c语言 printf格式化输出

    #include <iostream> #include<stdio.h> #include <cstring> using namespace std; int ...

  3. python特性

    # for用法 for i in range(0,100,2): print(i) n = 0 # while用法 while n < 100: print(n) n += 2 else: pr ...

  4. Mvc-WebAPI特性路由(自定义路由)Demo

    Demo由VS2017编写. 1.先建一个WebApi项目 2.WebApiConfig.cs需要注册特性路由,config.MapHttpAttributeRoutes(); 3.项目默认有2个Co ...

  5. Windows系统对拍程序

    Windows系统对拍程序,其中包含c++11用法,请使用c++11标准编译.此对拍程序会在发现错误时显示错误行号以及对应内容,方便比对. 此对拍程序自动使用g++对源代码进行编译.如果出现找不到g+ ...

  6. Linq To Sqlite使用心得

    若要使用Linq To Sqlite类库,可以安装Devart Linq Connect Model,如图: 新建这个Model就可以和Linq To Sql一样使用Linq模型,下载地址:https ...

  7. 【算法】状态压缩DP

    状态压缩DP是什么? 答:利用位运算(位运算比加减乘除都快!)来记录状态,并实现动态规划. 适用于什么问题? 答:数据规模较小:不能使用简单的算法解决. 例题: 题目描述 糖果店的老板一共有M 种口味 ...

  8. Application Server was not connected before run configuration stop, reason: Unable to ping server at localhost:1099

    方法:把catalina.bat 文件中set JAVA_OPTS= -Xmx1024M -Xms512M -XX:MaxPermSize=256m这行去掉,具体看下面两篇博客 https://blo ...

  9. 解决wxpy获取不到指定群聊对象的情况

    我们可以通过Bot.friends 以及Bot.groups 来获取到所有的好友以及聊天群,这里需要注意的是,聊天群需要保存到通讯录中,不然可能会出现找不到聊天群的情况. 摘自:http://www. ...

  10. Python实现求多个集合之间的并集

    目的:求多个集合之前的并集,例如:现有四个集合C1 = {11, 22, 13, 14}.C2  = {11, 32, 23, 14, 35}.C3 = {11, 22, 38}.C4 = {11,  ...