0
点赞
收藏
分享

微信扫一扫

AcWing 4211. 序列重排

非凡兔 2022-01-16 阅读 56
算法
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;

const int N = 1e3 + 10;
typedef long long ll;
typedef pair<char, int > PII;

int n;
ll get (ll a, ll b) {
	ll res = 0;
	while(a % b == 0) res ++, a /= b;
	return res;
}
struct Node {
	ll x, y, z;
	bool operator< (const Node &q) {
		if (x != q.x) return x < q.x;
		else return y < q.y;
	}
}q[N];
void solve() {
	cin >> n;
	for (int i =1; i<= n; i ++) {
		ll t;
		cin >> t;
		q[i].x = get(t, 2), q[i].y = -get(t, 3), q[i].z = t;
	}
	sort(q+ 1, q + 1 + n);
	for (int i= 1; i<= n; i++) {
		cout << q[i].z << " ";
	}
	puts("");
}
int main () {
	int t;
	t =1;
	while (t --) solve();
	return 0;
} 

从2,3因子的角度想,对于一个合法的序列 xi < xj huo yi > yj && xi==xj 且是唯一的反证法

举报

相关推荐

0 条评论