【GDOI2018模拟8】 数学竞赛 三角函数性质+记忆化搜索

 

数据范围:p,q≤20。

 

只能说我整个人傻逼了.....

我们考虑三角函数的部分性质:

sin(x)=1cos2(x)

cos(x)=1sin2(x)

tan(x)=sin(x)cos(x)

根据这三条公式,我们可以据此推出以下六种转移方式,即:

arcsin(x)cos(x) or tan(x)

arccos(x)sin(x) or tan(x)

arctan(x)sin(x) or cos(x)

 我们又根据上述的部分性质,我们用分数ab去表示x,其中a,b均为非负整数。

不难根据以下转移式子得到转移出的根式

arcsin(x)cos(x)得到bab

arcsin(x)tan(x)得到aba

arccos(x)sin(x)得到bab

arccos(x)tan(x)得到baa

arctan(x)sin(x)得到aa+b

arctan(x)cos(x)得到ba+b

然后简单地记忆搜索以下就可以了。

复制代码
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int vis[805][805]={0};
 4 int x,y;
 5 int cnt[2505]={0}; int use=0;
 6 void add(int x,int y){cnt[++use]=y; cnt[++use]=x;}
 7 int dfs(int a,int b){
 8     if(a>800||b>800||a<0||b<=0||(a==0&&b!=1)) return 0;
 9     int d=__gcd(a,b);
10     a/=d; b/=d;
11     if(a==x&&b==y) return 1;
12     if(vis[a][b]) return 0;
13     vis[a][b]=1;
14     if(dfs(b-a,b)) {add(2,3); return 1;} 
15     if(dfs(a,b-a)) {add(2,5); return 1;}
16     if(dfs(a,a+b)) {add(6,1); return 1;}
17     if(dfs(b,a+b)) {add(6,3); return 1;}
18     if(dfs(b-a,b)) {add(4,1); return 1;}
19     if(dfs(b-a,a)) {add(4,6); return 1;}
20     return 0;
21 }
22 
23 int main(){
24     string s; cin>>s;
25     scanf("%d/%d",&x,&y);
26     int d=__gcd(x,y);
27     x/=d; y/=d;
28     x=x*x; y=y*y;
29     dfs(0,1);
30     while(use--){
31         printf("%d",cnt[use+1]);
32     }
33 }
复制代码

 

 

posted @   AlphaInf  阅读(333)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示