雅虎北京研究院hack大赛题目

来源:互联网 发布:协同创新网络 编辑:程序博客网 时间:2024/04/30 05:27
Question 1 / 5 (Problem A)

Given a rational number expressed as A/B where A and B are integers, find the position of Mth occurrence of digit D (0-9) after decimal point. For example 3/7 = 0.4285714285... (A=3, B=7), so the 2nd (M=2) 4 (D=4) is the 7th digit after decimal point.

Limits:

  • 0 < A, B, M < 2 x 108

  • 0 <= D <= 9

Input:

The first line of the input gives the number of test cases, N. N test cases follow. Each test case consists of one line containing 4 numbers, A, B, M and D separated by spaces.

Output:

Each line contains the position (starting from 1) of the specified digit D. Output “0” if it is impossible to find the digit.

Sample:

InputOutut

7
3 7 1 1
3 7 2 2
3 7 3 6
5 11 2 3
5 11 3 7
20 193 20 6
200000 19893 50 8

6
8
0
0
0
191
470

Test case: (Please write a program to read the test case input data below from STDIN and print the output to STDOUT in the format as described above)

30
3 7 1 1
3 7 2 2
3 7 3 6
5 11 2 3
5 11 3 7
20 193 20 6
200000 19893 50 8
2 18 999 1
121 10000 2 1
121 10000 3 1
121 10000 1 5
1 1 1 1
12 21 21 2
123 321 321 3
1234 4321 4321 4
12345 54321 54321 5
123456 654321 654321 6
1234567 7654321 7654321 7
12345678 87654321 87654321 8
21 12 21 2
321 123 321 3
4321 1234 4321 4
54321 12345 54321 5
654321 123456 654321 6
7654321 1234567 7654321 7
87654321 12345678 87654321 8
24691111 199998000 1 3
24691111 199998000 100 5
24691111 199998000 5 3
24691111 199998000 99999999 9 

 

Question 2 / 5

Given a N*N grid where N is an even number and 6 points A, B, C, D, E and F. The coordinates of each point are (xa, ya), (xb, yb), ..., (xf, yf). Define S to be the following.

S = 2 * (SABC + SDEF) where SABC and SDEF are the area of the triangle ABC and DEF.

Below is an example of 4*4 grid. In this case S = 2 * SABC + 2 * SDEF= 6 + 8 = 14.

Now your task is, given an arbitrary S, find one possible solution of the 6 points that meets the above requirement.

Limits:

  • xa, ya, xb, yb, ..., xf, yf are integers between 0 and N.
  • N and S are natural numbers.
  • 0 < N, S < 1010

Input:

The first line of the input gives the number of test cases, N. N test cases follow. Each test case consists of one line containing 2 numbers, N and S separated by one space.

Output:

The coordinates of A, B, C, D, E and F. If no possible solution can be found, output the word “impossible” (quotes for clarity).

Sample:

InputOutput

3
4 14
4 36
6 21

0 0 1 4 2 1 0 0 1 4 2 1
impossible
0 0 1 6 2 2 0 0 1 6 2 1

Test case: (Please write a program to read the test case input data below from STDIN and print the output to STDOUT in the format as described above)

13
4 14
4 36
100 9999
100 19999
100 20000
100 20001
12 21
123 321
1234 4321
12345 54321
123456 654321
1234567 7654321
12345678 87654321

 

Question 3 / 5 (Problem C)

You are given N line segments, with each line segment depicted by its starting and ending points, calculate the longest continuous line segment with the given line segments set.

Limits:

  • 1 < N < 100
  • The starting and ending point integer ranges from 0 to 10,000

Input:

The first line of the input is the number of line segments N, each following line has two integers depicting the starting and ending points, respectively.

Output:

Length of longest consecutive line segment.

Sample:

InputOutput

5
0  1
0  5
7  10
8  12
1  3

5

With the given input set, the longest continuous line segment starts at 0 and ends at 5 (or starts at 7 and ends at 12), gives the length 5.

Test case: (Please write a program to read the test case input data below from STDIN and print the output to STDOUT in the format as described above)

 

Question 4 / 5

Given a source M*N matrix A and a target M*N matrix B, elements in each matrix are integers of range 0 ~ (M*N-1), each integer only appears once in the same matrix. Please find the steps to change matrix A to B. The rules are:

  • Only “0” can switch with neighbor element. A neighbor element is the one that is to the left/right/top/bottom of “0”.

  • Certain values in matrix A cannot be changed, they are designated in array C.

