【NWPU2018】组队对抗赛1010

焦作站校内选拔赛,总共A了7道题,算是创纪录了。但题比较水,排名十分靠后(校内倒数第三)。

先总体说下问题吧:

  1. 自己吓自己,明明是简单的问题却把它想得很复杂。
  2. 英语水平不过关,有一个词组“tie with”,误以为是连接的意思,实际上是“打平手”,直接导致K题没做出来。
  3. 对自己要求太低。做出3,4道题以后就有些放松。

一个博弈论总结:https://blog.csdn.net/bestsort/article/details/79782541

B - Unusual Team

一个简单的比大小,签到题

C - Cheap Kangaroo

读懂题以后,思路很简单。第一个要输出的是所有输入值之和。难点在于第二处,如何求出所有输入值的最小公因数?对于两个,可以gcd,但在本题中这样做显然会超时。

我的办法:先把所有数中最小的那个因数分解并储存下来,之后,对于每一个因数,判断是否能做其他所有数的因子。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100000+50;
int t,n,x[maxn];
int ys[500000];
bool vs[500000];
bool vvs[500000];
int tot=0;
int main()
{
	scanf("%d",&t);
	for(int i=1;i<=t;i++)
	{	
		long long ans=0; tot=0;
		scanf("%d",&n);
		int mi=2147483647;
		for(int j=1;j<=n;j++)
		{
			scanf("%d",&x[j]);
			ans+=x[j];
			mi=min(mi,x[j]);
		} 
		cout<<ans<<' ';
		for(int k=1;k<=sqrt(mi)+1;k++)
		if(mi%k==0)
		{		
			tot++;
			ys[tot]=mi/k;
			tot++;
			ys[tot]=k;
		}		
		sort(ys+1,ys+1+tot);
		for(int j=tot;j>=1;j--)
			{
				for(int cl=1;cl<=n+1;cl++)
				{	
					if(cl==n+1) 
					{	
							printf("%d\n",ys[j]);
							j=0;
							break;
					}
					if(x[cl]%ys[j])
					break;
															
				}
		
			}
	}
 	return 0;
}

D - Magical Bamboos

自身-1,其余+1,相当于自身-2.先排序,只要相邻两棵树距离差为偶数即能平均。

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define PI 3.14159265 
using namespace std;

int main()
{
	int t,n,h[100010];
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			scanf("%d",&h[i]);
		sort(h+1,h+n+1);
		int flag=1;
		for(int i=1;i<n;i++)
		{
			int a=h[i+1]-h[i];
			if(a%2==1) {flag=0;break;}
		}
		if(flag) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

             

E - Competitive Seagulls  

博弈论。只有当n==2或3时,后手才可能赢。其余情况下,只要先取中间的2/3块,使左右区间相等即可。

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int t,n;
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n;
        if((n==2)||(n==3)) cout<<"second"<<endl;
        else cout<<"first"<<endl;
    }
    return 0;
}

    H - Mirrored String I

队友写的,貌似不难

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>

using namespace std;

int T,ju;
char c[2000],jiben[20];

int main()
{
	scanf("%d",&T);
	jiben[1]='A';jiben[2]='H';
	jiben[3]='I';jiben[4]='M';
	jiben[5]='O';jiben[6]='T';
	jiben[7]='U';jiben[8]='V';
	jiben[9]='W';jiben[10]='X';
	jiben[11]='Y';
	for(int I=1;I<=T;I++)
	{
	    ju=0;
		char ch=getchar();
	    int len=0;
	    while(ch<'A'||ch>'Z')ch=getchar();
	    while(ch>='A'&&ch<='z')
	    {
	    	len++;
	    	c[len]=ch;
	    	bool f=0;
	    	for(int i=1;i<=11;i++)
	    	{
	    		if(ch==jiben[i])f=1;
			}
			if(!f)
			{
				ju=1;
			} 
			ch=getchar();
		}
		if(ju)
		{
			printf("no\n");
			continue;
		}
		bool f=1;
		for(int i=1;i<=len/2;i++)
		{
			if(c[len+1-i]!=c[i])
			{
				f=0;break;
			}
		}
		if(f)
		{
			printf("yes\n");
		}
		else printf("no\n");
	}
	return 0;
}

I - Mirrored String II

一开始大家都在疯狂回忆马拉车......

扫描二维码关注公众号,回复: 8986654 查看本文章

