甲乙小朋友的房子

甲乙小朋友很笨,但甲乙小朋友不会放弃

0%

ACM-poj1860-CurrencyExchange

Description

Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies. There can be several points specializing in the same pair of currencies. Each point has its own exchange rates, exchange rate of A to B is the quantity of B you get for 1A. Also each exchange point has some commission, the sum you have to pay for your exchange operation. Commission is always collected in source currency. For example, if you want to exchange 100 US Dollars into Russian Rubles at the exchange point, where the exchange rate is 29.75, and the commission is 0.39 you will get (100 - 0.39) * 29.75 = 2963.3975RUR. You surely know that there are N different currencies you can deal with in our city. Let us assign unique integer number from 1 to N to each currency. Then each exchange point can be described with 6 numbers: integer A and B - numbers of currencies it exchanges, and real RAB, CAB, RBA and CBA - exchange rates and commissions when exchanging A to B and B to A respectively. Nick has some money in currency S and wonders if he can somehow, after some exchange operations, increase his capital. Of course, he wants to have his money in currency S in the end. Help him to answer this difficult question. Nick must always have non-negative sum of money while making his operations.

currency exchange points:货币兑换点 commission:佣金 assign :分配

每个货币兑换点只能互换两种货币。兑换点可重复。每个点都有自己的兑换率,A to B 的兑换率是指1个A能兑换的B的数量。

兑换时收取一定的佣金,佣金是以来源货币来collect的。例如,如果你想将100dolars兑换成Russian Bules, 兑换点的兑换率是29.75,费用是0.39,,那么你会得到的钱是 (100 - 0.39) * 29.75 = 2963.3975RUR.

假设每种兑换的点数量是1-N,那么每个兑换点可以由6个num来描述:

interger A and B 兑换货币的序号 RAB A to B兑换率 CAB A to B 的佣金 RBA B to A 兑换率 CBA B to A 的佣金

Nick有些S货币,他很好奇他能否通过货币兑换的方式对他的资金进行增值。最终他希望他拿到还是S货币。帮他解决这个问题。Nick在这个过程中不能借钱。

Input

The first line of the input contains four numbers: N - the number of currencies, M - the number of exchange points, S - the number of currency Nick has and V - the quantity of currency units he has.

The following M lines contain 6 numbers each - the description of the corresponding exchange point - in specified above order. Numbers are separated by one or more spaces.

1<=S<=N<=100, 1<=M<=100, V is real number, 0<=V<=103.

For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10-2<=rate<=102, 0<=commission<=102.

Let us call some sequence of the exchange operations simple if no exchange point is used more than once in this sequence. You may assume that ratio of the numeric values of the sums at the end and at the beginning of any simple sequence of the exchange operations will be less than 104.

corresponding:相应的

第一行包含四个数字: N 货币的种类 M 兑换点的数量 S Nick的货币的序号 V Nick拥有的钱

接下来的M行,每行包含六个数字,描述相应的兑换点的属性。 数字由一个或多个空格隔开

1<=S<=N<=100, 1<=M<=100, V is real number, 0<=V<=103.

每个兑换点的兑换率和手续费都是实数,至多精确到两位小数。

10-2<=rate<=102, 0<=commission<=102

如果在操作序列中不适用多个兑换点,我们可以发起一些简单的兑换操作。你可以假设:(最后的总和/)

输出数据

如果nick能够实现他的愿望,则输出YES,否则输出NO。

样例输入

3 2 1 20.0 1 2 1.00 1.00 1.00 1.00 2 3 1.10 1.00 1.10 1.00

思路

将货币看做点,每种兑换规则为边,两点的路径长度为兑换后的钱数。建图之后可以看出题意为求图中是否存在正环,用Bellman-Ford求最长路径,如果存在正环输出YES,不存在输出NO。