2011浙大研究生机试题

(1)

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=15;
int a[maxn][maxn];
int m,n;

int main()
{
	while(scanf("%d",&m)!=EOF)
	{
		if(!m) break;
		scanf("%d",&n);
		memset(a,0,sizeof(a));
		int i,j,k=2;
		while(k--)
		{
			for(i=0;i<m;i++)
				for(j=0;j<n;j++)
				{
					int temp;
					scanf("%d",&temp);
					a[i][j]+=temp;
				}
		}
		int sum=0,flag;
			for(i=0;i<m;i++)
			{
				flag=1;
				for(j=0;j<n;j++)
					if(a[i][j])
					{
						flag=0;
						break;
					}
				if(flag) sum++;
			}
			for(j=0;j<n;j++)
			{
				flag=1;
				for(i=0;i<m;i++)
					if(a[i][j])
					{
						flag=0;
						break;
					}
				if(flag) sum++;
			}
			printf("%d\n",sum);
	}
	return 0;
}

(2)

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int p,t,g1,g2,g3,gj;

int max(int a,int b)
{
	return a>b?a:b;
}
int main()
{
	while(cin>>p>>t>>g1>>g2>>g3>>gj)
	{
		if(abs(g1-g2)<=t)
			printf("%.1f\n",((float)g1+g2)/2);
		else
		{
			if(abs(g1-g3)<=t||abs(g2-g3)<=t)
			{
				if(abs(g1-g3)<=t&&abs(g2-g3)<=t)
				{
					printf("%.1f\n",(float)max(max(g1,g2),g3));
				}
				else
				{
					if(abs(g1-g3)<abs(g2-g3))
					{
						printf("%.1f\n",((float)g1+g3)/2);
					}
					else
					{
						printf("%.1f\n",((float)g2+g3)/2);
					}
				}
			}
			else printf("%.1f\n",(float)gj);
		}
	}
	return 0;
}

(3)

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=2*1000000+10;
int m,n;
int a[maxn];
int main()
{
	while(scanf("%d",&m)!=EOF)
	{
		int i,j;
		for(i=0;i<m;i++)
			scanf("%d",&a[i]);
		scanf("%d",&n);
		for(j=0;j<n;j++)
			scanf("%d",&a[m+j]);
		sort(a,a+m+n);
		printf("%d\n",a[(m+n-1)/2]);
	}
	return 0;
}

(4)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

const int maxn=40000+10;
const int maxm=100+10;
const int maxk=5+2;
int n,m,k;
typedef struct
{
	int ge,gi,no;
	int pre[maxk];
}student;
student stu[maxn];
bool sel[maxn];
int quo[maxm];


int cmp(student a,student b)
{
	if((a.ge+a.gi)!=(b.ge+b.gi)) return a.ge+a.gi>b.ge+b.gi;
	else  return  a.ge>b.ge;
}
int main()
{
	while(cin>>n>>m>>k)
	{
		int i,j,s,t;
		for(i=0;i<m;i++)
			scanf("%d",&quo[i]);
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&stu[i].ge,&stu[i].gi);
			stu[i].no=i;
			for(j=0;j<k;j++)
				scanf("%d",&stu[i].pre[j]);
		}
		memset(sel,false,sizeof(sel));///一开始都没被录取
		sort(stu,stu+n,cmp);
		vector<int> res[maxm],result[maxm];
		for(t=0;t<n;t++)
		{
			for(s=0;s<k;s++)
			{
				if(sel[t]==false)
				{	
					i=stu[t].pre[s];///所选院校
					int si=res[i].size(),last;
					if(si>0) last=res[i][si-1];///faulty 
					if(si<quo[i]||(stu[t].ge==stu[last].ge&&stu[t].gi==stu[last].gi))///如果名额还有,或者分数和最后一名录取者相同
					{
						res[i].push_back(t);///排名第t被i录取
						sel[t]=true;
						break;
					}
				}
			}
		}
		for(i=0;i<m;i++)
		{
			for(j=0;j<res[i].size();j++)
			{
				int t=res[i][j];
				result[i].push_back(stu[t].no);
			}
			sort(result[i].begin(),result[i].end());
			for(j=0;j<result[i].size();j++)
			{
				printf("%d",result[i][j]);
				if(j<result[i].size()-1)
					printf(" ");
			}
			printf("\n");
		}
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值