HDU 1313 高精度*单精度

Round and Round We Go

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 658    Accepted Submission(s): 365

Problem Description

A cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a ~{!0~}cycle~{!1~} of the digits of the original number. That is, if you consider the number after the last digit to ~{!0~}wrap around~{!1~} 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

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, ~{!0~}01~{!1~} is a two-digit number, distinct from ~{!0~}1~{!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

题意:

给出一个数(长度<=60),然后这个数依次乘1--n(n为该数的长度),若每次乘后所得的数首尾相连构成的环和给的那个数构成的环相等,则该数是环。

思路:

高精度模拟一下就行了。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <vector>
 5 #include <algorithm>
 6 using namespace std;
 7
 8 char s[100];
 9 char str[200];
10
11 int solve(){
12     int a[100];
13     char s1[100];
14     int i, j, n=strlen(s);
15     for(i=2;i<=n;i++){
16         memset(s1,‘\0‘,sizeof(s1));
17         memset(a,0,sizeof(a));
18         for(j=n-1;j>=0;j--) a[j]=s[n-j-1]-‘0‘;
19         for(j=0;j<n;j++) a[j]*=i;
20         for(i=0;i<=n+2;i++){
21             a[i+1]=a[i+1]+a[i]/10;
22             a[i]%=10;
23         }
24         int k=n+2;
25         while(!a[k]) k--;
26         for(j=n-1;j>=0;j--) s1[j]=a[n-j-1]+‘0‘;
27         if(!strstr(str,s1)) return 0;
28     }
29     return 1;
30 }
31
32 main()
33 {
34     while(scanf("%s",s)!=EOF){
35         strcpy(str,s);
36         strcat(str,s);
37         int ans=solve();
38         if(ans) printf("%s is cyclic\n",s);
39         else printf("%s is not cyclic\n",s);
40     }
41 }

HDU 1313 高精度*单精度,布布扣,bubuko.com

时间: 2024-10-18 02:36:54

HDU 1313 高精度*单精度的相关文章

高精度 四位压缩

高精度 四位压缩 基本原理: 建立一个数组 每一位上存4位数字 运用一定的方法运算,以实现大整数的运算: 封装在了结构体内: 目前只有高精度+高精度.高精度*单精度.max(高精度,高精度): 代码: //高精度四位压缩================================================ const int M=85,mod=10000; struct HP { int p[505],len; HP() { memset(p,0,sizeof(p)); len=0;

【NOIP2007】矩阵取数

因为傻逼写错高精度搞了一下午浪费好多时间,好想哭qaq 原题: 帅帅经常更同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij据为非负整数.游戏规则如下: 1. 每次取数时须从每行各取走一个元素,共n个.m次后取完矩阵所有的元素: 2. 每次取走的各个元素只能是该元素所在行的行首或行尾: 3. 每次取数都有一个得分值,为每行取数的得分之和:每行取数的得分 = 被取走的元素值*2^i,其中i表示第i次取数(从1开始编号):  4. 游戏结束总得分为m次取数得分之和. 帅帅想请

hdu 1316 How Many Fibs? (模拟高精度)

题目大意: 问[s,e]之间有多少个 斐波那契数. 思路分析: 直接模拟高精度字符串的加法和大小的比较. 注意wa点再 s 可以从 0 开始 那么要在判断输入结束的时候注意一下. #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; struct node { char str[111]; int len; void

HDU 1316 斐波那契数列+高精度

How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4235    Accepted Submission(s): 1669 Problem Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-1

HDU 4927 Series 1(高精度+杨辉三角)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4927 解题报告:对于n,结果如下: C(0,n-1) *A[n] - C(1,n-1) * A[n-1] + C(2,n-1) * A[n-2] - C(3,n-1) * A[n-3] ....... C(n-1,n-1) * A[1]; n <= 3000,到了后面二项式会很大,因为要用到高精度的乘法和除法,所以直接用java的大数类写了,简单多了. 1 import java.math.BigI

HDU 1047 [Integer Inquiry] 高精度 格式

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047 题目大意:T组数据.每组给出n个大数,输出他们的和 关键思想:高精度,格式控制 代码如下: #include <iostream> #include <memory.h> using namespace std; int a[102][110]; int ans[110]; int cnt=0; bool flag;//处理前导零 void solve(){ int sum,c=

hdu 1316 How many Fibs?(高精度斐波那契数)

//  大数继续 Problem Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-1 + fn-2 (n >= 3) Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a, b]. Input The input contains several test cas

hdu 1063 Exponentiation (高精度小数乘法)

//大数继续,额,要吐了. Problem Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems. This problem re

hdu 5351 MZL&#39;s Border 打表+高精度

MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 462    Accepted Submission(s): 127 Problem Description As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was pl