Codeforces Round #277.5 (Div. 2)部分题解_html/css_WEB-ITnose
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.
Note that in this problem you do not have to minimize the number of swaps ? your task is to find any sequence that is no longer than n.
Input
The first line of the input contains integer n (1?≤?n?≤?3000) ? the number of array elements. The second line contains elements of array: a0,?a1,?...,?an?-?1 (?-?109?≤?ai?≤?109), where ai is the i-th element of the array. The elements are numerated from 0 to n?-?1 from left to right. Some integers may appear in the array more than once.
Output
In the first line print k (0?≤?k?≤?n) ? the number of swaps. Next k lines must contain the descriptions of the kswaps, one per line. Each swap should be printed as a pair of integers i, j (0?≤?i,?j?≤?n?-?1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i?=?j and swap the same pair of elements multiple times.
If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
Sample test(s)
input
55 2 5 1 4
output
20 34 2
input
610 20 20 40 60 60
output
input
2101 100
output
10 1
/************************************************************************* > File Name: cf.cpp > Author: acvcla > QQ: > Mail: acvcla@gmail.com > Created Time: 2014年11月17日 星期一 23时34分13秒 ************************************************************************/#include#include#include#include#include#include
B. BerSU Ball
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
Input
The first line contains an integer n (1?≤?n?≤?100) ? the number of boys. The second line contains sequencea1,?a2,?...,?an (1?≤?ai?≤?100), where ai is the i-th boy's dancing skill.
Similarly, the third line contains an integer m (1?≤?m?≤?100) ? the number of girls. The fourth line contains sequence b1,?b2,?...,?bm (1?≤?bj?≤?100), where bj is the j-th girl's dancing skill.
Output
Print a single number ? the required maximum possible number of pairs.
Sample test(s)
input
41 4 6 255 1 5 7 9
output
input
41 2 3 4410 11 12 13
output
input
51 1 1 1 131 2 3
output
直接贪心就好/************************************************************************* > File Name: cf.cpp > Author: acvcla > QQ: > Mail: acvcla@gmail.com > Created Time: 2014年11月17日 星期一 23时34分13秒 ************************************************************************/#include#include#include#include#include#include
C. Given Length and Sum of Digits...
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1?≤?m?≤?100,?0?≤?s?≤?900) ? the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers ? first the minimum possible number, then ? the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Sample test(s)
input
2 15
output
69 96
input
3 0
output
-1 -1
/************************************************************************* > File Name: cf.cpp > Author: acvcla > QQ: > Mail: acvcla@gmail.com > Created Time: 2014年11月17日 星期一 23时34分13秒 ************************************************************************/#include#include#include#include#include#include
D. Unbearable Controversy of Being
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one intersection to the other one. The capital of Berland is very different!
Tomash has noticed that even simple cases of ambiguity confuse him. So, when he sees a group of four distinct intersections a, b, c and d, such that there are two paths from a to c ? one through b and the other one through d, he calls the group a "damn rhombus". Note that pairs (a,?b), (b,?c), (a,?d), (d,?c) should be directly connected by the roads. Schematically, a damn rhombus is shown on the figure below:
Other roads between any of the intersections don't make the rhombus any more appealing to Tomash, so the four intersections remain a "damn rhombus" for him.
Given that the capital of Berland has n intersections and m roads and all roads are unidirectional and are known in advance, find the number of "damn rhombi" in the city.
When rhombi are compared, the order of intersections b and d doesn't matter.
Input
The first line of the input contains a pair of integers n, m (1?≤?n?≤?3000,?0?≤?m?≤?30000) ? the number of intersections and roads, respectively. Next m lines list the roads, one per line. Each of the roads is given by a pair of integers ai,?bi (1?≤?ai,?bi?≤?n;ai?≠?bi) ? the number of the intersection it goes out from and the number of the intersection it leads to. Between a pair of intersections there is at most one road in each of the two directions.
It is not guaranteed that you can get from any intersection to any other one.
Output
Print the required number of "damn rhombi".
Sample test(s)
input
5 41 22 31 44 3
output
input
4 121 21 31 42 12 32 43 13 23 44 14 24 3
output
12暴力就好,如果u,v之间长度为2的路径有x条,且x>1,那么显然以u,v为起点和终点的四边形有c(x,2)个
/************************************************************************* > File Name: cf.cpp > Author: acvcla > QQ: > Mail: acvcla@gmail.com > Created Time: 2014年11月17日 星期一 23时34分13秒 ************************************************************************/#include#include#include#include#include#include
F. Special Matrices
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
An n?×?n square matrix is special, if:
You are given n and the first m rows of the matrix. Print the number of special n?×?n matrices, such that the first m rows coincide with the given ones.
As the required value can be rather large, print the remainder after dividing the value by the given numbermod.
Input
The first line of the input contains three integers n, m, mod (2?≤?n?≤?500, 0?≤?m?≤?n, 2?≤?mod?≤?109). Thenm lines follow, each of them contains n characters ? the first rows of the required special matrices. Each of these lines contains exactly two characters '1', the rest characters are '0'. Each column of the given m?×?ntable contains at most two numbers one.
Output
Print the remainder after dividing the required value by number mod.
Sample test(s)
input
3 1 1000011
output
input
4 4 1005000110101001011001
output
Note
For the first test the required matrices are:
011101110011110101
In the second test the required matrix is already fully given, so the answer is 1.
具体看代码
/************************************************************************* > File Name: cf.cpp > Author: acvcla > QQ: > Mail: acvcla@gmail.com > Created Time: 2014年11月17日 星期一 23时34分13秒 ************************************************************************/#include#include#include#include#include#include
推荐阅读
-
Codeforces Round #659 (Div. 2) 题解
-
Codeforces Round #654 (Div. 2) - 题解
-
Educational Codeforces Round 98 (Rated for Div. 2) A-E 题解
-
Codeforces Round #670 (Div. 2) (A~E题解)
-
Codeforces Round #491 (Div. 2)部分题解
-
Codeforces Round #256 (Div. 2) 题解
-
Codeforces Round #156 (Div. 2)-A. Greg's Workout_html/css_WEB-ITnose
-
Codeforces Round #107 (Div. 2)-A. Soft Drinking_html/css_WEB-ITnose
-
Codeforces Round #191 (Div. 2)-A. Flipping Game_html/css_WEB-ITnose
-
Codeforces Round #279 (Div. 2)_html/css_WEB-ITnose