大数运算

本文介绍了一个使用C++实现的程序,该程序用于判断一个数是否为循环数。循环数是指一个整数,在乘以从1到其位数长度之间的任意整数时,其数字序列会形成一个循环。文章通过示例解释了循环数的概念,并提供了完整的源代码。

  C++ 中一直错用cstring,今天终于出错了,改回string 才好了

Round and Round We Go

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 10549 Accepted: 4830

 

Description

A cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a"cycle"of the digits of the original number. That is, if you consider the number after the last digit to "wrap around"back to the first digit, the sequence of digits in both numbers will be the same, though they may start at different positions.For example, the number 142857 is cyclic, as illustrated by the following table: 
142857 *1 = 142857 
142857 *2 = 285714 
142857 *3 = 428571 
142857 *4 = 571428 
142857 *5 = 714285 
142857 *6 = 857142 

Input

Write a program which will determine whether or not numbers are cyclic. The input file is a list of integers from 2 to 60 digits in length. (Note that preceding zeros should not be removed, they are considered part of the number and count in determining n. Thus, "01"is a two-digit number, distinct from "1" which is a one-digit number.)

Output

For each input integer, write a line in the output indicating whether or not it is cyclic.

Sample Input

142857
142856
142858
01
0588235294117647

Sample Output

142857 is cyclic
142856 is not cyclic
142858 is not cyclic
01 is not cyclic
0588235294117647 is cyclic

代码如下
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;

struct Node
{
int a[80];
int digit;
}num1,num2;
int sign1[80];

bool compare(int k,int sum  )        //判断是否为一个颠倒顺序的数组
{
int i,j;
for(i=k,j=0;i<sum;i++,j++)
if(num1.a[i]!=num2.a[j])
return false;

for(i=0;i<k;i++,j++)
if(num1.a[i]!=num2.a[j])
return false;

return true;
}

int main()
{
int i,j,k;
int temp;
bool ans;
string str;
//while(scanf("%s",str)!=EOF)
while(cin>>str)                //改为cstring时编译出错
{
num1.digit=str.length();
for(i=0,j=num1.digit-1;i<num1.digit;i++,j--)
{
num1.a[i]=str[j]-'0';
}
for(i=2;i<=num1.digit;i++)
{
int carry=0;
ans=false;
memset(sign1,0,sizeof(sign1));
for(j=0;j<num1.digit;j++)
{
temp=num1.a[j]*i+carry;
carry=temp/10;
num2.a[j]=temp%10;
}
if(carry)
//{printf("%s is not cyclic\n",str);break;}
{cout<<str<<" is not cyclic"<<endl; break;}
else
{
for(k=0;k<num1.digit;k++)
if(num1.a[k]==num2.a[0]&&sign1[k]==0)
{
sign1[k]=1;
ans=compare(k,num1.digit);
if(ans)
break;    //防止数组里有相同的数而再判断为false
}
if(!ans)
//{printf("%s is not cyclic\n",str);break;;}
{cout<<str<<" is not cyclic"<<endl; break;}
}//end else

}//end for (31)
if(ans)
//printf("%s is cyclic\n",str);
cout<<str<<" is cyclic"<<endl;

}//end while
return 0;
}

【评估多目标跟踪方法】9个高度敏捷目标在编队中的轨迹和测量研究(Matlab代码实现)内容概要:本文围绕“评估多目标跟踪方法”,重点研究9个高度敏捷目标在编队飞行中的轨迹生成与测量过程,并提供完整的Matlab代码实现。文中详细模拟了目标的动态行为、运动约束及编队结构,通过仿真获取目标的状态信息与观测数据,用于验证和比较不同多目标跟踪算法的性能。研究内容涵盖轨迹建模、噪声处理、传感器测量模拟以及数据可视化等关键技术环节,旨在为雷达、无人机编队、自动驾驶等领域的多目标跟踪系统提供可复现的测试基准。; 适合人群:具备一定Matlab编程基础,从事控制工程、自动化、航空航天、智能交通或人工智能等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于多目标跟踪算法(如卡尔曼滤波、粒子滤波、GM-CPHD等)的性能评估与对比实验;②作为无人机编队、空中交通监控等应用场景下的轨迹仿真与传感器数据分析的教学与研究平台;③支持对高度机动目标在复杂编队下的可观测性与跟踪精度进行深入分析。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注轨迹生成逻辑与测量模型构建部分,可通过修改目标数量、运动参数或噪声水平来拓展实验场景,进一步提升对多目标跟踪系统设计与评估的理解。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值