NEFU 大一练习赛 2019.12.31

NEFU OJ 大一练习赛 2019.12.31

Summary

第一次写博客,写的不一定很好,哈哈 QAQ
题目比较多就不粘题目了,可以点开链接查看题目 QWQ

Information

No. Title AC/Submit
A QWQ和QAQ 4/22
B QWQ和神奇的传送器 14/64
C QWQ和神秘商人 31/123
D QWQ和棋局挑战 20/50
E QWQ和彩色石 61/107
F QWQ和翻译机 53/140
G 海贼的奖品赞助 74/90

Problem A: QWQ和QAQ (1609) [4/22]

Tips

可以先计算每个产品的最大产量,然后暴力枚举

Code

#include <bits/stdc++.h>
using namespace std;

int gmin(int a,int b,int c)
{
	int m=a>b?b:a;
	return m>c?c:m;
}

int main()
{
	int t,a1,a2,a3,b1,b2,b3,c1,c2,c3,a,b,c,d1,d2,d3,ma,mb,mc;
	int costa,costb,costc,value,max;
	cin>>t;
	while(t--)
	{
		max=0;
		cin>>a1>>b1>>c1;
		cin>>a2>>b2>>c2;
		cin>>a3>>b3>>c3;
		cin>>a>>b>>c;
		cin>>d1>>d2>>d3;
		ma=gmin(a1==0?200:a/a1,b1==0?200:b/b1,c1==0?200:c/c1);
		mb=gmin(a2==0?200:a/a2,b2==0?200:b/b2,c2==0?200:c/c2);
		mc=gmin(a3==0?200:a/a3,b3==0?200:b/b3,c3==0?200:c/c3);
		for(int i=0;i<=ma;i++)
		{
			for(int j=0;j<=mb;j++)
			{
				for(int k=0;k<=mc;k++)
				{
					costa=i*a1+j*a2+k*a3;
					costb=i*b1+j*b2+k*b3;
					costc=i*c1+j*c2+k*c3;
					if(costa<=a&&costb<=b&&costc<=c)
					{
						value=i*d1+j*d2+k*d3;
						if(value>max)max=value;
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

Problem B: QWQ和神奇的传送器 (1608) [14/64]

Tips

链接暂时没看到,以后看到再补充
一道数学题,推出公式为 C m 1 n 1 {C_{m-1}^{n-1}} 就可以了

Code

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t,m,n;
	long long res;
	cin>>t;
	for(int i=0;i<t;i++)
	{
		res=1;
		cin>>m>>n;
		for(int j=n-1,k=0;k<m-1;k++,j--)
		{
			res*=j;
		}
		for(int j=m-1;j>1;j--)
		{
			res/=j;
		}
		cout<<res<<endl;
	}
	return 0;
}

Problem C: QWQ和神秘商人 (1607) [31/123]

Tips

宝物价格低于初始宝石数量的都可以买
所以不需要排序,当时一看到就想排序,也不知道为啥

Code

#include <bits/stdc++.h>
using namespace std;

struct obj
{
	int value;
	int cost;
}o[100000];

int cmp(obj o1,obj o2)
{
	return o1.cost>o2.cost;
}

int main()
{
	int n,k,tmp,maxn,ans;
	while(cin>>n>>k)
	{
		ans=0;
		for(int i=0;i<n;i++)
		{
			cin>>o[i].cost;
		}
		for(int i=0;i<n;i++)
		{
			cin>>o[i].value;
		}
		sort(o,o+n,cmp);
		for(int i=0;i<n;i++)
		{
			if(o[i].cost<=k)ans+=o[i].value;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Problem D: QWQ和棋局挑战 (1606) [20/50]

Tips

类似八皇后的算法,实际上据说用排列组合也是可以解的

Code

#include <bits/stdc++.h>
using namespace std;

int mapp[10],res;
int n,k;

int check(int l)
{
	for(int i=0;i<l;i++)
	{
		if(l==mapp[i])return 0;
	}
	return 1;
}

void dfs(int l,int s)
{
	//cout<<l<<" ";
	if(l>n)return;
	if(s>=k)
	{
		res++;
		return;
	}
	mapp[l]=-1;
	dfs(l+1,s);
	for(int i=0;i<n;i++)
	{
		mapp[l]=i;
		if(check(l))dfs(l+1,s+1);
	}
}

int main()
{
	while(cin>>n>>k)
	{
		res=0;
		dfs(0,0);
		cout<<res<<endl;
	}
	return 0;
}

Problem E: QWQ和彩色石 (1604) [61/107]

Tips

一个简单的桶排序

Code

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,num[101]={0},tmp,maxn;
	while(cin>>n)
	{
		memset(num,0,sizeof(num));
		maxn=0;
		for(int i=0;i<n;i++)
		{
			cin>>tmp;
			num[tmp]++;
			if(num[tmp]>maxn)maxn=num[tmp];
		}
		cout<<maxn<<endl;
	}
	return 0;
}

Problem F: QWQ和翻译机 (1605) [53/140]

Tips

字符串处理,注意字符串不等长的情况

Code

#include <bits/stdc++.h>
using namespace std;

int main()
{
	char c1[101],c2[101];
	int ok;
	while(cin>>c1>>c2)
	{
		if(strlen(c1)!=strlen(c2))
		{
			printf("NO\n");
			continue;
		}
		ok=1;
		for(int i=0;i<strlen(c1);i++)
		{
			if(c1[i]!=c2[strlen(c2)-i-1])
			{
				ok=0;
				break;
			}
		}
		if(ok)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Problem F: 海贼的奖品赞助 (1610) [74/90]

Tips

居然不是QWQ和QAQ ←_←

Code

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,ok=0;
	double tmp;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>tmp;
		if(tmp>=20)ok++;
	}
	printf("%.2f",ok/(double)n);
	return 0;
}
发布了32 篇原创文章 · 获赞 104 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/csg999/article/details/103805817