题目1473: A Huge Wave Of Professors Is Approaching!

题目描述

Welcome to apply for Zhejiang University.Each ZJU's professor's only admiss one student.And professors' recruitment criteria are different.Professor only recruit the student whoes exam result is between A and B,including A and B.And then professor will choose the student with the highest exam result in these students.Please output this lucky student's exam result.And then the next professor will continue to recruit student from the rest of the students.

 

输入

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 professor's recruitment criteria.

 

输出

For each test case, you should output m lines with the recruited student's exam result.If no student meet professor's requirement,you should output -1.

 

样例输入
7
306 304 389 342 343 355 302
4
350 390
380 400
307 303
500 400
 

样例输出
389
-1
306
-1
 

提示 [+]

*** 提示已隐藏,点击上方 [+] 可显示 ***

 

来源

2013年浙江大学复试机试模拟题

 


/*********************************
*   日期:2013-3-23
*   作者:SJF0115
*   题号: 题目1473: A Huge Wave Of Professors Is Approaching!
*   来源:http://acmclub.com/problem.php?id=1473
*   结果:AC
*   来源:2013年浙江大学复试机试模拟题
*   总结:
**********************************/
#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));
		//输入成绩
		for(i = 0;i < N;i++){
			scanf("%d",&grade);
			//标记一下
			Mark[grade] ++;
		}
		//M个导师
		scanf("%d",&M);
		//输入导师的分数段
		for(i = 0;i < M;i++){
			//上限 下限
			scanf("%d %d",&a,&b);
			//交换一下使a < b
			if(a > b){
				int temp = a;
				a = b;
				b = temp;
			}
			flag = 0;
			//统计人数
			for(j = b;j >= a;j--){
				if(Mark[j]){
					flag = 1;
					//输出满足条件的最大值
					printf("%d\n",j);
					//该学生已被录取
					Mark[j] --;
					break;
				}
			}
			//输出
			if(flag == 0){
				printf("-1\n");
			}
		}
	}
	return 0;
} 



#include<stdio.h>
int n;
void run()
{
        int i,m,max,min,j,k,answer,a[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%d",&max,&min);
                if(max<min)//A与B的大小关系不确定
                {
                        i=max;
                        max=min;
                        min=i;
                }
                for(i=0;i<n;i++)//如果找不到符合条件的学生,answer保持原值-1 
                        if(a[i]>=min&&a[i]<=max)//符合条件的学生,注意等号
                                if(a[i]>answer)
                                {
                                        k=i;//记录这个学生的位置,以便清除
                                        answer=a[i];
                                }
                printf("%d\n",answer);
                if(k>-1)
                        a[k]=-1;//清除被选中的学生
        }
}
int main()
{
        scanf("%d",&n);
        run();
        return 0;
}


你可能感兴趣的:(复试上机)