数学竞赛

数学竞赛

题目描述:

img

img

img
你们可能看不见图片。。。UPD:2018/8/15 可以看见啦

SAMEPLE INPUT

111111000
1/2

SAMEPLE OUTPUT

63616161

(你以为信息竞赛就只考信息吗?:P orz SK

分析:

​ 很显然,如果我们只需要(x ightarrowfrac{1}{x})(x ightarrow x+1)(x ightarrow sqrt{x^2+1})就可以满足题目的要求,但是如果题目不给使用你7、8操作该怎么办?

​ 于是我们可以考虑用操作1到6获得与操作7、8、9的相同效果。

​ 画出一个直角三角形,左捣捣,右捣捣,我们可以容易couchu求出:

(ullet x ightarrow 90^circ-x):取(sin x),再取(arccos x)

(ullet x ightarrow frac{1}{x}):取(arctan x)(x ightarrow90^circ-x),再取( an x)

(ullet x ightarrow sqrt{x^2+1}):取(arctan x)(cos x),再取(x ightarrow frac{1}{x})

​ 证明略。

​ 所以,我们只用把(frac{p}{q})看成(sqrt{frac{p^2}{q^2}}),就可以把(sqrt{x^2+1})看成(sqrt{x+1}),一套大力搜索就可以了。

​ 时间复杂度:O(不会求qwq)

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
using namespace std;
inline int rd()
{
	int x=0,f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}
char s[20];
int p,q;
inline int gcd(int a,int b){if(!b)return a;return gcd(b,a%b);}
void gao(int p,int q)
{
	int cnt=0;
	while(p>=q)p-=q,cnt++;
	if(p)gao(q,p),printf("6145");
	while(cnt--)printf("636145");
}
int main()
{
	scanf("%s",s+1);
	p=rd();q=rd();
	int g=gcd(p,q);p/=g,q/=g;
	gao(p*p,q*q);
	return 0;
}

原文地址:https://www.cnblogs.com/JackyhhJuRuo/p/8876950.html