Steven loves reading book on his phone. The book he reads now consists of N paragraphs and the i-th paragraph contains ai characters.
Steven wants to make the characters easier to read, so he decides to increase the font size of characters. But the size of Steven's phone screen is limited. Its width is W and height is H. As a result, if the font size of characters is S then it can only show ⌊W / S⌋ characters in a line and ⌊H / S⌋ lines in a page. (⌊x⌋ is the largest integer no more than x)
So here's the question, if Steven wants to control the number of pages no more than P, what's the maximum font size he can set? Note that paragraphs must start in a new line and there is no empty line between paragraphs.
Input may contain multiple test cases.
The first line is an integer TASKS, representing the number of test cases.
For each test case, the first line contains four integers N, P, W and H, as described above.
The second line contains N integers a1, a2, ... aN, indicating the number of characters in each paragraph.
For all test cases,
1 <= N <= 103,
1 <= W, H, ai <= 103,
1 <= P <= 106,
There is always a way to control the number of pages no more than P.
For each testcase, output a line with an integer Ans, indicating the maximum font size Steven can set.
2 1 10 4 3 10 2 10 4 3 10 10样例输出
Little Hi runs a web server. Sometimes he has to deny access from a certain set of malicious IP addresses while his friends are still allow to access his server. To do this he writes N rules in the configuration file which look like:
allow 184.108.40.206/30 deny 220.127.116.11 allow 127.0.0.1 allow 18.104.22.168/3 deny 0.0.0.0/0
Each rule is in the form: allow | deny address or allow | deny address/mask .
When there comes a request, the rules are checked in sequence until the first match is found. If no rule is matched the request will be allowed. Rule and request are matched if the request address is the same as the rule address or they share the same first mask digits when both written as 32bit binary number.
For example IP "22.214.171.124" matches rule "allow 126.96.36.199" because the addresses are the same. And IP "188.8.131.52" matches rule "deny 184.108.40.206/20" because 10000000011111110000010001100100 (220.127.116.11 as binary number) shares the first 20 (mask) digits with10000000011111110000100001111101 (18.104.22.168 as binary number).
Now comes M access requests. Given their IP addresses, your task is to find out which ones are allowed and which ones are denied.
Line 1: two integers N and M.
Line 2-N+1: one rule on each line.
Line N+2-N+M+1: one IP address on each line.
All addresses are IPv4 addresses(0.0.0.0 - 255.255.255.255) . 0 <= m ask <= 32.
For 40% of the data: 1 <= N, M <= 1000.
For 100% of the data: 1 <= N, M <= 100000.
For each request output "YES" or "NO" according to whether it is allowed.
5 5 allow 22.214.171.124/30 deny 126.96.36.199 allow 127.0.0.1 allow 188.8.131.52/3 deny 0.0.0.0/0 184.108.40.206 220.127.116.11 18.104.22.168 100.100.100.100 22.214.171.124样例输出
YES YES NO YES NO
You work as an intern at a robotics startup. Today is your company's demo day. During the demo your company's robot will be put in a maze and without any information about the maze, it should be able to find a way out.
The maze consists of N * M grids. Each grid is either empty(represented by '.') or blocked by an obstacle(represented by 'b'). The robot will be release at the top left corner and the exit is at the bottom right corner.
Unfortunately some sensors on the robot go crazy just before the demo starts. As a result, the robot can only repeats two operations alternatively: keep moving to the right until it can't and keep moving to the bottom until it can't. At the beginning, the robot keeps moving to the right.
rrrrbb.. ...r.... ====> The robot route with broken sensors is marked by 'r'. ...rrb.. ...bb...
While the FTEs(full-time employees) are busy working on the sensors, you try to save the demo day by rearranging the maze in such a way that even with the broken sensors the robot can reach the exit successfully. You can change a grid from empty to blocked and vice versa. So as not to arouse suspision, you want to change as few grids as possible. What is the mininum number?
Line 1: N, M.
Line 2-N+1: the N * M maze.
For 20% of the data, N * M <= 16.
For 50% of the data, 1 <= N, M <= 8.
For 100% of the data, 1<= N, M <= 100.
The minimum number of grids to be changed.
4 8 ....bb.. ........ .....b.. ...bb...样例输出
Little Hi is playing a sandbox voxel game. In the game the whole world is constructed by massive 1x1x1 cubes. The edges of cubes are parallel to the coordinate axes and the coordinates (x, y, z) of the center of each cube are integers.
At the beginning there is nothing but plane ground in the world. The ground consists of all the cubes of z=0. Little Hi needs to build everything by placing cubes one by one following the rules:
1. The newly placed cube must be adjacent to the ground or a previously placed cube. Two cubes are adjacent if and only if they share a same face.
2. The newly placed cube must be accessible from outside which means by moving in 6 directions(up, down, left, right, forward, backward) there is a path from a very far place - say (1000, 1000, 1000) in this problem - to this cube without passing through ground or other cubes.
Given a sequence of cubes Little Hi wants to know if he can build the world by placing the cubes in such order.
The first line contains the number of test cases T(1 <= T <= 10).
For each test case the first line is N the number of cubes in the sequence.
The following N lines each contain three integers x, y and z indicating the coordinates of a cube.
For 20% of the data, 1 <= N <= 1000, 1 <= x, y, z <= 10.
For 100% of the data, 1 <= N <= 100000, 1 <= x, y, z <= 100.
For each testcase output "Yes" or "No" indicating if Little Hi can place the cubes in such order.
In the first test case three cubes are placed on the ground. It's OK.
In the second test case (1, 3, 2) is neither on the ground nor adjacent to previous cubes. So it can't be placed.
In the last test case (2, 2, 1) can not be reached from outside. So it can't be placed.
3 3 1 1 1 1 2 1 1 3 1 3 1 1 1 1 2 1 1 3 2 17 1 1 1 1 2 1 1 3 1 2 3 1 3 3 1 3 2 1 3 1 1 2 1 1 2 1 2 1 1 2 1 2 2 1 3 2 2 3 2 3 3 2 3 2 2 2 2 2 2 2 1样例输出
Yes No No