2496: 【普及+/提高】【P1080】国王游戏

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:1 解决:1

题目描述

恰逢 H 国国庆,国王邀请 lns="http://www.w3.org/1998/Math/MathML"> 位大臣来玩一个有奖游戏。首先,他让每个大臣在左、右手上面分别写下一个整数,国王自己也在左、右手上各写一个整数。然后,让这 lns="http://www.w3.org/1998/Math/MathML"> 位大臣排成一排,国王站在队伍的最前面。排好队后,所有的大臣都会获得国王奖赏的若干金币,每位大臣获得的金币数分别是:排在该大臣前面的所有人的左手上的数的乘积除以他自己右手上的数,然后向下取整得到的结果。

国王不希望某一个大臣获得特别多的奖赏,所以他想请你帮他重新安排一下队伍的顺序,使得获得奖赏最多的大臣,所获奖赏尽可能的少。注意,国王的位置始终在队伍的最前面。

输入

第一行包含一个整数 lns="http://www.w3.org/1998/Math/MathML">,表示大臣的人数。

第二行包含两个整数 lns="http://www.w3.org/1998/Math/MathML"> 和 lns="http://www.w3.org/1998/Math/MathML">,之间用一个空格隔开,分别表示国王左手和右手上的整数。

接下来 lns="http://www.w3.org/1998/Math/MathML"> 行,每行包含两个整数 lns="http://www.w3.org/1998/Math/MathML"> 和 lns="http://www.w3.org/1998/Math/MathML">,之间用一个空格隔开,分别表示每个大臣左手和右手上的整数。

输出

一个整数,表示重新排列后的队伍中获奖赏最多的大臣所获得的金币数。

样例输入 复制

3 
1 1 
2 3 
7 4 
4 6 

样例输出 复制

2

提示

【输入输出样例说明】

按 lns="http://www.w3.org/1998/Math/MathML">1lns="http://www.w3.org/1998/Math/MathML">2lns="http://www.w3.org/1998/Math/MathML">3 这样排列队伍,获得奖赏最多的大臣所获得金币数为 lns="http://www.w3.org/1998/Math/MathML">2

按 lns="http://www.w3.org/1998/Math/MathML">1lns="http://www.w3.org/1998/Math/MathML">3lns="http://www.w3.org/1998/Math/MathML">2 这样排列队伍,获得奖赏最多的大臣所获得金币数为 lns="http://www.w3.org/1998/Math/MathML">2

按 lns="http://www.w3.org/1998/Math/MathML">2lns="http://www.w3.org/1998/Math/MathML">1lns="http://www.w3.org/1998/Math/MathML">3 这样排列队伍,获得奖赏最多的大臣所获得金币数为 lns="http://www.w3.org/1998/Math/MathML">2

lns="http://www.w3.org/1998/Math/MathML">2lns="http://www.w3.org/1998/Math/MathML">3lns="http://www.w3.org/1998/Math/MathML">1这样排列队伍,获得奖赏最多的大臣所获得金币数为 lns="http://www.w3.org/1998/Math/MathML">9

按 lns="http://www.w3.org/1998/Math/MathML">3lns="http://www.w3.org/1998/Math/MathML">1lns="http://www.w3.org/1998/Math/MathML">2这样排列队伍,获得奖赏最多的大臣所获得金币数为 lns="http://www.w3.org/1998/Math/MathML">2

lns="http://www.w3.org/1998/Math/MathML">3lns="http://www.w3.org/1998/Math/MathML">2lns="http://www.w3.org/1998/Math/MathML">1 这样排列队伍,获得奖赏最多的大臣所获得金币数为 lns="http://www.w3.org/1998/Math/MathML">9

因此,奖赏最多的大臣最少获得 lns="http://www.w3.org/1998/Math/MathML">2 个金币,答案输出 lns="http://www.w3.org/1998/Math/MathML">2

【数据范围】

对于 lns="http://www.w3.org/1998/Math/MathML">20% 的数据,有 lns="http://www.w3.org/1998/Math/MathML">110,0<,<8

对于 lns="http://www.w3.org/1998/Math/MathML">40% 的数据,有lns="http://www.w3.org/1998/Math/MathML">120,0<,<8

对于 lns="http://www.w3.org/1998/Math/MathML">60% 的数据,有 lns="http://www.w3.org/1998/Math/MathML">1100

对于 lns="http://www.w3.org/1998/Math/MathML">60% 的数据,保证答案不超过 lns="http://www.w3.org/1998/Math/MathML">109

对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,有 lns="http://www.w3.org/1998/Math/MathML">11,000,0<,<10000

NOIP 2012 提高组 第一天 第二题

#include<bits/stdc++.h>
using namespace std;
struct people {
	int a,b;
}ps[10005];
bool cmp (people p1,people p2) {
	return p1.a*p1.b < p2.a*p2.b;
}
int s[1000000] = {1}, ans[1000000],slen=1;
void mul(int n);
void div(int n);
void print();
int main(){
    int n;
    cin >> n;
    for (int i = 0; i <= n; i++) cin >> ps[i].a >> ps[i].b;
    sort(ps+1,ps+n+1,cmp);
    for (int i = 0; i < n; i++) {
    	mul(ps[i].a);
	}
	div(ps[n].b);
	print();
	return 0;
}
void mul(int n) {
	int tem=0;
	for (int i = 0; i < slen; i++) s[i]*=n;
	for (int i = 0; i < slen; i++) {
		tem = tem + s[i];
		s[i] = tem % 10;
		tem /= 10;
	}
	while (tem !=0 ) {
		s[slen] = tem % 10;
		slen++;
		tem /=10;
	}
	return;
}
void div(int n) {
	int tem=0;
	for (int i = slen-1; i >=0 ; i--) {
		tem = tem * 10 + s[i];
		ans[i] = tem / n;
		tem %= n;
	}
	return;
}
void print() {
	int tmp = slen;
	while (ans[tmp] == 0) {
		tmp--;
		if (tmp == -1) {
			cout << 1;
			return;
		}
	}
	for (int i = tmp; i >=0 ; i--) {
		cout << ans[i];
	}
	return;
}