| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10478 | Simply Fractions |
|
| 10673 | Queueing |
|
| 10682 | Parentheses Matching |
|
| 11029 | extend |
|
| 11055 | Vector Intersection |
|
| 11465 | Use std::map |
|
| 11484 | Draw the Shapes |
|
| 11485 | Use std::set |
|
| 11486 | Josephus Prob. using Circular Linked List (better) |
|
Description
Given several fractions, compute their sum and express the answer in the simplest fraction form.
Input
There are many test cases in one subtask.
The first line of each test case contains an integer t, which indicates the number of fractions in the input. Each of the following t lines contains two integers a and b, which represent the numerator and the denominator of a fraction.
subtask 1 : t=2. 1<=a,b<=10.
subtask 2 : t<=5. 1<=a,b<=10.
subtask 3 : t<=5. 1<=a,b<=50.
subtask 4 : t<=10. 1<=a,b<=100.
Output
Each test case outputs one line.
The output is the sum reduced to the simplest fraction form. You need to print a '/' between the numerator and the denominator.
Sample Input Download
Sample Output Download
Tags
Discuss
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
Description
A string is said to be valid if it matches one of the following rules:
(1) The string is an empty string.
(2) If a string S is valid, then {S}, [S], (S) and <S> are valid.
(3) If strings S1 and S2 are both valid, then S1S2 is valid.
Given a string consisting of parentheses, determine if it is a valid string.
Input
The first line of the input contains an integer N (N ≤ 10000) denoting the number of test cases followed by. Each of the next N lines corresponds to a test case, which contains a string consisting of parentheses, and the maximum string length will be no more than 1000. Note that an empty string (a line which contains the newline character only) may be contained in the input and it should be considered as a valid string according to rule (1).
Case 1 : N≤50
Case 2: N≤100
Case 3: N≤1000
Case 4: N≤10000
Output
For each test case, print “Case i:” and then “Yes” or “No” to indicate that the string is valid or not, separated by a space character. i is the test case number starting from 1.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given an integer sequence, say {6, 1, 4, 3, 5, 2}, we can choose any pair of two neighboring numbers (in a circular sense) and swap them to generate a new sequence. For example,
If we choose 6 and 2, we get {2, 1, 4, 3, 5, 6} after swapping.
If we choose 1 and 4, we get {6, 4, 1, 3, 5, 2} after swapping.
Try to generate all possible results for the original sequence, and print the results in lexicographical order. For the example above, the output would be
1 6 4 3 5 2
2 1 4 3 5 6
6 1 3 4 5 2
6 1 4 3 2 5
6 1 4 5 3 2
6 4 1 3 5 2
Hint:
1. Use the set and vector containers.
2. The items in a set will be automatically sorted in lexicographical order.
main
Input
An integer sequence, separated by spaces. End by EOF.
Output
List all possible results for the original sequence in lexicographical order.
Each line contains one sequence, where there is a space between each number.
Note that there is a '\n' at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given two vectors of numbers, output their intersection set.
Note: the numbers of vectors need not to be unique.
Input
There are multiple test cases. Each case contains four lines. The first line begins with an integer N. The second line contains N integers, representing the numbers in the first set. The third line has one integer M, and the fourth line contains M integers, represent the numbers in the second set. All the numbers are 32 bit signed integers. The input is terminated if N = 0.
For case 1, 1 <= N, M <= 103
For case 2, 1 <= N, M <= 104
For case 3, 1 <= N, M <= 105
For case 4, 1 <= N, M <= 106
Output
For each test case, print the intersection of the two sets. Output them in ascending order. If the intersection of the two sets is an empty set, print “empty” (without quotes).
Note: There's a newline character at the end of each output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
This is an advanced version of http://acm.cs.nthu.edu.tw/problem/11447/
Notice, this time, first and last is [first, last].
Hint: std::map<std::string,...>
lower_bound and upper_bound can help you.
Input
The input consist of series of command. Each commands is insert, sum, range output, range erase or output.
insert: inserts a integer (0<=val<65536) with a string (key) to map. If the key has already existed, insert the val at the begining of integer (the val which the key belongs).
For example,
insert a 10
insert b 20
The map should contain 10, 20.
insert a 20
The map should contain 20 10, 20.
sum: sums up the integer with the key. Sum is 0 if a key is not existed. Output a newline character ('\n') after printing the sum.
For example,
insert a 10
insert b 20
The map should contain 10, 20.
insert a 20
The map should contain 20 10, 20.
sum a
It should output 30 (because 20 + 10).
range output: outputs the integer from key (first) to key (last). Output a space character (' ') after printing an element. Output a newline character ('\n') after printing all elements (even first key equals to last key).
For example,
insert a 10
insert b 20
The map should contain 10, 20.
insert a 20
The map should contain 20 10, 20.
range output a b
It should output 2010 20.
range erase: erase the integer from key (first) to key (last).
output: outputs all integer in map. From the smallest key to biggest key. Output a space character (' ') after printing an element. Output a newline character ('\n') after printing all elements (even map is empty).
insert a 10
insert b 20
The map should contain 10, 20.
insert a 20
The map should contain 20 10, 20.
output
It should output 2010 20.
Output
Complete the above operations.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Giving basic information of some shapes, you need to draw them on the Cartesian coordinate system and calculate the total area.
PI has already defined in function.h.
Input
There are only 2 shapes in this problem :
1. R (Rectangle), followed by 4 points. Each point represent 1 vertex of the rectangle, with the format (x, y).
2. C (Circle), followed by 1 point represent the centre of the circle, and a number of its radius.
If the radius is negative, set it to 0.
e.g., the result of sample input would be like :

Output
Output the total area of all the shapes.
Sample Input Download
Sample Output Download
Partial Judge Code
11484.cppPartial Judge Header
11484.hTags
Discuss
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
Description
In computer science and mathematics, the Josephus problem (or Josephus permutation) is a theoretical problem related to a certain counting-out game.
People are standing in a circle waiting to be executed. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of people are skipped, the next person is executed. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains, and is freed.
The problem — given the number of people, starting point, direction, and number to be skipped — is to choose the position in the initial circle to avoid execution.
You're asked to solve this problem using circular linked list.
Input
The input has two positive integers, n (the number of people) and m (kill every mth people).
Output
The output is the order of people that were killed.