ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

1055 集体照 较复杂

2022-07-11 12:07:09  阅读:149  来源: 互联网

标签:tmp count 1055 复杂 int 集体照 height array tmp3


关键

  1. 双端队列的使用
  2. 数值和字符串的相互映射(有重复值)

代码

#include <iostream>
#include <cstdio>
#include <string>
#include <set>
#include <deque>
#include <algorithm>
using namespace std;

string array[300][2000];
int a[10001];
string h[10001];
string h2[10001];

int main(){

	int n,k;
	int count;
	string name;
	int height;
	multiset<int> st;
	deque<string> dq;
	int tmp3;
	int tmp4=0;
	cin>>n>>k;
	count=n/k;//最后一排: n-count*(k-1)
	for(int i=0;i<n;i++){
		cin>>name>>height;
		tmp3=0;
		while(array[height][tmp3]!=""){
			tmp3++;
		}
		array[height][tmp3]=name;
		for(int j=tmp3;j>=0;j--){
			h[j]=array[height][j];
		}
		sort(h,h+tmp3+1); 
		for(int j=tmp3;j>=0;j--){
			array[height][j]=h[j];
		}
		st.insert(height);
	}
	int tmp=0;
	for(multiset<int>::iterator it=st.begin();it!=st.end();it++){//按身高有序排列 
		a[tmp]=*it;
		while(array[a[tmp]][tmp4]!=""){
			tmp4++;
		}
		h2[tmp]=array[a[tmp]][tmp4-1];
		array[a[tmp]][tmp4-1]="";
		tmp4=0;
		tmp++;
	}

	
	int tmp2;
	for(int i=0;i<k-1;i++){
		tmp2=0;
		for(int j=count-1;j>=0;j--){
			if(tmp2%2==0){
				dq.push_back(h2[i*count+j]);
			}
			else{
				dq.push_front(h2[i*count+j]);
			}
			tmp2++;
		}
		for(int j=0;j<count;j++){
			h2[i*count+j]=dq.front();
			dq.pop_front();
		}
	}
	tmp2=0;
	for(int i=n-1;i>=count*(k-1);i--){	
		if(tmp2%2==0){
			dq.push_back(h2[i]);
		}
		else{
			dq.push_front(h2[i]);
		}
		tmp2++;
	}
	for(int i=count*(k-1);i<n;i++){	
		h2[i]=dq.front();
		dq.pop_front();
	}


	for(int i=count*(k-1);i<=n-1;i++){
		if(i==count*(k-1)){
			cout<<h2[i];
		}
		else{
			cout<<" "<<h2[i];
		}
	}
	cout<<endl;

	for(int i=k-2;i>=0;i--){
		for(int j=0;j<=count-1;j++){
			if(j==0){
				cout<<h2[i*count+j];
			}
			else{
				cout<<" "<<h2[i*count+j];
			}
		}
		if(i!=0){
			cout<<endl;
		}
	}
    return 0;
}

标签:tmp,count,1055,复杂,int,集体照,height,array,tmp3
来源: https://www.cnblogs.com/wodeblog1982/p/16465912.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有