| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10580 | Fill the Boxes |
|
| 11055 | Vector Intersection |
|
| 11071 | Simply Fractions (multiplication) |
|
| 11072 | I2P(II)2020 final exam Cheatsheet |
|
| 11075 | Binary Addition |
|
| 11077 | Queueing |
|
Description
Assume that we need to send a stream of data items as a series of packets. The size limit of a packet is M, and each item i has a size s_i satisfying s_i < M, for i = 1, 2, ....N
For each item i, we can append it to the current packet as long as the total size of the items in the packet does not exceed the limit; otherwise, we put the item into a new packet.
Our task is to simulate the process and decide how many packets are needed.
Case1: 0<M<=1*102, 0<=N<=20
Case2: 0<M<=2*104, 0<=N<=100
Case3: 0<M<=1*105, 0<=N<=10000
Case4: 0<M<=2*109, 0<=N<=10000
Input
The input consists of several test cases.
Each test case starts with an integer M indicating the size limit of a packet.
The subsequent positive integers enumerate the sizes of the items, and a number 0 denotes the end of the current stream.
Output
The output contains several lines.
Each line prints the number of packets needed to send the stream for the corresponding test case.
Each line is ended with a newline character.
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
Given several fractions, compute their product (multiplies all fractions) 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 product 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
1. How to make cin faster?
std::ios_base::sync_with_stdio(false);
use '\n' instead of endl
2. An example of using <vector>
#include <iostream>
#include <vector>
#include <algorithm> // sort
int main ()
{
std::vector<int> V;
int x;
while (std::cin>>x) {
V.push_back(x);
}
for (auto t : V) std::cout<<" "<< t;
std::cout << "\n";
std::sort(V.begin(), V.end());
for (auto t : V) std::cout<<" "<< t;
std::cout << "\n";
}
3. An example of using <stringstream>
#include <string>
#include <iostream>
#include <sstream> // std::stringstream
int main () {
std::stringstream ss;
ss << "Hello " << 123;
std::string s = ss.str();
std::cout << s << '\n';
}
4. An example of using <set>
#include <iostream>
#include <set>
int main()
{
std::set<int> S = {1, 2, 3, 4};
auto search = S.find(2);
if(search != S.end()) {
std::cout << (*search) << '\n';
}
else {
std::cout << "Not found\n";
}
}
5. An example of using <stack>
#include <stack>
#include <iostream>
int main()
{
std::stack<int> s;
s.push( 3 ); s.push( 6 );
s.push( 18 );
std::cout<<s.size()<<" elements\n";
std::cout<<"Top: "<< s.top()<< "\n";
s.pop();
std::cout<<s.size()<<" elements\n";
}
6. An example of getline()
#include <string>
#include <iostream>
int main()
{
std::string name;
std::cout << "What is your name? ";
std::getline(std::cin, name);
std::cout << "Hello "<< name<< "\n";
}
7. An example of using <map>
#include <iostream>
#include <string>
#include <map>
#include <utility> // make_pair
int main()
{
std::map<std::string, int> ID;
ID.insert(std::make_pair("Tom", 123));
std::cout << ID["Tom"] << "\n";
}
Input
Output
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Compute the sum of two given N-bit binary numbers.
Input
The first line of the input file contains a positive integer T indicating the number of test cases. The first line of each test case is a positive integer N denoting the length of bits. The second and third lines are the two N-bit binary numbers. The first bit of each binary number is always 0, which guarantees that the sum of the two binary numbers can still be expressed as an N-bit binary number.
Level 1 : T<=100, N<=100
Level 2 : T<=200, N<=1000
Level 3 : T<=300, N<=5000
Level 4 : T<=400, N<=10000
Output
For each test case, your program should print the sum in the same format as the binary numbers given in input.
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. Note that you NEED to add a "\n" at the end.