Fourth session CCF software Competency Certification

Source: Internet
Author: User
Tags cmath

1. Image rotation

Problem description

Rotation is the basic operation of image processing, in which you need to rotate an image 90 degrees counterclockwise.
The image representation in a computer can be represented by a matrix, in order to rotate an image, only the corresponding matrix is rotated.

Input format

The first line of input contains two integers n, m, representing the number of rows and columns of the image matrix, respectively.
The next n rows contain m integers for each row, representing the input image.

Output format

Output m rows, each containing n integers, representing the matrix after the original matrix rotated 90 degrees counterclockwise.

Sample input

2 3
1 5 3
3 2 4

Sample output

3 4
5 2
1 3

Measuring use case size and conventions

1≤n, m≤1,000, the number in the matrix is not more than 1000 non-negative integers.

1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <cmath>6# define LLLong Long7 using namespacestd;8 9 inta[1010][1010] ;Ten  One intMain () A { -     //freopen ("In.txt", "R", stdin); -     intN, M; thescanf"%d%d", &n, &m); -     intI, J; -      for(i =0; I < n; i++) -          for(j =0; J < M; J + +) +scanf"%d", &a[i][j]); -      for(i = m1; I >=0; i--) +     { A          for(j =0; J < N; J + +) at         { -printf"%d", A[j][i]); -         } -printf"\ n") ; -     } -  in  -     return 0 ; to}
View Code

2. Sorting by Numbers

Problem description

given n integers, count the number of occurrences of each integer and output in the order of occurrences, from many to fewer.

Input format

The first line of input contains an integer n, which represents the number of a given number.
The second row contains n integers, separated by a space between adjacent integers, representing the given integer.

Output format

Outputs multiple lines, each containing two integers, representing a given integer and the number of times it appears. Output in descending order of occurrences. If two integers occur as many times as possible, the output value is smaller and the output value is larger.

Sample input

12
5 2 3 3 1 3 4 2 5 2 3 5

Sample output

3 4
2 3
5 3
1 1
4 1

Measuring use case size and conventions

1≤n≤1000, the given number is a non-negative integer of not more than 1000.

1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <cmath>6# define LLLong Long7 using namespacestd;8 9 structShuTen { One     intnum; A     intID; -}a[1010]; -  the BOOLCMP (Shu x, shu y) - { -     if(X.num = =y.num) -         returnX.id <y.id; +     Else -         returnX.num >Y.num; + } A  at intMain () - { -     //freopen ("In.txt", "R", stdin); -     intN; -scanf"%d", &n); -     inti, X; in      for(i =1; I <=1005; i++) -     { toA[i].id =i; +A[i].num =0 ; -     } the  *      while(n--) $     {Panax Notoginsengscanf"%d", &x); -a[x].num++ ; the     } +Sort (A +1, A +1005, CMP); A      for(i =1; I <=1005; i++) the     { +         if(A[i].num = =0) -              Break ; $printf"%d%d\n", A[i].id, a[i].num); $     } -  -  the     return 0 ; -}
View Code

3. Festivals

Problem description

The dates for a class of festivals are not fixed, but are set down in the form of "B-week C" in "a month", for example, Mother's Day is set as the second Sunday of May each year.
Now, give you a,b,c and Y1, y2 (1850≤y1, y2≤2050), and I hope you export the date from the year of A.D. Y1 year to the first B week of the month of A.D. y2 years.
Tip: Rules about leap years: A year is an integer multiple of 400 when it is a leap year, otherwise a multiple of 4 and not a multiple of 100 is a leap year, and the other years are not leap. For example, 1900 is not a leap year, and 2000 is a leap year.
To facilitate your reckoning, it is known that January 1, 1850 is Tuesday.

Input format

The input contains exactly one row, with five integers a, B, C, Y1, Y2. Among them c=1, 2, ..., 6, 7 respectively Monday 、......、 six, day.

Output format

For each year between Y1 and Y2, including Y1 and Y2, output a row in the order of the year from small to large.
If the month B of the year does exist, it is output in the format "YYYY/MM/DD", that is, the four-digit year, the two-digit month, the two-digit date, the middle slash "/", and the number of digits before 0.
If the month B of the year does not exist, the output is "none" (with no double quotes).

Sample input

5 2 7) 2014 2015

Sample output

2014/05/11
2015/05/10

Measuring use case size and conventions

All evaluation cases are met: 1≤a≤12,1≤b≤5,1≤c≤7,1850≤y1, y2≤2050.

4. Network delay

Omitted..

5.

Minimum cost

Problem description

c There are N cities in the communist countries. There are n-1 two-way road, each road connects two cities, and any two cities can reach each other. Small R to travel to the country of C, he planned the route of M-route, the first line of travel is Si, the end point is Ti. In the course of travel, little R needs to eat one unit of food per walk of a unit length of road. Food in C countries can only be bought in cities, and the prices of food in different cities may vary.
However, Little R does not want to detour the road in order to buy a lower-priced food during the trip, so he always chooses the nearest way to go. Now, please calculate the minimum cost per travel route for the small R plan.

Input format

The first line contains 2 integers of N and M.
The second line consists of n integers. The first integer WI represents the food price of the city I.
Next n-1 line, each line consists of 3 integers u, V, E, which indicates a two-way road with E between City U and City v.
Next m line, each row contains 2 integers si and ti, each representing the start and end of a travel route.

Output format

The output m lines represent the minimum cost of each travel plan.

Sample input

6 4
1 7 3 2 5 6
1 2 4
1 3 5
2 4 1
3 5 2
3 6 1
2 5
4 6
6 4
5 6

Sample output

35
16
26
13

Sample Description

For the first route, the small R will pass through the 2->1->3->5. 2 of them in the city for 7 of the price to buy 4 units of food, to the City 1 o'clock all eat, and 1 of the price to buy 7 units of grain, and then reached the end.

Measuring use case size and conventions

The first 10% evaluation cases meet: N, m≤20, wi≤20;
The first 30% evaluation cases meet: N, m≤200;
Another 40% of the evaluation cases are met: One city is at most connected to two other cities.
All evaluation cases are met: 1≤n, m≤105,1≤wi≤106,1≤e≤10000.

Fourth session CCF software Competency Certification

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.