【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 ...
随机推荐
- IDEA模板注释及相关快捷键设置
IDEA模板注释及相关快捷键设置 最近使用IDEA时发现自带的模板注释不怎么好用,因此自己根据网上的教程总结了适合自己的模板设置,可以一键生成类和方法的注释,废话不多说一起看看吧: 第9步的类模板注释 ...
- 5.Dockerfile 定制镜像
概述 Dockerfile 是一个文本文件,其内包含了一条条的 指令(Instruction),每一条指令构建一层,因此每一条指令的内容,就是描述该层应当如何构建. 以之前的 Nginx 镜像为例,这 ...
- Wannafly Camp 2020 Day 2A 托米的字符串
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n; char str[N]; int a ...
- python3练习100题——032
链接:http://www.runoob.com/python/python-exercise-example32.html 题目:按相反的顺序输出列表的值. 我的代码: for i in li[:: ...
- JDBC没有导入驱动jar包
- ❀❀ selenium 学习网站 ★★★★★
http://edu.51cto.com/course/course_id-7320.html Selenium IDE WEB自动化测试入门视频课程(上)(共10课时)_在线自学视频教程_51C ...
- AI赋能抗疫!顶象入选“中关村第二批抗疫新技术新产品新服务清单”
新型冠状病毒疫情仍未到达拐点,要打赢这场疫情攻坚战,不仅需要全国人民共同努力,还要使用科技的手段,用科学来守护大家的安全.对病毒的识别需要运用生物学技术进行基因测序,病患需要依靠医学能力进行救治.与此 ...
- Python连接操作数据库
步骤: 1.创建与数据库的连接对象: 2.创建游标: 3.通过游标执行语句 4.增删改需要提交(commit)数据 5.关闭连接 如: import MySQLdb # Python通过MySQL ...
- java 中使用MD5加密 , 入库时对密码进行加密
import lombok.extern.slf4j.Slf4j; import java.security.MessageDigest; @Slf4j public class MD5Util { ...
- hdu1716 排列2
12 21 123 132 213 231 321 312 .... 每次都将后面n-1位进行全排列.递归的出口当起始坐标等于终止坐标时.需要还原. 设计标记数组.因为需要从小到大输出. #def ...