1325 - I2P (I) 2017_Yang_hw4 Scoreboard

Time

2017/11/06 18:00:00 2017/11/20 18:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11192 find palindrome
11194 Stairs Climbing
11200 Tower of Hanoi
11658 Eulerian Path

11192 - find palindrome   

Description

Palindrome is a string that is identical to its reverse, like "level" or "aba". Given a string, find the longest palindrome in the string.

 

Input

the first line of the input is a integer N, indicating the number of test cases.
In the next N lines, each contains a string. The length of each string is less than 1000. The number of test case is less than or equal to 10.

Output

In each test case, output the longest palindrome in the string. If there are many palindromes of the same length, output the first one in the string.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss




11194 - Stairs Climbing   

Description

Bob is a man who wants to climb 3 step stairs.

Suppose he can only climb 1 or 2 step at a time.

Then , there are 3 possible ways to climb 3 step stairs

          (1)  1 step + 1 step + 1 step
          (2)  1 step + 2step
          (3)  2 step + 1step

The question is : if Bob want to climb X step stairs. 

How many possible ways are there to climp X step stairs.
 

 

 

Input

An integer N represents the number of testcases.

Then , there are following N lines.

Each line contain an integer X that  represents the number of stairs in that testcase.

P.S. 1<= X <=40

Output

An integer represents the number of possible way to climb N stairs.

Note that you have to add '\n' at the end of output

 

Sample Input  Download

Sample Output  Download

Tags




Discuss




11200 - Tower of Hanoi   

Description

The Tower of Hanoi is a mathematical game puzzle. It consists of three rods, which are A, B and C. The puzzle starts with disks in ascending order of size on rod A, the smallest at the top.

The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:

1.   Only one disk can be moved at a time.

2.   Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.

3.   No disk may be placed on top of a smaller disk.

Write a program to simulate the moves of the disks. Print the number of disk which is moved in each step.

 

For example, if n = 3, the moves of each steps are:

move disk 1 from rod A to rod C
move disk 2 from rod A to rod B
move disk 1 from rod C to rod B
move disk 3 from rod A to rod C
move disk 1 from rod B to rod A
move disk 2 from rod B to rod C
move disk 1 from rod A to rod C


You should print out:

1
2
1
3
1
2
1

HINT : You can modify this sample code and implement the function 'hanoi'

#include <stdio.h>
void hanoi(int n, char A, char B, char C);

int main(){
    int n;
    scanf("%d", &n);
    hanoi(n, 'A', 'B', 'C');
    return 0;
}

Input

An integer n (0<n<20), which means the number of disk.

Output

Print out the number of disk which is moved in each step, and there is a '\n' at the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11658 - Eulerian Path   

Description

There are N distinct points on a paper, labeled from 1 to N. You are asked to draw a path connecting all the points, and each point is allowed to be visited more than once. For example, the following 5 points can be connected into the shape of a house in the order of 1,4,2,3,4,5,3,1,2.

Now, you need a program to check whether the graph can be drawn by only one stroke. Since you have already checked that all the points are connected, there must be a path for any one point to reach another.

 

Input

There are several test cases, but no more than 10 test cases. In each test case, there’re two numbers N and M in the first line, indicating that there’re N points and M lines on the paper. Each line can be used only once.

In the next M lines, each line contains two numbers i and j, which means there’s a line connecting point i and point j.

  • 1 <= N <= 10^4
  • N-1 <= M <= 10^5
  • 1 <= i, j <= N
  • The given graph contains only one connected component which connects all the points. There’s no a point that cannot reach all the other points.

Output

If the graph can be drawn by only one stroke, print Yes; otherwise, print No.

Hint:

If a graph G has an Eulerian path, then it must have exactly two odd vertices.

1. Suppose that a graph has an Eulerian path P, which can be drawn by only one stroke. For every vertex v other than the starting and ending vertices, the path P enters v the same number of times that it leaves v (say s times). Therefore, there are 2s edges having v as an endpoint. Therefore, all vertices other than the two endpoints of P must be even vertices. 

 

2. Suppose the Eulerian path P starts at vertex x and ends at vertex y. The P leaves x one more time than it enters, and leaves y one fewer time than it enters. Therefore, the two endpoints of P must be odd vertices.

*Note that if the path starts and ends at the same vertex, there's no odd vertex.

Reference: https://www.math.ku.edu/~jmartin/courses/math105-F11/Lectures/chapter5-part2.pdf 

Sample Input  Download

Sample Output  Download

Tags




Discuss