事实上判断是不是由指定字符组成的回文串即可

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=50000;
char jiben[50];
int n;
string a="P";
int B[maxn];
int E[maxn];
int nx[maxn];
bool judge(char x)
{
	for(int i=1;i<=11;i++)
	if(x==jiben[i])
	return 1;
	return 0;
}
int t;
string s;
int main()
{
	scanf("%d",&t);
	jiben[1]='A';jiben[2]='H';
	jiben[3]='I';jiben[4]='M';
	jiben[5]='O';jiben[6]='T';
	jiben[7]='U';jiben[8]='V';
	jiben[9]='W';jiben[10]='X';
	jiben[11]='Y';
	for(int i=1;i<=t;i++)
	{
		cin>>s; int ANS=0;  s=a+s;  memset(nx,0,sizeof(nx)); int num=0; int tot=0;
		n=s.length(); int tp=-1; int fs=-1; s[n]='P'; int fss=-1;
	//	int ed;
	/*	for(int j=0;j<=n;j++)
		{
			if(!judge(s[j]))
			{
				if(tp!=-1)
				nx[tp]=j;
				tp=j;
				if(fs==-1)
				fs=j;
			}
			else
		{
			
			if(fss==-1)
			{
				fss=j;
				
			}
			ed=j;
		}
		} 
		if(fss==-1)
		{
			printf("0\n");
			continue;
		}
			int l=fss;
			int r=nx[fss-1]-1;*/
		int bg=-1; int ed=-1;
		for(int j=0;j<=n;j++)
		{
			if(judge(s[j]))
			{
				if(bg==-1)
				{
					bg=j;
					num++;
				}
				ed=j;
			}
			else
			{
				if(bg!=-1&&num!=0)
				{
					tot++;
					B[tot]=bg;
					E[tot]=ed;
					bg=-1;
					ed=-1;
					num--;
				}
			}
		}
		for(int cl=1;cl<=tot;cl++)
			{	
				
 				int l=B[cl]; int r=E[cl];  //printf("l=%d  r=%d\n",l,r);
				 for(int k=l;k<=r;k++)
				{
					int ll=k; int rr=k+1;  int ans=0;
					while(s[ll]==s[rr]&&ll>=l&&rr<=r)
					{
						ans+=2;
						ll--;
						rr++;
					}
					int ans2=1;
					ll=k-1; rr=k+1;
					while(ll>=l&&rr<=r&&s[ll]==s[rr])
					{
						ans2+=2;
						ll--;
						rr++;
					}
					ans=max(ans,ans2);
					ANS=max(ANS,ans);
				}
			/*	if(r==ed) break;
				while(1)
				{
					if(nx[r+1]==r+2)
					r++;
					else
					break;
				}
				l=r+2;
				r=nx[r+1];*/
				}
			printf("%d\n",ANS);
	}
		
		return 0;	
}

J - Lazy Physics Cat

数学题。用圆弧面积减去三角形面积。

一个注意事项:sin()函数中是弧度制。

#include<iostream>
#include<cmath>
#include<cstdio>
#define PI 3.14159265 
using namespace std;

int main()
{
	int t,L,a;
	cin>>t;
	while(t--)
	{
		cin>>L>>a;
		double r=a*PI/180;
		double s1=a*1.0*PI*L*L/360;
		double s2=1.0/2*L*L*sin(r);
		printf("%.6lf\n",s1-s2);
	}
	return 0;
}

K - Owl Geeks

这个题就是那道因为一个词组没看懂,最后时间不够的题QAQ

看懂题后就非常简单了

#include<cmath>
#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX = 1e5 + 10;
typedef long long LL;
int m[12],mm[12];
int main()
{
    int T; scanf("%d",&T);
    while(T--){
        int a,b,n; scanf("%d %d %d",&a,&b,&n);
        int r = 0;
        memset(m,0,sizeof(m));
        for(int i = 1; a * i * i + b * i <= n; i++) r = i;
        if(r == 0){
            puts("-1"); continue;
        }
        for(int i = 1; i <= r; i++){
            int o = i * i * a + b * i;
            memset(mm,0,sizeof(mm));
            int v = 0;
            while(o){
                int u = o % 10;
                mm[u]++;
                v = max(v,mm[u]);
                o /= 10;
            }
            for(int j = 0; j <= 9; j++)
                if(mm[j] == v)
                    m[j]++;
        }
        int u = 0;
        for(int i = 0; i <= 9; i++) if(m[i] > m[u]) u = i;
        printf("%d\n",u);
    }
    return 0;
}

M - Make Cents?

scanf比cin快很多!!!!!!

cin优化后也比不上!!!!!!

这个题调了好久,一直TLE,最后把cin改成scanf就A了......明明开了cin优化还是不行。

言归正传,用map维护即可。注意,scanf读入字符串时,最好用字符数组,然后强制转化为string

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<map>
#define PI 3.14159265 
using namespace std;
map<string,double> m;
const int N=100010;
//string str[N];
double v[N];
char s[22];
int main()
{
	//ios::sync_with_stdio(false);
	int t,c,n;
	cin>>t;
	while(t--)
	{
		cin>>c>>n;   m.clear();
		//scanf("%d%d",&c,&n);
		for(int i=1;i<=c;i++) 
		{
		 	scanf("%s%lf",s,&v[i]);
			//cin>>s>>v[i];
			m[string(s)]=v[i];
		}	
		//for(int i=1;i<=c;i++) cout<<str[i]<<" ";
		double ans=0;
		for(int i=1;i<=n;i++)
		{
			double k;
			//cin>>k>>s;
			scanf("%lf%s",&k,s);
			if(string(s)=="JD") {ans+=k;continue;}
			ans+=k*m[string(s)];
		}
		printf("%.6lf\n",ans);
	}
	return 0;
}
发布了38 篇原创文章 · 获赞 12 · 访问量 3956

猜你喜欢

转载自blog.csdn.net/int_lyy/article/details/83052486