1243 - I2P(II)2016_Yang_final Scoreboard

Time

2017/06/16 13:30:00 2017/06/16 17:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10673 Queueing
11462 cppreference
11487 Parentheses Matching
11496 MAP Test
11497 Move and Reverse
11498 Count the Leaves

10673 - Queueing   

Description

You need to write a program to simulate a queue of names.  Each name is a string consisting of English letters only.  There are three operations:

1.         “Push [name]”, which means to enque name in the queue.

2.         “Pop”, which means to deque. If the queue is empty, this operation takes no effect.

3.         “Front”, which means to print out the name in the front of queue. If the queue is empty, print "empty" (without quotes).

 

Case1 : #operation <= 10^2, There will be no "Pop" and "Front" command when queue is empty.
Case2 : #operation <= 10^3. There will be no "Pop" and "Front" command when queue is empty.
Case3 : #operation <= 10^4.
Case4 : #operation <= 10^6.

Input

Each line contains one of the following operations. “Push [name]” (without quotes), “Pop” (without quotes), “Front”(without quotes). The length of each name is at most 10.

Output

For each “Front” operation, print out the name in the front of the queue.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11462 - cppreference   

Description

版本:

20180311

 

使用說明:

請下載code或header(兩個是同個檔案)

把附檔名從.cpp改成.zip

解壓縮後

reference>en>cpp.html

即可看到官方文件

Input

Output

Sample Input  Download

Sample Output  Download

Partial Judge Code

11462.cpp

Partial Judge Header

11462.h

Tags

CPP Reference



Discuss




11487 - Parentheses Matching   

Description

A string is said to be a SM string if it matches one of the following rules:

(1) An empty string is a SM string.

(2) If strings S1 and S2 are both SM strings, then S1S2 is SM string.

(3) If a string S is SM string, then {S}, [S], (S) and <S> are SM strings.

(4) If a string S is SM string, then "sm"S is a SM string.

Given a string consisting of parentheses, determine if it is a SM string.

Input

The input consists of several lines.

Each line contains a string S(1 <= |S| <= 10^6 ), where S consists of only '{', '}', '[', ']', '(', ')' and "sm".

Output

For each strings S, output "SM" if it is a SM string, "MS" if not.

There should be a '\n' in the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11496 - MAP Test   

Description

Notice, first and last is [first, last].

The following references will help you understand how to use functions in std::map.

Input

The input consists of a series of commands. A command can be an insert or range erase.

insert: inserts a string (cmd) with the key (key) to map. If the key has already existed, insert the cmd at the begining of string (the string which the key belongs).

For example,

insert 0 "abc"

insert 1 "def"

the map should contain "abc", "def".

insert 0 "xyz"

the map should contain "xyzabc", "def".

range erase: erase the strings from key (first) to key (last).

operator<<: outputs all strings in map. From the smallest key to biggest key. Output a space character (' ') after printing an element.

Output

Complete insert, erase and operator<<.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11496.cpp

Partial Judge Header

11496.h

Tags




Discuss




11497 - Move and Reverse   

Description

There are N numbers in a sequence.  The original sequence is from 1 to N. (1 is the head).
For example, if N=5, the original sequence should be 1 2 3 4 5.

There are three commands in the input as follows:

The operation “Move1 a” means to move the first two numbers to the BACK of a without changing order.
For example, if the original sequence is 5 1 4 3 2 , "Move1 4" will turn the sequence into 4 5 1 3 2.
Note that if a is one of the first two numbers then you don't need to do anything.

The operation “Move2 a” means to move the first two numbers to the BACK of a with reversed order.
For example, if the original sequence is 5 1 4 3 2, "Move2 3" will turn the sequence into 4 3 1 5 2.
Note that if a is one of the first two numbers then you don't need to do anything.

The operation “Reverse” means to reverse the whole sequence.
For example, if the original sequence is 5 1 4 3 2, "Reverse" will turn the sequence into 2 3 4 1 5.

Given several such commands and output the final status of the sequence.

You can use the following code.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct _node{
    int n;
    struct _node* prev;
    struct _node* next;
}node;

int main(){
    int N,M;
    char cmd[10];
    scanf("%d%d",&N,&M);

    // initialize your structures here

    for(int i=0;i<M;i++){
        scanf("%s",cmd);
        if(strcmp(cmd,"Reverse")==0){
            //your code here
        }else if(strcmp(cmd,"Move1")==0){
            //your code here
        }else if(strcmp(cmd,"Move2")==0){
            //your code here
        }
    }

    //output
    /*
    Here is an example of output from class but you have to modify it according to your algorithm.
    while(head!=NULL){
        if(head->prev == NULL) printf("%d", head->data);
        else printf(" %d", head->data);
        head = head->next;
    }
    printf("\n");
    */

    return 0;
}

Input

The input begins with two integers N and M, indicating there are N numbers in the original sequence and there are M commands in this testcase.
The next M lines will be the commands.

subtask 1 : 3<=N<=100, 1<=M<=100, including Move1, you can use O(N) algorithm.

subtask 2 : 3<=N<=100, 1<=M<=100, including Move1, you can use O(N) algorithm.

subtask 3 : 3<=N<=100, 1<=M<=100, including Move1, you can use O(N) algorithm.

subtask 4 : 3<=N<=10000, 1<=M<=1000000, including Move1, you should use O(1) algorithm.

subtask 5 : 3<=N<=10000, 1<=M<=1000000, including Move1 and Move2, you should use O(1) algorithm.

subtask 6 : 3<=N<=100000, 1<=M<=100000, including Move1 and Move2, you should use O(1) algorithm.

subtask 7 : 3<=N<=100000, 1<=M<=100000, including Move1, Move2 and Reverse, you should use O(1) algorithm.

subtask 8 : 3<=N<=1000000, 1<=M<=1000000, including Move1, Move2 and Reverse, you should use O(1) algorithm.

Output

Output the numbers from the first one to the last one, and separate two consecutive numbers by a space. You NEED to print "\n" at the end of the line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11498 - Count the Leaves   

Description

Given a tree, count the number of leaves in this tree. Each node has unique integer identification (ID), but all IDs may not be consecutive.

Input

There are multiple test cases. Each test case begins with an integer N (1 <= N <=1000). In the following N lines, each line has two integer a and b (1 <= a,b <= 1000), indicating node a is node b’s parent. The next line contains an integer R, which represents the root of the Tree. You can assume that all the nodes will be on the same tree. The input is terminated by N = 0.

Output

Print the number of the leaves for each test case.

Hint: All leaves have no children!

Sample Input  Download

Sample Output  Download

Tags




Discuss