猴年大吉之开心刷题

网友投稿 1164 2022-10-04

猴年大吉之开心刷题

猴年大吉之开心刷题

过年了,各种走亲访友,大吃大喝。为了不让自己忘了算法为何物,做了几道练手的题。

最少乘法次数

​​#include #include using namespace std;const int N=5e6+10;int p[N];void init(){ p[1]=0; p[2]=1; for(int i=3;i

摆方格

​​class="data-table" data-id="t7a7e9d1-K8L7gg0F" data-width="" style="outline: none; border-collapse: collapse; width: 100%;">

19

20

1

2

3

18

21

22

5

4

17

16

23

6

7

14

15

24

25

8

13

12

11

10

9

16

1

2

3

15

14

13

4

10

11

12

5

9

8

7

6

发现规律:

一共N-1项

#include #include using namespace std;typedef unsigned long long LL;int main(){ LL n; while(cin>>n){ LL ans=(n-1)*n*n-(n-1)*(n-2)+(n*n-2*(n-2))/2; printf("%llu\n",ans); } return 0;}

分数拆分

​​#include #include using namespace std;const double eps=1e-7;int main(){ int t,k; cin>>t; while(t--){ scanf("%d",&k); for(int y=k+1;y<=2*k;y++){ for(int x=y;;x++){ double p1=1.0/k; double p2=1.0/x+1.0/y; if(fabs(p1-p2)eps) break; } } } return 0;}

nyist 743 复杂度

​​operation 共执行了多少次吗

相当于在N个元素中取M个,这M个元素是递增的。即M个元素一旦选定,就只有一种情况,没有排列的情况。所以:C(n,m)

用素因子做居然Wa了。为什么。。。

WA:

#include #include #include using namespace std;typedef long long LL;const LL mod=1009,N=2005;LL pri[N],cnt;bool vis[N];void getpri(){ for(LL i=2;i0){ if(p&1) ans=ans*a%mod; a=a*a%mod; p>>=1; } return ans;}int main(){ getpri(); LL n,m; while(cin>>m>>n&&(m+n)){ LL ans=1; for(LL i=0;pri[i]<=n;i++){ LL t1=getd(n,pri[i]),t2=getd(n-m,pri[i]),t3=getd(m,pri[i]); ans=ans*power(pri[i],t1-t2-t3)%mod; } printf("%d\n",ans); } return 0;}

打表:

#include #include #include using namespace std;const int mod=1009,N=2005;int dp[N][N];void init(){ for(int i=0;i>m>>n&&(m+n)){ printf("%d\n",dp[n][m]); } return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:微信小程序怎么实现蓝牙连接?(代码示例)(小程序对接蓝牙)
下一篇:如何实现小程序动画?小程序动画的实现方法(小程序 动画库)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~