Codeforces round #194 (first two questions)

Source: Internet
Author: User
A. Candy bagstime limit per test

1 second

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Gerald hasNYounger brothers and their number happens to be even. One day he boughtN2 candy
Bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integerKFrom 1N2 he
Has exactly one bagKCandies.

Help him giveNBags of candies to each brother so that all brothers got the same number of candies.

Input

The single line contains a single integerN(NIs
Even, 2 bytes ≤ averageNLimit ≤ limit 100)-the number of Gerald's brothers.

Output

Let's assume that Gerald indexes his brothers with numbers from 1N.
You need to printNLines, onI-Th line printNIntegers
-The numbers of candies in the bags forI-Th brother. Naturally, all these numbers shoshould be distinct and be within limits from 1N2.
You can print the numbers in the lines in any order.

It is guaranteed that the solution exists at the given limits.

Sample test (s) Input
2
Output
1 42 3
Note

The sample shows Gerald's actions if he has two brothers. in this case, his bags contain 1, 2, 3 and 4 candies. he can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.

Give you an even N, from 1 to n ^ 2. Divide them into N portions, N numbers for each portion, and the sum of each portion is equal. Output n copies.
Solution: Let's give an example to illustrate my ideas. Example 1 ~ 16. it is divided into four parts, which exist in a two-dimensional array. A [4] [4] = {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16 }}. in each grid, take one from the relative position. For example, if you take 1, you cannot take 5, 9, 13, and then take 6 and then take 10, 14. according to this rule, the N copies are found.
Address: codeforces #194 round a. candy bags
AC code:
# Include <cstdio> # include <iostream> # include <cstring> # include <string> using namespace STD; int main () {int N, I, j; int flag = 0; int A [102] [102]; while (CIN> N) {for (I = 0; I <n; I ++) for (j = 1; j <= N; j ++) A [I] [J-1] = I * n + J; for (I = 0; I <N; I ++) {flag = 0; For (j = 0; j <n; j ++) {If (flag = 0) {flag = 1; cout <A [J] [(j + I) % N]; // For example, if 4*4 = 16, a [4] [4] = {1, 2, 3, 4}, {5, 6, 7, 8} {9, 10, 11, 12}, {13, 14, 15, 16} // each time, the relative position of each grid is output, output 1 can output 6, 7, or 8, but cannot output 5, 9, 13} else cout <"" <A [J] [(j + I) % N];} cout <Endl ;}} return 0 ;}
B. Eight Point setstime limit per test

1 second

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Gerald is very particle to eight point sets. he thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, should t for the average
Of these nine points. In other words, there must be three IntegersX1, bytes,X2, bytes,X3 and
Three more IntegersY1, bytes,Y2, bytes,Y3,
Such thatX1 worker <workerX2 bytes <averageX3,Y1 worker <workerY2 bytes <averageY3 and
The eight point set consists of all points (XI, Bytes,YJ) (1 limit ≤ limitI, Bytes,JLimit ≤ limit 3 ),
Before t for point (X2, bytes,Y2 ).

You have a set of eight points. Find out if Gerald can use this set?

Input

The input consists of eight lines,I-Th line contains two space-separated IntegersXIAndYI(0 bytes ≤ bytesXI, Bytes,YILimit ≤ limit 106 ).
You do not have any other conditions for these points.

Output

In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly"
Otherwise.

Sample test (s) Input
0 00 10 21 01 22 02 12 2
Output
respectable
Input
0 01 02 03 04 05 06 07 0
Output
ugly
Input
1 11 21 32 12 22 33 13 2
Output
ugly

I will give you eight points. If there are (x1, Y1), (x1, Y2), (x1, Y3), (X2, Y1), (X2, y3), (X3, Y1), (X3, Y2), (X3, Y3 ). in this order, and there is (X1 <X2 <X3, Y1 <Y2 <Y3. Output respectable if conditions are met; otherwise, output ugly.
Solution: sort the eight points entered each time by size, and then use the fragment condition.
Address: codeforces round #194 B. Eight point sets
AC code:

# Include <cstdio> # include <iostream> # include <cstring> # include <string> # include <algorithm> using namespace STD; struct node // X of eight vertices, y. {int X; int y ;}; int CMP (node A, Node B) // Press (x1, Y1), (x1, Y2), (x1, Y3 ), (X2, Y1), (X2, Y3), (X3, Y1), (X3, Y2), (X3, Y3 ). {if (. x <B. x) return 1; else if (. X = B. X &. Y <B. y) return 1; else return 0;} int main () {int I; node P [9]; while (~ Scanf ("% d", & P [0]. x, & P [0]. y) {for (I = 1; I <8; I ++) scanf ("% d", & P [I]. x, & P [I]. y); sort (p, p + 8, CMP); If (P [0]. X = P [1]. X & P [1]. X = P [2]. X & P [3]. X = P [4]. X & P [5]. X = P [6]. X & P [6]. X = P [7]. X & P [0]. y = P [3]. Y & P [3]. y = P [5]. Y & P [1]. y = P [6]. Y & P [2]. y = P [4]. Y & P [4]. y = P [7]. Y & P [0]. x <p [3]. X & P [3]. x <p [5]. X & P [0]. Y <p [1]. Y & P [1]. Y <p [2]. y) cout <"respectable" <Endl; // sort by size. If yes, the respectable is output. else cout <"ugly" <Endl;} return 0 ;}

When I arrived at home more than three o'clock P.M. yesterday, I had a rush to report my name. At the beginning, I found that the computer had only power, and then I was in a hurry to find the charger. The pace of the competition was quite good, but it was about 45 minutes before the competition was over and suddenly went out of service. The air conditioner didn't work and suddenly felt a little pain in the head. However, I had a good idea at the second question, I am going to take a rest after I finish the second question, because I haven't slept at noon. After writing the sample, the page is refreshed and cannot be displayed when you prepare to submit it in 50 minutes. How to cut off the network, Dad said with a smile, the power must be cut off .... In the end, the house was so hot that the family went out for a barbecue and called at half past eight.
The learning environment at home is not very good. The whole family is Yue feifeng. My father caught up with 24 sets, my mother caught up with 19 sets, and my sister caught up with 14 sets, I also saw Episode 1 last night...
In the beginning, CF dropped all rating .. It's just a waste. Now I finally find a bit of feeling. Let's take a look at the CDE later ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.