# Summary of the Sixth individual competition #,
Competition link: click here ~~
Password: nyist
A-Gardenia blossom
Time Limit:1000 MS
Memory Limit:32768KB
64bit IO Format:% I64d & % I64uSubmit Status Practice FZU 1921
Description
This is a season of Gardenia blossom, and also a season of separation. over one thousand days and nights in four years, the corner of the campus fell, leaving us with meditation. The hundreds of rankings, it proves that we have made continuous progress in a very simple way, but these advances are inseparable from the teacher's teaching.
As a computer student, algorithms and data structures are required courses. Therefore, every teacher in the course is very concerned about the learning situation of every student, every day after class, the teacher will give out-of-class tutoring to a student. First, the teacher will give each student a score. If a student asks the teacher to give him tutoring, the teacher will give the student extra-curricular tutoring, the teacher will give tutoring to students with the lowest scores. After the instructor provides tutoring to students, their abilities will increase. However, the growth of different students varies. The instructor wants to know the number and score of the lowest score in the class several days after tutoring for the students.
Input
First, the first behavior T indicates that there is a T group of data. The structure of each group of data is as follows:
The first row has a number n, indicating that there are n students ranging from 1 to n. (1 <= n <= 10000 ).
The next row contains n numbers, which are the initial competence level xi (1 <= xi <= 1000) of students numbered from 1 to n ).
Next, there is a row with a number of m, indicating that the teacher gave students tutoring m days (1 <= m <= 100000 ).
In the next m row, there are two numbers (ai bi) in each row, indicating that the teacher gave the ai students a makeup lesson on the day I, students numbered with ai can improve bi (0 <= ai <= n, 1 <= bi <= 1000 ). If ai is 0, it means that the teacher provides the worst-performing Student counseling today. If there are multiple students at the same time, the students with small numbers will be given additional lessons.
Output
For each group of data, output the number of the first group (starting from 1), and then output the number and score of the students in the class after m days.
Sample Input
1310 20 3030 1003 100 40
Sample Output
Case 1: 3 40
Hint
The above data shows the growth of students' abilities as follows:
Day 1: 110 20 30
Second day: 110 20 40
Third day: 110 60 40
[Solution ]:
At first glance, we can see that it is a line segment tree, but it hasn't been learned yet ~~ Finally, we found that priority queue can be used to solve the problem:
Code:
# Include <stdio. h> // priority queue simulation # include <string. h> # include <stdlib. h> # include <queue> # include <math. h> # include <iostream> # include <algorithm> using namespace std; # define mem (a) memset (a, 0, sizeof (a) struct nod {int val, num; friend bool operator <(nod a, nod B) {if (. val! = B. val) return. val> B. val; else return. num> B. num ;}} a [10050], B; int main () {int t, n, m, I, tot = 1; scanf ("% d", & t ); while (t --) {priority_queue <nod> Q; // it must be added here. If it is placed outside, WA scanf ("% d", & n); for (I = 1; I <= n; I ++) {scanf ("% d", & a [I]. val); a [I]. num = I; Q. push (a [I]);} scanf ("% d", & m); while (m --) {int k, q; scanf ("% d ", & k, & q); if (! K) // when the number is 0 {while (1) {B = Q. top (); // obtain the top Q of the stack. pop (); if (a [B. num]. val = B. val) // judge {a [B. num]. val + = q; Q. push (a [B. num]); // press the stack break;} else {Q. push (a [B. num]); // pressure stack }}else {a [k]. val + = q ;}} B = Q. top (); Q. pop (); while (B. val! = A [B. num]. val) // The last {Q. push (a [B. num]); B = Q. top (); Q. pop ();} printf ("Case % d: % d \ n", tot ++, B. num, B. val);} return 0 ;}
Line Segment tree: (beginner)
The most basic line segment tree. Each node records the id of the minimum value of the current line segment .... therefore, the min_id field of the root node records the number generated by the current shard .. # include <stdio. h> # include <string. h> # include <stdlib. h> # include <queue> # include <math. h> # include <iostream> # include <algorithm> using namespace std; # define lson l, m, rt <1 # define rson m + 1, r, rt <1 | 1 const int maxn = 1e5; int val [maxn <2], num [maxn <2]; # define mem (a) memset (, 0, sizeof (a) void Pushup (int rt) {if (val [rt <1] <= val [rt <1 | 1]) {val [rt] = val [rt <1]; num [rt] = num [rt <1];} else {val [rt] = val [rt <1 | 1]; num [rt] = num [rt <1 | 1] ;}} void Build (int l, int r, int rt) {if (l = r) {scanf ("% d", & val [rt]); num [rt] = l; return ;} int m = (l + r)> 1; Build (lson); Build (rson); Pushup (rt);} void Update (int p, int c, int l, int r, int rt) {if (l = r) {val [rt] + = c; return;} int m = (l + r)> 1; if (p <= m) Update (p, c, lson); else Update (p, c, rson); Pushup (rt) ;}int main () {int T, n, m, p, c, tot = 1; scanf ("% d", & T); while (T --) {scanf ("% d", & n ); build (1, n, 1); scanf ("% d", & m); while (m --) {scanf ("% d", & p, & c); if (p = 0) p = num [1]; Update (p, c, 1, n, 1);} printf ("Case % d: % d \ n ", tot ++, num [1], val [1]) ;}}
B-non-mainstream
Time Limit:1000 MS
Memory Limit:32768KB
64bit IO Format:% I64d & % I64uSubmit Status Practice FZU 1922
Description
Non-mainstream things do not belong to the mainstream, such as cultural sub-cultures, religious cults, and heterogeneous groups. Non-mainstream concepts exist over mainstream ones. One thing can be changed from non-mainstream to mainstream, or from mainstream to non-mainstream. Therefore, there is no absolute mainstream, and there will be no absolute non-mainstream.
There are several duck farms around the new campus of fudao, and of course there are also different duck groups. The duck farm owner believes that these alternative ducks can either sell for a good price or be worthless.
We define the features of each duck as a one-dimensional 0-1 vector, for example:
Among the three ducks, duck a1 has the following options: dist (a1, a1) + dist (a1, a2) + dist (a1, a3 ).
The dist operation is defined:
Dist (a1, a1) = (| 1-1 | + | 0-0 | + | 0-0 | + | 1-1 | + | 0-0 |) = 0
Dist (a1, a2) = (| 1-0 | + | 0-1 | + | 0-0 | + | 1-0 | + | 0-1 |) = 4;
Dist (a1, a3) = (| 1-0 | + | 0-0 | + | 0-1 | + | 1-0 | + | 0-1 |) = 4;
Then we can see that the alternative degree of duck a1 among the three ducks is 8.
The more ducks there are, the greater the risk. Therefore, the boss of the duck farm hopes to determine how many ducks there are in his group.
Input
First, the first behavior T indicates that there is a T group of data. The structure of each group of data is as follows:
Three integers n, m, and p separated by spaces in the first row of data. N indicates that n ducks exist (2 <= n <= 10,000), m indicates that these ducks have m feature values (5 <= m <= 200 ), p indicates the boundary of an alternative degree. a duck that is greater than or equal to p is considered an alternative duck (0 <= p <= 2,000,000 ).
In the next n rows, each row has m numbers 0 or 1 separated by spaces, representing the feature value of the duck.
Output
Output the number of groups (starting from 1) for each row of data, and then output the number of ducks in the group.
Sample Input
13 5 81 0 0 1 00 1 0 0 10 0 1 0 1
Sample Output
Case 1: 1 [solutions ]:
Process 0. and 1.
Code:
// Simulate # include <stdio. h> # include <string. h> # include <stdlib. h> # include <queue> # include <math. h> # include <iostream> # include <algorithm> using namespace std; # define lson l, m, rt <1 # define rson m + 1, r, rt <1 | 1 const int maxn = 1e5; // int val [maxn <2], num [maxn <2]; # define mem () memset (a, 0, sizeof (a) const int N = 10000 + 10; const int M = 200 + 10; int num [N] [M], sum [M]; int main () {int T, n, m, p, tot = 1; scanf ("% d", & T); while (T --) {scanf ("% d", & n, & m, & p); memset (sum, 0, sizeof (sum )); for (int I = 1; I <= n; I ++) {for (int j = 1; j <= m; j ++) {scanf ("% d", & num [I] [j]); if (num [I] [j]) sum [j] ++ ;}} int count = 0; for (int I = 1; I <= n; I ++) {int ans = 0; for (int j = 1; j <= m; j ++) if (num [I] [j]) ans + = n-sum [j]; else ans + = sum [j]; if (ans> = p) count ++;} printf ("Case % d: % d \ n", tot ++, count);} return 0 ;}
D-deadlock
Time Limit:1000 MS
Memory Limit:32768KB
64bit IO Format:% I64d & % I64uSubmit Status Practice FZU 1924
Description
There is a deadlock problem in the operating system.
In the process of execution, the process waits for resources. If there is no external force, they will not be able to proceed. It is said that the system is in a deadlock state or the system has a deadlock. These processes that are always waiting for each other are called deadlock processes.
Because resource usage is mutually exclusive, after a process applies for resources, the relevant process will never be allocated with necessary resources and cannot continue to run without external assistance, this produces a deadlock.
For example, if thread A occupies resource 1 and waits for resource 2, and thread B occupies Resource 2 and waits for resource 1, A deadlock occurs between the two threads.
To describe the problem of system resource allocation, we use a directed graph G to represent the resource allocation diagram. V is the vertex set of the directed graph, including the process node set P = {p 1, p 2 ,..., P n} and Resource Node Set R = {r 1, r 2 ,..., R m}. E is a set of directed edges. Its elements include binary groups (p I, r j) or (r j, p I ). (P I, r j) indicates that process p I applies for resource r j, (r j, p I) indicates that resource r j is occupied by PROCESS p I.
According to the knowledge in the operating system, if no path can be returned from any node in a resource allocation diagram, there is no deadlock in the system, otherwise, deadlocks may exist in the system.
Your task is to allocate a Resource Graph to you to determine whether a deadlock may exist.
Input
The first line of the input is an integer T, indicating that there are T groups of data.
The first row of each group of data is four integers, namely, P, R, E1, and E2. P indicates the number of worker nodes, R indicates the number of resource nodes, and E1 indicates (pi, rj) number of edges. E2 indicates the number of edges (rj, pi). 1 <= P, R <= 500. Next, there are two integers (pi) in each row in line E1, rj, indicating that an edge exists from the node pi to rj. Next, there are two integers rj and pi in each row in the row E2, indicating that an edge exists from the node rj to the pi. 0 <= pi <P, 0 <= rj <R.
Output
Output The number of output groups (starting from 1) for each row of data in each group, and then output "Possible" in case of a deadlock. If no deadlock exists, output an "Impossible" line ".
Sample Input
22 2 1 10 10 13 3 40 01 12 20 12 02 11 2
Sample Output
Case 1: ImpossibleCase 2: Possible
[Solution ]:
Use of the query set:
Code:
// D-deadlock # include <stdio. h> # include <string. h> # include <stdlib. h >#include <iostream >#include <algorithm> using namespace std; int father [1010]; int Find (int x) {if (father [x] = x) return x; else return Find (father [x]);} int scan () {int res = 0, flag = 0; char ch; if (ch = getchar ()) = '-') flag = 1; else if (ch> = '0' & ch <= '9') res = ch-'0 '; while (ch = getchar ()> = '0' & ch <= '9') res = res * 10 + (Ch-'0'); return flag? -Res: res;} int main () {int t, n, m, p, r, e1, e2, x, y, I, tot = 1; t = scan (); while (t --) {bool flag = 0; p = scan (); r = scan (); e1 = scan (); e2 = scan (); for (I = 0; I <p + r; I ++) father [I] = I; for (I = 0; I <e1; I ++) {x = scan (); y = scan (); father [x] = p + y;} for (I = 0; I <e2; I ++) {x = scan (); y = scan (); int a = Find (father [x + p]); int B = Find (father [y]); if (a = B) flag = 1; else father [B] = a;} printf ("Case % d :", tot ++); if (flag) printf ("Possible \ n"); else printf ("Impossible \ n");} return 0 ;}
F-fill in the blanks
Time Limit:1000 MS
Memory Limit:32768KB
64bit IO Format:% I64d & % I64uSubmit Status Practice FZU 1926
Description
"Guan guanpique, in the continent of the river. Ladies and gentlemen ." Many of the classical Chinese texts in high school require reciting, and the Chinese teacher will ask the students to fill in the articles on a regular basis. The teacher will first teach the students a text article, then give some sentences, dig out some spaces, and ask the students to fill the spaces completely. Therefore, the teacher needs to select an article and give an incomplete sentence, and make an answer in advance. However, when the teacher makes a mistake, some sentences cannot be left blank Based on the article. Determine whether the given sentence can be filled in based on the text.
Input
First, the first behavior T indicates that there is a T group of data. The structure of each group of data is as follows:
First, an article is given, ending. The number of words in a document cannot exceed 1000.
The next n (1 <= n <= 1000) indicates that there are n query sentences.
N incomplete sentences are given in the next n rows. The number of words in each sentence is less than or equal to 100 and carries "_", ending. "_" Indicates an unknown word.
The document and the given sentence are both English words and contain lowercase characters without punctuation marks.
Output
For each group of data, first enter the number of rows (starting from 1 ).
For each query sentence of each group of data, answer "YES" and "NO ".
YES indicates that the sentence can be entered based on the content of the article.
NO indicates that the sentence cannot be entered based on the content of the article.
Sample Input
1 much of the language used to describe monetary policy such as steering the economy to a soft landing or a touch on the brakes makes it sound like a precise science nothing cocould be further from the truth @ 3 much of the language _ describe monetary policy @ steering the economy to a _ landing @ much of the _ describe monetary @
Sample Output
Case 1: YESYESNO [solution ]:
Kmp algorithm:
Code:
Problem 1926 fill in the blanks # include <iostream> # include <stdio. h> # include <stdlib. h> # include <string. h> # include <math. h> # include <set> # include <queue> # include <vector> # include <map> # include <algorithm> int a [200001], B [200001], dp [300]; int aa [10011] [300]; int father [1005]; int n, m, t, bb, I, j; using namespace std; const int maxn = 1005; char str [maxn]; string s [maxn], s2 [maxn]; int next [maxn]; int lens, lens2; struct node {int X, y, sum;} p [10000]; int Find (int x) {if (x! = Father [x]) return father [x] = Find (father [x]); return x;} void init (string s2 []) // construct the next Array {int I = 0, j =-1; next [0] =-1; while (I <lens2) {if (j =-1 | s2 [I] = s2 [j] | s2 [I] = "_" | s2 [j] =" _") next [++ I] = ++ j; else j = next [j] ;}} int kmp (string s [], string s2 []) // KMP {int I = 0, j = 0; init (s2); while (I <lens) {while (I <lens & j <lens2) {if (j =-1 | s [I] = s2 [j] | s2 [j] = "_") {I ++; j ++;} else j = next [j];} if (j = lens2) return true;} return false;} int main () {int t, m, cas = 1; scanf ("% d", & t); while (t --) {int ss = 0; while (scanf ("% s", str )) {if (strcmp (str, "@") = 0) break; s [ss ++] = string (str) ;}printf ("Case % d: \ n ", cas ++); lens = ss; scanf (" % d ", & m); while (m --) {ss = 0; while (scanf ("% s", str) {if (strcmp (str, "@") = 0) break; s2 [ss ++] = string (str);} lens2 = ss; // printf ("Case % d: \ n", cas ++ ); if (kmp (s, s2) printf ("YES \ n"); else printf ("NO \ n") ;}} return 0 ;}
I-An Equation
Time Limit:1000 MS
Memory Limit:32768KB
64bit IO Format:% I64d & % I64uSubmit Status Practice FZU 1909
Description
Given four integers, your task is to find out whether there is a permutation A, B, C, D, such that the equation A + B = C + D holds.
For example, if there are four integers 2, 5, 6, 3, we cocould find out an equation 2 + 6 = 3 + 5 that satisfies A + B = C + D. if there are four integers 1, 2, 4, 9, we cocould not find out any equation that satisfies A + B = C + D.
If we cocould use these four integers to form an equation that satisfies A + B = C + D, please output "Yes", otherwise output "No" instead.
Input
The first line of the input contains an integer T (T <= 10), indicating the number of cases. each case begins with a line containing four integers a, B, c, d (1 <= a, B, c, d <= 10 ).
Output
For each test case, print a line containing the test case number (beginning with 1) and whether there is a permutation A, B, C, D, such that the equation A + B = C + D holds.
Sample Input
42 3 5 64 3 2 12 1 1 21 2 4 9
Sample Output
Case 1: YesCase 2: YesCase 3: YesCase 4: No [solution ]:
Simulation:
I - An Equation:#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <algorithm>using namespace std;int a[4];int main(){ int t,tot=1; scanf("%d",&t); while(t--) { scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]); sort(a,a+4); if(a[0]+a[3]==a[1]+a[2]) printf("Case %d: Yes\n",tot++); else printf("Case %d: No\n",tot++); } return 0;}