Aroma's Search(暴力)
THE SxPLAY & KIVΛ - 漂流
KIVΛ & Nikki Simmons - Perspectives
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 00, with their coordinates defined as follows:
The coordinates of the 00-th node is (x0,y0)(x0,y0)
For i>0i>0, the coordinates of ii-th node is (ax?xi?1+bx,ay?yi?1+by)(ax?xi?1+bx,ay?yi?1+by)
Initially Aroma stands at the point (xs,ys)(xs,ys). She can stay in OS space for at most tt seconds, because after this time she has to warp back to the real world. She doesn’t need to return to the entry point (xs,ys)(xs,ys) to warp home.
While within the OS space, Aroma can do the following actions:
From the point (x,y)(x,y), Aroma can move to one of the following points: (x?1,y)(x?1,y), (x+1,y)(x+1,y), (x,y?1)(x,y?1) or (x,y+1)(x,y+1). This action requires 11 second.
If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 00 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within tt seconds?
Input
The first line contains integers x0x0, y0y0, axax, ayay, bxbx, byby (1≤x0,y0≤10161≤x0,y0≤1016, 2≤ax,ay≤1002≤ax,ay≤100, 0≤bx,by≤10160≤bx,by≤1016), which define the coordinates of the data nodes.
The second line contains integers xsxs, ysys, tt (1≤xs,ys,t≤10161≤xs,ys,t≤1016) – the initial Aroma’s coordinates and the amount of time available.
Output
Print a single integer — the maximum number of data nodes Aroma can collect within tt seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 55 data nodes are (1,1)(1,1), (3,3)(3,3), (7,9)(7,9), (15,27)(15,27) and (31,81)(31,81) (remember that nodes are numbered from 00).
In the first example, the optimal route to collect 33 nodes is as follows:
Go to the coordinates (3,3)(3,3) and collect the 11-st node. This takes |3?2|+|3?4|=2|3?2|+|3?4|=2 seconds.
Go to the coordinates (1,1)(1,1) and collect the 00-th node. This takes |1?3|+|1?3|=4|1?3|+|1?3|=4 seconds.
Go to the coordinates (7,9)(7,9) and collect the 22-nd node. This takes |7?1|+|9?1|=14|7?1|+|9?1|=14 seconds.
In the second example, the optimal route to collect 22 nodes is as follows:
Collect the 33-rd node. This requires no seconds.
Go to the coordinates (7,9)(7,9) and collect the 22-th node. This takes |15?7|+|27?9|=26|15?7|+|27?9|=26 seconds.
In the third example, Aroma can’t collect any nodes. She should have taken proper rest instead of rushing into the OS space like that.
思路:通過觀察可以發(fā)現(xiàn),其實(shí)利益點(diǎn)與前一個(gè)利益點(diǎn)橫縱坐標(biāo)之間成冪次關(guān)系,這樣的話就肯定不會(huì)太多,因此我們可以先暴力將所有范圍內(nèi)的點(diǎn)找出來然后暴力去找。在規(guī)定時(shí)間內(nèi)能找到的利益點(diǎn),肯定是連續(xù)的,因?yàn)椴皇沁B續(xù)點(diǎn)之間的距離一定大于連續(xù)點(diǎn),貪心思想就一定是連續(xù)點(diǎn)。
代碼如下:
努力加油a啊,(o)/~
總結(jié)
以上是生活随笔為你收集整理的Aroma's Search(暴力)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NEKO's Maze Game(思维)
- 下一篇: Obtain a Permutation