【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:

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 pair<int,string>pr[10007];
 5 bool cmp(pair<int,string>a,pair<int,string>b){
 6     if(a.first!=b.first)
 7         return a.first<b.first;
 8     return a.second>b.second;
 9 }
10 string ans[10007];
11 int main(){
12     ios::sync_with_stdio(false);
13     cin.tie(NULL);
14     cout.tie(NULL);
15     int n,k;
16     cin>>n>>k;
17     for(int i=1;i<=n;++i)
18         cin>>pr[i].second>>pr[i].first;
19     sort(pr+1,pr+1+n,cmp);
20     int m=n;
21     int x=n-n/k*k+n/k;
22     int cnt=x;
23     int temp=0;
24     int t=0;
25     int flag=-1;
26     while(cnt--){
27         ans[x/2+1+temp]=pr[m--].second;
28         if(flag<0)
29             ++t;
30         temp=t*flag;
31         flag=-flag;
32     }
33     int num=x;
34     for(int i=1;i<k;++i){
35         int cnt=n/k;
36         int temp=0;
37         int t=0;
38         int flag=-1;
39         while(cnt--){
40             ans[num+n/k/2+1+temp]=pr[m--].second;
41             if(flag<0)
42                 ++t;
43             temp=t*flag;
44             flag=-flag;
45         }
46         num+=n/k;
47     }
48     for(int i=1;i<=x;++i){
49         cout<<ans[i];
50         if(i<x)
51             cout<<" ";
52         else
53             cout<<"\n";
54     }
55     for(int i=x+1;i<=n;++i){
56         cout<<ans[i];
57         if((i-x)%(n/k))
58             cout<<" ";
59         else if(i<n)
60             cout<<"\n";
61     }
62     return 0;
63 }

原文地址:https://www.cnblogs.com/ldudxy/p/12267290.html

时间: 2024-11-09 13:03:33

【PAT甲级】1109 Group Photo (25分)(模拟)的相关文章

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

题意:n个人,要拍成k行排队,每行 n/k人,多余的都在最后一排. 从第一排到最后一排个子是逐渐增高的,即后一排最低的个子要>=前一排的所有人 每排排列规则如下: 1.中间m/2+1为该排最高: 2.其他人按各自降序顺序,轮流排到中间最高的左边和右边: 举个例子 190 188 186 175 170 - - 190 - - - 188 190 - - - 188 190 186 - 175 188 190 186 - 175 188 190 186 170 3.当个子一样高时,名字按字典序顺序

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

1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connec

PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if

PAT 甲级 1105 Spiral Matrix (25分)(螺旋矩阵,简单模拟)

1105 Spiral Matrix (25分) This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then move in a clockwise spiral. The

PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)

1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Non-palindromic n

PAT 甲级 1028 List Sorting (25 分)(排序,简单题)

1028 List Sorting (25 分)   Excel can sort records according to any column. Now you are supposed to imitate this function. Input Specification: Each input file contains one test case. For each case, the first line contains two integers N (≤) and C, wh

PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)

1063 Set Similarity (25 分)   Given two sets of integers, the similarity of the sets is defined to be /, where N?c?? is the number of distinct common numbers shared by the two sets, and N?t?? is the total number of distinct numbers in the two sets. Yo

【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全部出手的利润.输出最大利润. trick: 测试点2可能包含M不为整数的数据.(尽管题面说明M是正整数,可是根据从前PAT甲级题目的经验,有可能不是整数.....) 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using names

【PAT甲级】1032 Sharing (25分)

1032 Sharing (25分) To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example, loading and being are stored a