2018 National multi-school algorithm winter Camp Practice competition (fourth session) ABCFH

Source: Internet
Author: User

A Oil Collection

Links: Https://www.nowcoder.com/acm/contest/76/A
Source: Niu Ke Net

Title Description

With the issue of oil spills at sea, a new lucrative industry is being created, which is the oil-skimming industry. Today, a large amount of oil floating in the Gulf of Mexico attracts a lot of businessmen's attention. These businessmen have a special kind of plane, can be a scoop over the entire sea 20 meters by 10 meters such a large rectangle. (adjacent or left and right adjacent to the lattice, can not be inclined to come) of course, this requires a scoop of the past is all oil, if there is oil in a ladle there is water, it is meaningless, the resources are completely unusable. Now, businessmen want to know how much oil he can get in this area.

The map is a NXN network, each of which represents a square area of 10mx10m, each of which is marked with oil or water.
Input Description:
Test input contains multiple test data
The first line of the test data gives the number of test data T (t<75)
Each test sample uses the number n (n<50) to represent the size of the map area, followed by n lines with n characters in each row, where the symbol '. ' Indicates the surface of the sea, symbol ' # ' represents the oil surface.
Output Description:
The output format is "Case X:m" (X starting from 1) and M is the maximum amount of oil a trader can get.
Example 1 input
16.......##..........#. #.. #.. ##......
Output
Case 1:3


For the number of # 2 wide to 1, because two are connected, then the coordinates (x, y) are added must be an odd even, each # block statistics after odd numbers, the smallest one must be the largest of the region block.

#include <bits/stdc++.h> #define LL long longusing namespace std;const int n = 55;char Str[n][n];int t, N, ANS1, ans2 ; void Dfs (int x, int y) {if (1 > x | | x > N | | 1 > y | | y > N | | str[x][y] = = '. ') return; ((x+y) &1)? ans1++: Ans2++;str[x][y] = '. '; DFS (X+1,y);d FS (x-1,y);d FS (x,y-1);d FS (x,y+1);}  int main () {cin >> t;for (int ca = 1; CA <= T; CA + +) {cin >> n;for (int i = 1; I <= n; i + +) cin >> Str[i]+1;int ans = 0;for (int i = 1; I <= n; i + +) {for (int j = 1; J <= N; j + +) {if (str[i][j] = = ' # ') {ans1 = Ans2 = 0;dfs (i,j); ans + = min (ans1, ans2);}} printf ("Case%d:%d\n", Ca,ans);} return 0;}

B Road Construction

Links: https://www.nowcoder.com/acm/contest/76/b
Source: Niu Ke Net

Title Description

As today's society continues to change and traffic problems become more important, the mayor decides to build roads to facilitate trade and transactions between cities. Although the mayor's idea is very good, but he also met the general people also often headache problem, that is the money at hand is limited ... In the planning process, designers have budgeted for some of the cities to build road funding needs. Now the mayor wants to know if it will be able to make his M-City road traffic in a limited amount of money. If you can, output yes, otherwise output no (two cities do not have to be directly connected to the road, indirect road can also be reached.) )

Input Description:
Test input contains multiple test data
The 1th line of each test data gives the available funding of C (<1000000), the number of roads N (n<10000), and the number of cities m (<100).
The next n rows give information on the cost of establishing the highway, with each row giving three integers, each connected to two Cities V1, V2 (0<v1,v2<=m) and the cost H (h<100) required to build the road.
Output Description:
For each test case, output yes or No.
Example 1 input
20 10 51 2 61 3 31 4 41 5 52 3 72 4 72 5 83 4 63 5 94 5 2
Output
Yes
Example 2 input
10 2 21 2 51 2 15
Output
Yes
Note:
Multiple lines may exist between two cities


Template problem for minimum spanning tree
#include <bits/stdc++.h>using namespace Std;const int N = 10010;int c, N, m;struct Nod {int u, V, W;} Nod[n];int fa[110], Ans;bool CMP (nod A, nod b) {return A.W < B.W;} void Init () {for (int i = 0; i <; i + +) fa[i] = I;ans = 0;} int find (int x) {return fa[x] = = x x:find (fa[x]);} void Uni (int x, int y) {x = find (x), y = Find (Y), if (x > Y) fa[x] = Y;else Fa[y] = x;} int main () {while (scanf ("%d%d%d", &c,&n,&m)! = EOF) {init (); for (int i = 0; i < n; i + +) {cin >> nod[i] . u >> nod[i].v >> nod[i].w;} Sort (nod,nod+n,cmp); for (int i = 0; i < n; i + +) {if (Find (nod[i].u)! = Find (NOD[I].V)) {ans + = Nod[i].w;uni (Nod[i].u,nod [I].V);}} if (ans > C) printf ("no\n"), Else printf ("yes\n");}}

