Description
Welcome to apply for Zhejiang University. Each zju's processors sor's only admiss one student. And professors 'recruitment criteria are different. interpreter sor only recruit the student whoes exam result is
A and B, including a and B. and then sor will choose the student with the highest exam result in these students. please output this lucky student's exam result. and then the next parent sor will continue to recruit student from the rest of the students.
Input
The input consists one test case. the first line contains an integer n (n <= 300), which means the number of students. the second line contains N integers means the exam results of these N students. as you know, full mark is 500.the third line contains an integer m, which
Means the number of professors. Then follows M lines, each line contains two integer, A and B (0 <= A, B <= 500), which means worker's recruitment criteria.
Output
For each test case, You shoshould output M lines with the recruited student's exam result. If no student meet should sor's requirement, you shoshould output-1.
Sample Input
7
306 304 389 342 343 355 302
4
350 390
380 400
307 303
500 400
Sample output
389
-1
306
-1
Prompt [+]
* ** The prompt is hidden. Click [+] at the top to display it ***
Source
2013 Zhejiang University retest machine test simulation questions
/********************************** Date: * Author: sjf0115 * question: Question 1473: a huge wave of professors is approaching! * Source: http://acmclub.com/problem.php? Id = 1473 * result: AC * Source: re-test computer simulation questions of Zhejiang University in 2013 * conclusion: * *********************************/# include <stdio. h> # include <string. h> int main () {int N, flag, A, B, I, J, M; int grade; int mark [501]; // freopen ("C: \ Users \ SJF \ Desktop \ acm.txt "," r ", stdin); While (scanf (" % d ", & N )! = EOF) {memset (mark, 0, sizeof (Mark); // enter the score for (I = 0; I <n; I ++) {scanf ("% d", & grade); // mark [Grade] ++;} // M instructor scanf ("% d", & M ); // enter the score of the instructor for (I = 0; I <m; I ++) {// The upper limit scanf ("% d", &, & B); // enable a <BIF (A> B) {int temp = A; A = B; B = temp;} flag = 0; // count (j = B; j> = A; j --) {If (MARK [J]) {flag = 1; // output the maximum value printf ("% d \ n", j) that meets the conditions; // This student has been admitted to mark [J] --; break ;}} // output if (flag = 0) {printf ("-1 \ n") ;}} return 0 ;}
# Include <stdio. h> int N; void run () {int I, m, Max, Min, J, K, answer, a [1, 111111]; for (I = 0; I <N; I ++) scanf ("% d", & A [I]); scanf ("% d", & M); For (j = 1; j <= m; j ++) {k =-1; answer =-1; scanf ("% d", & MAX, & min); If (max <min) // The relationship between A and B is uncertain. {I = max; max = min; min = I ;}for (I = 0; I <n; I ++) // if no qualified student is found, answer retains the original value-1 if (a [I]> = min & A [I] <= max) // for qualified students, pay attention to the equal sign if (a [I]> answer) {k = I; // record the student's position, to clear answer = A [I];} printf ("% d \ n", answer); If (k>-1) A [k] =-1; // clear selected student} int main () {scanf ("% d", & N); run (); Return 0 ;}