アットウィキロゴ
Imoのアルゴリズムライブラリ
掲示板 掲示板 ページ検索 ページ検索 メニュー メニュー

Imoのアルゴリズムライブラリ

Max Power … 多倍長整数

最終更新:

imolib

- view
メンバー限定 登録/ログイン

Max Power

問題(Code: MXP)

a1, a2, …, anとb1, b2, …, bnの二つの数列があった時、
akのbk乗が最大になるkを求めよ。
引用: Open 2008 (SPOJ)

入力

The first line of input contains a positive integer n, not greater than 10000. In the second line you are given a set of positive integers ai separated by spaces, and in the third line – integers bi. All numbers in both sequences are not greater than 10000. It is guaranteed that all power values are different.

計算量

O(N)

ソースコード

#include <stdio.h>
#include <math.h>

int n, o, i;
double m, q, a[10001], b[10001];

int main(void) {
	scanf("%d", &n);
	{
		for (i = 1; i <= n; ++i) scanf("%lf", &a[i]);
		for (i = 1; i <= n; ++i) scanf("%lf", &b[i]);
		m = log(a[1]) * b[1]; o = 1;
		for (i = 2; i <= n; ++i) {
			q = log(a[i]) * b[i];
			if (m < q) m = q, o = i;
		}
	}
	printf("%d\n", o);
	return 0;
}

確認

済み
最近更新されたスレッド
ウィキ募集バナー