Harmonic Value Description (思维+找规律)

Harmonic Value Description

  HDU - 5916 
 
The harmonic value of the permutation p1,p2,pn is 
i=1n1gcd(pi.pi+1)

Mr. Frog is wondering about the permutation whose harmonic value is the strictly k-th smallest among all the permutations of [n].

InputThe first line contains only one integer T (1T100), which indicates the number of test cases. 

For each test case, there is only one line describing the given integers n and k (12kn10000).
OutputFor each test case, output one line “Case #x: p1 p2  pn”, where x is the case number (starting from 1) and p1 p2  pn is the answer.

Sample Input

2

4 1

4 2

Sample Output

Case #1: 4 1 3 2

Case #2: 2 4 1 3

思路:如果k=1 那么便 1 2 3...n 相邻两两之间的最大公约数为1 ,如果k不为1,那么只用让k和2*k这两个数之间的最大公约数变成k,其余仍为1即可。

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<iostream>
 5 using namespace std;
 6 int casen;
 7 int n,k;
 8 int main()
 9 {
10     cin>>casen;
11     int cas=0;
12     while(casen--)
13     {
14         scanf("%d%d",&n,&k);
15         cas++;
16         printf("Case #%d:",cas);
17         if(k==1)
18         {
19             for(int i=1;i<=n;i++)
20             {
21                 printf(" %d",i);
22             }
23             printf("\n");
24         }
25         else
26         {
27             printf(" %d %d",2*k,k);
28             for(int i=k-1;i>=1;i--)
29                 printf(" %d",i);
30             for(int i=k+1;i<=n;i++)
31             {
32                 if(i!=2*k)
33                 {
34                     printf(" %d",i);
35                 }
36             }
37             printf("\n");
38         }
39     }
40 return 0;
41 }

 

转载于:https://www.cnblogs.com/1013star/p/9709845.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Duffing谐振子是一种非线性振动系统,具有能量耗散和非线性耦合的特点。在Matlab中,可以通过数值计算来模拟和分析Duffing谐振子的行为。 首先,我们需要定义Duffing谐振子的数学模型。Duffing谐振子的微分方程可以表示为: m*x'' + c*x' + k*x + a*x^3 = F*cos(ω*t) 其中,m是质量,c是阻尼系数,k是刚度系数,a是非线性刚度系数,F是外加力的振幅,ω是外加力的角频率。这个方程描述了Duffing谐振子的运动。 在Matlab中,可以使用ode45函数来数值求解微分方程。我们可以定义一个函数,将微分方程转化为一阶微分方程的形式。然后,可以使用ode45函数来求解这个一阶微分方程,得到系统的时间响应。 除了求解时间响应外,还可以分析Duffing谐振子的振幅-频率响应曲线。通过改变外加力的角频率ω,可以得到不同频率下的振幅。可以构建一个循环,改变外加力的频率,在每个频率下求解微分方程,得到振幅的曲线。这样就可以分析Duffing谐振子的频率特性。 此外,还可以通过绘制Duffing谐振子的相图来分析其运动特性。相图展示了系统状态变量 x 和速度变量 x' 之间的关系。可以通过定义一组初始条件,求解微分方程,并将系统的状态变量绘制在相图上。这样可以观察到系统的稳定点、周期轨道等特性。 总之,通过在Matlab中数值求解微分方程、分析振幅-频率响应曲线和绘制相图,可以对Duffing谐振子的行为进行模拟和分析。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值