2019年杭州师范大学第十二届程序设计竞赛

目录

A  Little Sub and Applese

B  Little Sub and Triples(斐波那契打表+排序+暴力)

D   Little Sub and Balloons(set)

H   Little Sub and Counting(二分)

I  Little Sub and Enigma(思维+坑)

J  Little Sub and Apples

K   Little Sub and Triangles(三角形面积+暴力)


A  Little Sub and Applese

【分析】把字符串结尾的 '.' 换成 '!' ;

B  Little Sub and Triples(斐波那契打表+排序+暴力)

【题意】求序列中下标x,y,z对应的数a,b,c满足 a≤b≤c 且a+b>c;

【分析】题目转换成排序后的区间是否满足a[i]+a[i+1]>a[i+2];

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

如果是a[i]+a[i+1]=a[i+2]就变成了斐波那契数列,斐波那契数列增长的很快,那么可以打表看一下大概在多少项会溢出int;

那么只要大于这个溢出的数,就一定会满足a+b>c;

那么,低于这个数的区间,暴力枚举时间复杂度也不会很高;还有注意long long

(思路好巧妙呀!队友真棒)

【代码】

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long ll;//注意long long 
const int maxn=2e5+10;
int fb[100];
ll a[maxn],b[maxn];

void init()//打表求范围 
{
	fb[0]=1;fb[1]=1;
	for(int i=2;i<100;++i)
	{
		fb[i]=fb[i-1]+fb[i-2];
		printf("%d,%d\n",i,fb[i]);
	}
}
int main()
{
//	init();//可知,第46项开始溢出
	ll n,q;scanf("%lld%lld",&n,&q);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&a[i]);
		b[i]=a[i];
	 } 
	while(q--)
	{
		ll l,r;scanf("%lld%lld",&l,&r);
		if(l>r || r-l+1<3){puts("NO");continue;}
		if(r-l+1>=46){puts("YES");continue;}
		int cnt=0;
		for(int i=l;i<=r;++i)
			b[cnt++]=a[i];
		sort(b,b+cnt);
		int f=0;
		for(int i=0;i<cnt-2;++i)
		{
			if(b[i]+b[i+1]>b[i+2])
			{
				puts("YES");
				f=1;
				break;
			}
		}
		if(!f)puts("NO");
	}
}

D   Little Sub and Balloons(set)

【题意】求序列中不同的数的个数;set容器存一下求size即可

H   Little Sub and Counting(二分)

【题意】对式子取ln,得到ylnx > xlny,则y/lny > x/lnx

【分析】

求出每个数对应的y/lny值,然后排序二分找数量;注意当a[i]==1时答案永远是0的,这时就要给c[i]赋一个很大的值;

为了避免精度误差,采用的是放大100倍;不过后来题解上是这么说的:

怎么避免精度误差呢?——考虑x/lnx的单调性

  求导后大家会发现导函数的极值点是e,所以如果所有数字都大于e的话,直接排序就好了。这时有两个例外:12,提前拿出来特判算答案贡献即可。

  一些corner caseln1=0         24=42

【代码】

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;

const int maxn=1e5+10;
ll a[maxn],b[maxn],c[maxn];
int main()
{
	int n;scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		scanf("%lld",&a[i]);
		if(a[i]==1)c[i]=999999999999999999;//注意这里~~
		else c[i]=(a[i]*1.0/log(a[i]))*100;//避免精度误差
		b[i]=c[i];
	}
	sort(b,b+n);        //排序
	for(int i=0;i<n;++i)
	{
		int pos=upper_bound(b,b+n,c[i])-b;
		pos=n-pos;
		if(i==n-1)printf("%d\n",pos);
		else printf("%d ",pos);
	}
}

I  Little Sub and Enigma(思维+坑)

【题意】字符串的解密,并且知道25个字母的对应密码之后是可以直接推出第26个的

【分析】

神坑....巨坑   比赛的时候,各种情况排列组合做,,,一直wa一直wa   做了很久还是没有A

好好学英语之--------observed or deducted(推断)

然后比赛结束才知道,知道25个是可以推出第26个的... 而且并没有我们想的那么多的情况(比如不是小写原样输出或者直接判Impossible啊,比如上下两个串一样也impossible啊...但其实都没关系)只要一个字母不对应多个字母或者多个字母不对应一个字母就可以的..

【代码】

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

const int maxn=1e6+10;
char s1[maxn],s2[maxn];
int vis1[maxn],vis2[maxn];

int main()
{
	scanf("%s%s",s1,s2);
	int len1=strlen(s1),len2=strlen(s2);
	if(len1!=len2){puts("Impossible");return 0;}
	int f=1,cnt=0;
	for(int i=0;i<len1;++i)
	{
		if(!vis1[s1[i]] && !vis2[s2[i]])
		{
			vis1[s1[i]]=s2[i],cnt++;
			vis2[s2[i]]=1;
		}
		else if(vis1[s1[i]] && vis1[s1[i]]==s2[i])continue;
		else {f=0;break;}
	}
	if(!f)puts("Impossible");
	else
	{
		int id1=-1,id2=-1;
		if(cnt==25)
		{
			for(int i='a';i<='z';++i)
			{
				if(!vis1[i])id1=i;
				if(!vis2[i])id2=i;
			}
			for(int i='a';i<='z';++i)
			{
				if(i==id1)printf("%c->%c\n",i,id2);
				else  printf("%c->%c\n",i,vis1[i]);
			}
			return 0;
		}
		for(int i='a';i<='z';++i)
			if(vis1[i])printf("%c->%c\n",i,vis1[i]);
	}
	return 0;
}

J  Little Sub and Apples

【题意】n个苹果每天吃t个k天后剩多少

K   Little Sub and Triangles(三角形面积+暴力)

【题意】给出一系列的点,问任意三个点组成的三角形询问范围内有多少个

【分析】做的时候算了下复杂度,感觉还ok,就先交了一发,running时间有点长,但但,A了.....??  暴力出奇迹...

【代码】

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

const int maxn=1e7+10;
typedef long long ll;

struct node{
	double x,y;
}a[maxn];
double s[maxn];

double xmult(const node &p1,const node &p2,const node &p0)
{
	return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double areas(const node &p1,const node &p2,const node &p3)
{
	return fabs(xmult(p1,p2,p3))/2;
}
int main()
{
	ll n,q;scanf("%lld%lld",&n,&q);
	for(int i=0;i<n;++i)
		scanf("%lf%lf",&a[i].x,&a[i].y);
	ll cnt=0;
	for(int i=0;i<n;++i)
	{
		for(int j=i+1;j<n;++j)
		{
			for(int k=j+1;k<n;++k)
				s[cnt++]=areas(a[i],a[j],a[k]);
		}
	}
	sort(s,s+cnt);//别忘了!! 
	while(q--)
	{
		double l,r;scanf("%lf%lf",&l,&r);
		ll pos1=lower_bound(s,s+cnt,l)-s;
		ll pos2=upper_bound(s,s+cnt,r)-s;
		printf("%lld\n",pos2-pos1);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_38735931/article/details/88659472
今日推荐