C seeking Intersection

Links: https://www.nowcoder.com/acm/contest/76/c
Source: Niu Ke Net

Title Description
Give you two sets in ascending order, and find the intersection of the two sets.
Input Description:
There are multiple test cases, entered to the end of the file.
For each test case:
The first line enters two integers n,m (0<n,m<=1000000), representing the number of elements of the first and second sets, respectively.
The second line enters n integers, representing the elements in the first collection, separated by a space between the elements.
The third line enters a m integer that represents the elements in the second set, separated by spaces between the elements.
The range of elements in the two set is within the [ -1000000000,1000000000] interval.
Output Description:
Each test case outputs all elements of the intersection of two sets (elements separated by spaces and sorted in ascending order) with one line, and output "empty" if the intersection is empty.
Example 1 input
2 31 31) 2 3
Output
1 3
Note:
When the intersection is empty, the output is "empty".

Start with set, found that memory is super, the use of the array storage, and because it is sorted well, it does not need to sort, the direct two-point search.
#include <bits/stdc++.h> #define LL long longusing namespace Std;int N, m, x;const int n = 1000010;int vis[n];vector& lt;int> Vs;bool Bin (int x) {int L = 1, R = N;while (L <= r) {int m = (l+r) >> 1;if (vis[m] = = x) return true;els E if (Vis[m] > x) r = m-1;else L = m+1;} return false;} int main () {while (CIN >> n >> m) {vs.clear (); for (int i = 1; I <= n; i + +) {scanf ("%d", &vis[i]);} for (int i = 1; I <= m; i + +) {scanf ("%d", &x), if (Bin (x)) vs.push_back (x);} if (Vs.empty ()) printf ("empty\n"), else {for (int i = 0, Len = vs.size (); i < Len; i + +) {printf ("%d%c", Vs[i], (i==len-1)? ' \ n ': ');}}} return 0;}

F call to your teacher

Links: https://www.nowcoder.com/acm/contest/76/f
Source: Niu Ke Net

After the title is out of the lab, you suddenly find that you have left your computer in the lab, but the lab teacher has locked the door. To make things worse, you don't have the teacher's phone number. You start by calling everyone you know, asking if they have a teacher's phone number, and if they don't, they'll ask their classmates to ask for their phone numbers. So, can you contact the teacher and get the computer? Input Description:
There are several samples of test sample
The first line of each sample is two integers n (1<n<=50), M (1<m<=2000), n is the number of people that appear in the title, where your serial number is number 1th, and the number of the lab teacher is N.
The next M-line, each line has two integers x (1<=x<=n), Y (1<=y<=n), which represents the phone number x has y.
Output Description:
For each set of sample samples, if you can eventually contact the teacher, output "Yes", otherwise output "No".
Example 1 input
5 51 32 33 42 44 5
Output
Yes
Example 2 input
4 31 22) 34 1
Output
No

Simple DFS issues
#include <bits/stdc++.h> #define LL long longusing namespace std;vector<int> vs[55];bool vis[55], Flag;int N, M;void Init () {for (int i = 0; i <; i + +) {vs[i].clear (); vis[i] = 0;} Flag = false;} void Dfs (int x) {for (int i = 0; i < vs[x].size (); i + +) {int y = vs[x][i];if (y = = N) {flag = True;return;} if (!vis[y]) {Vis[y] = True;dfs (y);}}} int main () {while (CIN >> n >> m) {init (); for (int i = 1; I <= m; i + +) {int x, y;cin >> x >> y;v S[x].push_back (y);} DFS (1); if (flag) printf ("yes\n"), Else printf ("no\n");} return 0;}

H Lao Tzu's whole arrangement?

Links: https://www.nowcoder.com/acm/contest/76/h
Source: Niu Ke Net

The topic describes the old Li saw the monk won his own wine, but he also reluctant to play up the cheat, to the monk said, light Wu not, and then to point to the text, you give me out 1-8 of the full sort, I let you drink, this time will not play you, you can help the monk? Input Description:
No
Output Description:
The full arrangement of the 1~8 is output in the order of the full arrangement, with no spaces at the end of each line.
Example 1 input
No_input
Output
Full arrangement of 1~8
Note:
All-in-all arrangement  :
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

Registration questions.
#include <bits/stdc++.h> #define LL long longusing namespace Std;int a[] = {1,2,3,4,5,6,7,8};int main () {do{for (int i = 0; I < 8; i + +) {printf ("%d%c", A[i], (i==7)? ' \ n ': ');}} while (Next_permutation (a,a+8)); return 0;}

2018 National multi-school algorithm winter Camp Practice competition (fourth session) ABCFH

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.