PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000055. Đầu cơ chênh lệch tỉ giá (Arbitrage)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đầu cơ chênh lệch tỉ giá (Arbitrage)
Arbitrage
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Given exchange rates between every pair of distinct currencies, find the minimum number of exchanges in a closed sequence whose product of rates is strictly greater than 1.01. Print a valid sequence of currency indices, starting and ending at the same currency.
Input
First n; then n lines each containing n-1 positive rates in increasing destination index order, omitting i to i.
Output
Print no arbitrage sequence exists if none. Otherwise output a profitable shortest-length closed sequence of 1-based currency indices, space-separated.
Subtasks
- Subtask 1 (40 points): . Exchange rates are positive decimal values with at most five digits after the decimal point.
- Subtask 2 (60 points): . Exchange rates are positive decimal values with at most five digits after the decimal point.
Examples
Input
3
1.20000 1.00000
0.90000 1.00000
1.00000 1.00000
Output
1 2 1
Explanation
Exchanging 1→2→1 multiplies the amount by 1.2 × 0.9=1.08, greater than 1.01. The two-exchange cycle is shortest.