Input:

First line is M, N separated by space, followed by M lines of elements in matrix A, then followed by M lines of elements in matrix B, then followed by a line of elements in array C. Values in each line are separated by spaces.

Output:

One line with X steps, separated by space. Each step is the value of element that would switch with “0”.

Sample:

 

For A= [0 1 2
3 4 5
6 7 8
], B= [3 1 2 
6 4 5
0 7 8
], C=[1]InputOutput

3 3
0 1 2
3 4 5
6 7 8
3 1 2
6 4 5
0 7 8
1

3 6

Test case: (Please write a program to read the test case input data below from STDIN and print the output to STDOUT in the format as described above)

3 3
0 1 2
3 4 5
6 7 8
3 1 2
6 4 5
0 7 8
1

Scoring: The sample test-case is not worth any points. Your code should be able to clear the hidden test-cases which we'll run after the contest. Depending on how many test-cases your code passes, you'll get a score.

 

Question 5 / 5

A palindrome is a word, phrase, number, or sentence, whose meaning may be interpreted the same way in either forward or reverse direction.

Some well-known English palindromes are, "Able was I ere I saw Elba", "A man, a plan, a canal Panama!",  "Madam, I'm Adam" or "Madam in Eden, I'm Adam", "Doc, note: I dissent. A fast never prevents a fatness. I diet on cod" and "Never odd or even".

You are given a list of words, please use those words to find out the longest palindrome, with as many characters as you can.

Notes:

  1. The sentence need not to be logically meaningful nor grammatically correct, it can be any combination of the words;

  2. Palindrom's are case insensitive, e.g. letter 'E' is considered same as letter 'e';

  3. You can only use the words in the given list;

  4. Each word can be used at most once;

  5. Word list may contain 1~100000 words.

Input:

First line is the number of the words in the list, then followed by the list of words, with one word in each line.

Output:

Just output any of the longest sentence you found. If the given list can’t construct a valid palindrome sentence, just output “impossible”.

Sample:

InputOutput5
ate
Lisa
Bonet
basil
no

Lisa Bonet ate no basil

 

Sample 2:

InputOutput8
cat
in
Oozy
zoo
park
a
sanitary
rat

oozy rat in a sanitary zoo

Sample 3:

InputOutput

5
too
hard
to
get
​one

impossible

 

Test cases: (Please write a program to read the test case data from STDIN and print the output to STDOUT in the format described above).

 

 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 生完宝宝后头发掉的厉害怎么办 生完宝宝头发掉的厉害怎么办 生了小孩后头发掉很多怎么办 生了孩子头发掉的很厉害怎么办 母乳期头发掉的很厉害怎么办 宝宝吃母乳头发掉的厉害怎么办 头发油腻头皮屑多还掉头发怎么办 头发剪了中分刘海弯了怎么办 头发掉了长出来的头发很细怎么办? 头皮损伤毛囊怎么办还会长头发吗 一岁宝宝头发稀少怎么办能刮光头么 前编头发长了怎么办怎么梳理 九个月宝宝头发稀少不长怎么办 前牙吃饭咬合很深吃饭就痛怎么办 吃了甜的冷的就牙疼怎么办 吃热的凉的甜的牙疼怎么办 头发太细了想让头发变粗点怎么办 我的头发又少又很油该怎么办 头发油掉发头顶头发稀疏怎么办 我的头发天生就少又细怎么办 头发越来越少怎么办 用什么好呢 头发油掉头发怎么办吃什么药好 生完孩子三个月掉头发很厉害怎么办 电夹板夹头发现在掉头发怎么办 刚剪完的头发前面短后面长怎么办 头发太多太厚怎么办_百度经验 米诺地尔搽剂喷在头皮上痛怎么办 米诺地尔擦了头皮痒怎么办 头发又细又少一天不洗就油怎么办 头又尖头发又细又少不知怎么办 蘑菇头发型留长尴尬期怎么办 月经期间洗了下头量很少了怎么办 宝宝喝了有沐浴露的洗澡水怎么办 4个月宝宝头发长的慢怎么办 宝宝不小心吃了自己拉的屎怎么办 手机不小心弄成耳机模式怎么办 苹果手机不小心按了丢失模式怎么办 苹果手机不小心调成耳机模式怎么办 不小心把图书馆的书弄坏了怎么办 不小心把图书馆书拿出来了怎么办 八个月宝宝吃母乳缺铁怎么办