2359 - I2P(II)2021_Yang_hw5 Scoreboard

Time

2021/05/25 18:00:00 2021/06/04 13:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11447 Use std::map
11485 Use std::set
13218 BBPoints
13219 BFS - Practice

11447 - Use std::map   

Description

This problem will help you understand how to use std::map.

http://en.cppreference.com/w/cpp/container/map

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

目前有五個測資,第三筆測資不算,答題測資看另外四筆

Input

The input consist of series of command. Each commands is insert, range output 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 output: outputs the string from key (first) to key (last). Output a space character (' ') after printing an element.

 

range erase: erase the string 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, output, erase and operator<<.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11447.cpp

Partial Judge Header

11447.h

Tags




Discuss




11485 - Use std::set   

Description

This problem will help you understand how to use std::set and comparator.

e.g., std::set<std::vector<int>>

http://en.cppreference.com/w/cpp/container/set

Input

How to compare the integer sequence (calculate the key of an integer sequence):

  • get the length of integer sequence (size)
  • key value=[first element]*(size)+[second element]*(size-1)+[third element]*(size-2)+...+[last element]*1
  • compare the key value. Small key value is smaller.
  • if the length of a integer sequence is 0, the key value is 0.
  • e.g., the key of an integer sequence "3 9 -1 3 -6" is 48 (3*5+9*4+(-1)*3+3*2+(-6)*1)

 

The input consist of series of command. Each commands is insert, range_out or output.

​insert: inserts an integer sequence (each value is greater than -6 and smaller than 11, stop reading from cin when value is 0). If the key has already existed, then

  • output "exist\n"
  • erase the integer sequence from set
  • reverse the integer sequence (from input)
  • insert the reversed integer sequence

For example,

insert 3 9 -1 3 -6 0

The set should contain 3 9 -1 3 -6.

insert 9 -2 6 6 0

The set should contain 6 6 -2 9.


range_out: outputs all integer sequences from the integer sequence (first key) to the integer sequence (second key) of set (including the second key). First key and second key are read from input (each value is greater than -6 and smaller than 11, stop reading from cin when value is 0).

For example,

insert 2 -5 -5 0

insert 3 9 -1 3 -6 0

insert 7 6 1 2 0

insert 10 10 10 2 0

range_out -5 0 10 9 2 0

It should output

3 9 -1 3 -6

7 6 1 2

For example,

insert 2 -5 -5 0

insert 3 9 -1 3 -6 0

insert 7 6 1 2 0

insert 10 10 10 2 0

range_out -5 0 10 10 10 0

It should output

3 9 -1 3 -6

7 6 1 2

 

output: outputs all integer sequences from the smallest key to the biggest key of set. Output a space character (' ') after printing an integer. Output a newline character ('\n') after printing all elements of a key.

Output

Complete insert, range output and output.

Sample Input  Download

Sample Output  Download

Tags




Discuss




13218 - BBPoints   

Description

There are  black points on coordinate plane. The -th black point(they're numbered in 1-based) is on  in the beginning.

Then  events happens. There are two types of event:

  1. y-coordinates of the -th point increase by 
  2. a blue point appears on  and it will keep moving right until it reaches . When it touches some black point, that black point will move down for "the distance which the blue point has moved". The blue point will vanish when it touches a black point or stop moving.

In the end, output y-coordinates of all the black points.

Hint

If you use std::set to store elements, you can use its member function std::set::lower_bound to find the iterator of the least element which is greater than or equal to the element you pass. The time complexity of std::set::lower_bound is  where  is the number of elements in that std::set. Do not use std::lower_bound on std::set.

You can refer to the following code.

set<int> s;

/* insert some elements into s */

int x = 5;
set<int>::iterator it;

/* (1) good */
it = s.lower_bound(x);

/* (2) bad */
it = lower_bound(s.begin(), s.end(), x);

Input

The first line contains two integers  and   – the number of black points and the number of events.

Then  lines follow. The -th line contains an integer  – the type of the -th event. If  is equal to 1, then two integers  and  follow. Otherwise three integers  and  follow.

 

It's guaranteed that:

  • The 1st testcase must be identical to the Sample below
  • For the first 5 testcases:  and  y-coordinate of any black point  always holds
  • For the first 7 testcases:  y-coordinate of any black point  always holds

Output

After the  events, output y-coordinates of all the black points and print a newline('\n') character.

Sample Input  Download

Sample Output  Download

Tags




Discuss




13219 - BFS - Practice   

Description

There is a grid. Each cell is either an empty cell or a wall. You are on in the beginning and want to go to .

It's guaranteed that  and  are empty cells.

You could move to an adjacent empty cell (i.e an empty cell which shares a common side with the cell which you are on).

Find the minimum number of cells you need to pass by to reach . There may be no such a path for you to reach .

Input

The first line contains two positive integers  and   the size of the grid.

Then  lines folllow. The -th line contains  characters. The -th characters in the -th line  may be 0 or 1. The cell  is an empty cell if  is equal to 0. Otherwise it's a wall.

The next line contains two integers  and   the initial cell you are on.

The final line contains two integers  and   the cell you want to go.

Note that  and  must be empty cells. Also they are different(i.e  or ).

 

It's guaranteed that:

  • The 1st testcase must be identical to the Sample #1 below
  • For the first 5 testcases: 
  • For the first 7 testcases: 

Output

Output the minimum cells you must pass by for you to reach . Output -1 instead if there is no such a path.

Remember to print a newline('\n') character at the end of the line.

 

Note: there are two sample below. "# Sample Input 1/2" and "# Sample Output 1/2" are not the part of input and output.

They are just for marking that the following content corresponds to which sample.

Sample Input  Download

Sample Output  Download

Tags




Discuss