跳到正文

题解

出题人完全不会给题目起名字 题解

Melo.VVちゃん约 3 分钟
原文

这是 2026年2月25日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年2月13日
收录
2026年2月25日
更新
2026年11月12日
篇幅
约 3 分钟

版本

  1. v2当前
  2. v1

我们观察第一次操作之后序列会变成什么样子,显然是形如:

a1aj,a2aj…1…anaj\frac{a_1}{a_j},\frac{a_2}{a_j}\dots1\dots\frac{a_n}{a_j}

然后我们发现,如果再进行一次操作,比如这次我们选择的下标是 kk,那么序列会变成:

a1ak,a2ak…1…anak\frac{a_1}{a_k},\frac{a_2}{a_k}\dots1\dots\frac{a_n}{a_k}

不难发现,如果我们需要第二次操作的结果,在第一次就可以直接做到。

所以有结论至多操作一次,操作完一次之后序列的 min⁡\min 最小是 min⁡iaimax⁡iai\frac{\min_i a_i}{\max_i a_i}。

视实现的精细程度可以做到 O(n)O(n) 或者 O(nlog⁡n)O(n\log n),不过我好像不太精细。

C++
#include "bits/stdc++.h"
#define int long long 
#define f(i ,m ,n ,x) for (int i = (m) ; i <= (n) ; i += (x))

using arr = std :: array < int ,2 > ;
const int N = 1e6 + 25 ;
int n ;
std :: basic_string < arr > ps ;

signed main (void) {
	std :: ios  :: sync_with_stdio (false) ,
	std :: cin.tie (nullptr) ,std :: cout.tie (nullptr) ;
	
	std :: cin >> n ; 
    assert (n <= 1000000) ;
    f (i ,1 ,n ,1) {
		int x ,y ; std :: cin >> x >> y ;
        assert (x > 0 && x <= 1000000000 && y > 0 && y <= 1000000000) ;
		int d = std :: __gcd (x ,y) ; x /= d ,y /= d ;
		ps += (arr){x ,y} ;
	}
	
	std :: sort (ps.begin () ,ps.end () ,[] (const arr &x ,const arr &y) 
	{ return x[0] * y[1] > y[0] * x[1] ;}) ;
	
	arr ans = *ps.begin () ;
	if (ans[0] <= ans[1]) {
		ans = *ps.rbegin () ;
		std :: cout << ans[0] << ' ' << ans[1] << '\n' ;
	} else {
		arr tmp = *ps.rbegin () ;
		int x = tmp[0] * ans[1] ,y = tmp[1] * ans[0] ;
		int d = std :: __gcd (x ,y) ; x /= d ,y /= d ;
		std :: cout << x << ' ' << y << '\n' ;
	}
	return 0 ;
}