PAT 1109 Group Photo (25 分)

题意:

拍照片,让你根据升高排队,题好难读。

思路:

sort一遍,我把行列搞错了...  ...  ...以致数组大小估计错误。

代码:

#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stack>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int N = 1e4+50;
const double eps = 1.e-8;

int n, hei, k;
char x[10];
struct node {
    int h;
    char name[10];
}a[N];
int c[N];

bool cmp (node aa, node bb) {
    if (aa.h == bb.h)
        return strcmp(aa.name, bb.name) < 0;
    return aa.h > bb.h;
}

int main() {
    cin>>n>>k;
    for (int i = 0; i < n; i++) {
        scanf("%s%d", &x, &hei);
        a[i].h = hei;
        strcpy(a[i].name, x);
    }
    sort(a, a+n, cmp);
    //for (int i = 0; i < n; i++) cout<<a[i].name<<" "<<a[i].h<<endl;
    int lie = n / k;
    int res = n % lie;
    int th = 0;
    for (int i = 0; i < k; i++) {//made a mistake in row and column. takes me more than 25 minutes to check
        int r = lie;
        if (i < res) r++;
        int left = r/2+1;
        int right = r/2+1;
        int j = 0;
        for(int p = 0; p < r; p++) {
            if (j == 0) {
                c[right++] = th++;
                j = 1;
            }
            else {
                c[--left] = th++;
                j = 0;
            }
        }
        for (int p = 1; p <= r; p++) {//注意这里开一维的,二维1e4 * 1e4要炸,要么用容器
            int q = c[p];
            printf("%s", a[q].name);
            if (p == r) printf("\n");
            else printf(" ");
        }
    }

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值