题目描述One measure of “unsortedness” in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequence ``DAABEC’’, this measure is 5, since D is greater than four letters to its right and E is greater than one letter to its right. This measure is called the number of inversions in the sequence. The sequence ``AACEDGG’’ has only one inversion (E and D)—it is nearly sorted—while the sequence ``ZWQM’’ has 6 inversions (it is as un...
题目描述Unique For a sequence of integers A={a0,a1,…,an−1} which is sorted by ascending order, eliminate all equivalent elements.
输入A sequence is given in the following format.
n
a0 a1,…,an−1
输出Print the sequence after eliminating equivalent elements in a line. Separate adjacency elements by a space character.
样例输入1241 2 2 4
样例输出11 2 4
提示1≤n≤100,000
−1000,000,000≤ai≤1,000,000,000
a0≤a1≤…≤an−1
题解12345678910111213141516#include <set>#include <iostream>using namespace std;int...
题目描述Sorting Pairs Write a program which print coordinates (xi,yi) of given n points on the plane by the following criteria.
first by x-coordinate in case of a tie, by y-coordinate
输入The input is given in the following format.
n
x0 y0
x1 y1
:
xn−1 yn−1
In the first line, the number of points n is given. In the following n lines, coordinates of each point are given.
输出Print coordinate of given points in order.
样例输入12345654 75 52 36 82 1
样例输出123452 12 34 75 56 8
提示1≤n≤100,000
−1,000,0...
题目描述For given a sequence A={a0,a1,…,an−1}, print the previous permutation and the next permutation in lexicographic order.
输入A sequence is given in the following format.
n
a0 a1…an−1
输出Print the previous permutation, the given sequence and the next permutation in the 1st, 2nd and 3rd lines respectively. Separate adjacency elements by a space character. Note that if there is no permutation, print nothing in the corresponding line.
样例输入123432 1 333 2 1
样例输出123451 3 22 1 32 3 13 1 23 2 1
...
题目描述For a given sequence A={a0,a1,…,an−1} which is sorted by ascending order, find the lower bound for a specific value k given as a query.
lower bound: the place pointing to the first element greater than or equal to a specific value, or n if there is no such element.
输入The input is given in the following format.
n
a0 a1,…,an−1
q
k1
k2
:
kq
The number of elements n and each element ai are given in the first line and the second line respectively.
In the third line, the number o...
题目描述小数字的计算很多时候并不能满足现实的需要,现在需要输入两个数字a,b,计算a+b的和。
其中0<=a,b<10^100.
输入a b
输出a+b
样例输入1231 2100 1221000000000000000000000 2
样例输出12332221000000000000000000002
题解1234567891011121314151617181920212223242526272829303132333435#include <iostream>#include <vector>using namespace std;vector<int> add(vector<int> &A, vector<int> &B) { vector<int> C; int t = 0; for (int i = 0; i < A.size() i < B.size(); i++) { if (i <...
题目描述在基于Internet的程序中,我们常常需要判断一个IP字符串的合法性。合法的IP是这样的形式:A.B.C.D其中A、B、C、D均为位于[0, 255]中的整数。为了简单起见,我们规定这四个整数中不允许有前导零存在,如001这种情况。现在,请你来完成这个判断程序吧^_^
输入输入由多行组成,每行是一个字符串。字符串长度最大为30,且不含空格和不可见字符
输出对于每一个输入,单独输出一行如果该字符串是合法的IP,输出Y,否则,输出N
样例输入1234561.2.3.4a.b.c.d267.43.64.1212.34.56.bb210.43.64.129-123.4.5.6
样例输出123456YNNNYN
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475#include <iostream>#include <cstdio...
题目描述现在给出了一个只包含大小写字母的字符串,不含空格和换行,要求把其中的大写换成小写,小写换成大写,然后输出互换后的字符串。
输入第一行只有一个整数m(m<=10),表示测试数据组数。 接下来的m行,每行有一个字符串(长度不超过100)。
输出输出互换后的字符串,每组输出占一行。
样例输入1232AcmACCEPTED
样例输出12aCMaccepted
题解12345678910111213141516#include <iostream>using namespace std;int main() { ios::sync_with_stdio(false); int n; string a; cin>>n; while(n--){ cin>>a; for(int i=0;i<a.size();i++) { if (a[i] >= 'A' && a[i] <...
题目描述For a dynamic list L of integers, perform a sequence of the following operations.
L has a special element called END at the end of the list and an element of L is indicated by a cursor.
insert(x): Insert x before the element indicated by the cursor. After this operation, the cursor points the inserted element.
move(d): Move the cursor to the end by d, if d is positive. Move the cursor to the front by d, if d is negative.
erase(): Delete the element indicated by the cursor. After this ...
题目描述For n dynamic arrays Ai (i=0,1,…,n−1), perform a sequence of the following operations:
pushBack(t, x): Add element x at the end of At.
dump(t): Print all elements in At.
clear(t): Clear At. If At is empty, do nothing.
Ai is a 0-origin array and it is empty in the initial state.
输入The input is given in the following format.
n
q
query1
query2
:
queryq
Each query queryi is given by 0 t x or 1 t or 2 t where the first digits 0, 1 and 2 represent pushBack, dump and clear operat...