生活随笔
收集整理的這篇文章主要介紹了
【PAT】B1055 集体照(25 分)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
很簡單的two points問題
##注意:K是行數(shù)
#include<stdio.h>
#include<string.h>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
struct people{char name[10];int height;
}arr[10005];
bool cmp(people A,people B){if(A.height!=B.height) return A.height<B.height;else return strcmp(A.name,B.name)>0;
}
int main(){int N,K;scanf("%d %d",&N,&K);for(int i=0;i<N;i++){//輸入getchar();//吸收上一行的換行符scanf("%s %d",arr[i].name,&arr[i].height);}sort(arr,arr+N,cmp);//排序//讓儲存從下標(biāo)1開始people data[N/K*3];int flag=N-1;for(int i=K;i>=1;i--){//K排int left=1,right=N/K;if(i==K) right=N/K+N%K;int mid=right/2+1;int l=mid-1,r=mid+1;data[mid]=arr[flag--];while(l>=left||r<=right){if(l>=left){data[l--]=arr[flag--];}if(r<=right){data[r++]=arr[flag--];}}for(int j=1;j<=right;j++){if(j!=1) printf(" ");printf("%s",data[j].name);if(j==right&&i!=1) printf("\n");}}getchar();return 0;
}
轉(zhuǎn)載于:https://www.cnblogs.com/hebust/p/9496797.html
總結(jié)
以上是生活随笔為你收集整理的【PAT】B1055 集体照(25 分)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。