PAT (Advanced Level) 1109. Group Photo (25)
简单模拟。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std; struct X
{
string name;
int h;
} s[+];
int n,k;
vector<int>g[];
int tmp[+]; bool cmp(const X&a,const X&b)
{
if(a.h==b.h) return a.name<b.name;
return a.h>b.h;
} int main()
{
scanf("%d%d",&n,&k);
for(int i=; i<=n; i++)
cin>>s[i].name>>s[i].h;
sort(s+,s+n+,cmp); int t=n+;
for(int i=k; i>=; i--)
{
int m;
if(i>) m=n/k;
else m=n-n/k*(k-);
t=t-m;
int y=t,p=m/+,sz=;
int L,R;
tmp[p]=y++,sz++,L=p-,R=p+;
while()
{
if(sz==m) break;
if(sz%==) tmp[R++]=y++;
else tmp[L--]=y++;
sz++;
}
for(int j=;j<=m;j++) g[i].push_back(tmp[j]); }
for(int i=; i<=k; i++)
{
for(int j=; j<g[i].size(); j++)
{
cout<<s[g[i][j]].name;
if(j<g[i].size()-) printf(" ");
else printf("\n");
}
}
return ;
}
PAT (Advanced Level) 1109. Group Photo (25)的更多相关文章
- 【PAT甲级】1109 Group Photo (25分)(模拟)
题意: 输入两个整数N和K(N<=1e4,K<=10),分别表示人数和行数,接着输入N行每行包括学生的姓名(八位无空格字母且唯一)和身高([30,300]的整数).按照身高逆序,姓名字典序 ...
- 1109 Group Photo (25分)
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- 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 (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT (Advanced Level) 1105. Spiral Matrix (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...
- PAT (Advanced Level) 1101. Quick Sort (25)
树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...
- PAT (Advanced Level) 1071. Speech Patterns (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1063. Set Similarity (25)
读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...
随机推荐
- Wsyscheck(系统检测维护工具) v1.68.33绿色版
软件名称:系统检测维护工具(Wsyscheck) v1.68.33绿色版软件类别:国产软件运行环境:windows软件语言:简体中文授权方式:免费版软件大小:1022 KB软件等级:整理时间:2011 ...
- 关于oracle数据库(1)
兼容性的设置 cmd.exe是微软Windows系统的命令行程序,类似于微软的DOS操作系统.cmd.exe是一个16/32位的命令行程序,运行在Windows NT/2000/XP/2003/Vis ...
- C#采用OpenXml给word里面插入图片
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- db2安装要设置tcp、ip
1.注册表变量DB2COMM是否已经设置了值,是什么级别的?db2set -all | grep -i "DB2COMM" (in unix like os)db2set -all ...
- tomcat的几种配置方式(常用)
https://www.baidu.com url www.baidu.com 主机名 baidu.com 域名 第一种 放在webapp目录下 也可以放在ROOT 根目录下 访问路径 IP:端口 ...
- ios实现文字的自适应
如果你是用xib搭的cell界面 那么cell上面的UIlabel就不能设置宽高 要选择上下左右自适应 并且label的行数设置为0 然后在tableView的代理方法 (UITable ...
- Linux关机命令详解
在linux下一些常用的关机/重启命令有shutdown.halt.reboot.及init,它们都可以达到重启系统的目的,但每个命令的内部工作过程是不同的. Linux centos重启命令: 1. ...
- Hadoop中的一些基本操作
先粗略说一下“hadoop fs”和“hadoop dfs”的区别:fs是各比较抽象的层面,在分布式环境中,fs就是dfs,但在本地环境中,fs是local file system,这个时候dfs不可 ...
- hdu_5044_Tree(树链剖分)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5044 题意:给一棵树,在点和边上操作 题解:树链剖分,剖完后用树状数组维护即可,因为只有加减操作,连树 ...
- putty 默认设置
打开 在 title上 点击 change settings / 或直接打开 设置面板 ,session 写 Default Settings 点击 save OK 另外 在 window- ...