POJ 1047 Round and Round We Go
https://vjudge.net/problem/POJ-1047
题意:
给一个整数,它的长度为n,从1开始一直到n和该整数相乘,判断每次结果是否和原来的整数是循环的。
思路:
大整数的乘法。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include<vector>
using namespace std; char s[];
int num[];
int temp[];
int n; bool cacl(int m)
{
int t = ;
for (int i = ; i < n; i++)
{
temp[i] = (num[i] * m + t) % ;
t = (num[i] * m + t) / ;
}
if (t>) return false;
return true;
} bool judge()
{
for (int i = ; i<n; ++i)
{
int k = ;
if (temp[i] == num[])
{
while (k<n &&num[++k] == temp[(i+k) % n]);
if (k == n) return ;
}
}
return ;
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
while (gets(s))
{
memset(num, , sizeof(num));
n = strlen(s);
for (int i = n - ; i >= ; i--)
{
num[n - - i] = s[i] - '';
}
bool flag = false;
for (int i = ; i <= n; i++)
{
if (cacl(i))
{
if (!judge())
{
printf("%s is not cyclic\n", s);
flag = true;
break;
}
}
else
{
printf("%s is not cyclic\n", s);
flag = true;
break;
}
}
if (!flag)
printf("%s is cyclic\n", s);
}
return ;
}
POJ 1047 Round and Round We Go的更多相关文章
- POJ 1047 Round and Round We Go 最详细的解题报告
题目链接:Round and Round We Go 解题思路:用程序实现一个乘法功能,将给定的字符串依次做旋转,然后进行比较.由于题目比较简单,所以不做过多的详解. 具体算法(java版,可以直接A ...
- POJ1047 Round and Round We Go
题目来源:http://poj.org/problem?id=1047 题目大意: 有一些整数具有这样的性质:它的位数为n,把它和1到n的任意一个整数相乘结果的数字会是原数字的一个“环”.说起来比较抽 ...
- POJ 2942Knights of the Round Table(tarjan求点双+二分图染色)
Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 13954 Accepted: 4673 Description Bein ...
- POJ 1584:A Round Peg in a Ground Hole
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5741 Acc ...
- POJ 2942Knights of the Round Table(二分图判定+双连通分量)
题目链接 题意:一些骑士,他们有些人之间有矛盾,现在要求选出一些骑士围成一圈,圈要满足如下条件:1.人数大于1.2.总人数为奇数.3.有仇恨的骑士不能挨着坐.问有几个骑士不能和任何人形成任何的圆圈. ...
- poj 2942--Knights of the Round Table (点的双连通分量)
做这题简直是一种折磨... 有n个骑士,骑士之间相互憎恨.给出骑士的相互憎恨的关系. 骑士要去开会,围成一圈坐,相互憎恨的骑士不能相邻.开会骑士的个数不能小于三个人.求有多少个骑士不能开会. 注意:会 ...
- Round and Round We Go
http://acm.hdu.edu.cn/showproblem.php?pid=1313 考查大整数与小整数相乘 #include<iostream> #include<cstd ...
- 【HDOJ】1313 Round and Round We Go
大数乘,果断java A了. import java.util.Scanner; import java.lang.StringBuilder; import java.math.BigInteger ...
- Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2)
A: 思路:就是找b,c之前有多个s[i] 代码: #include<stdio.h>#define ll long longusing namespace std;ll a,b,c;in ...
随机推荐
- [SQL] 获取 Microsoft SQL Server 2008 的数据表结构
then d.name else '' end , 表说明 then isnull(f.value,'') else '' end , 字段序号 = a.colorder , 字段名 = a.name ...
- svn-maven-tomcat自动发布脚本
#!/bin/sh #svn-maven-tomcat自动发布脚本 #变量设置 svnpath=svn://10.60.10.120/研发部/xx-maven svnusername=xxx svnp ...
- maven学习(一)(转)
我记得在搞懂maven之前看了几次重复的maven的教学视频.不知道是自己悟性太低还是怎么滴,就是搞不清楚,现在弄清楚了,基本上入门了.写该篇博文,就是为了帮助那些和我一样对于maven迷迷糊糊的人. ...
- supervisor安装篇
服务器环境: [root@kafka60 supervisor-]# uname -a Linux kafka60 -.el6.x86_64 # SMP Tue May :: UTC x86_64 x ...
- poj1722 SUBTRACT【线性DP】
SUBTRACT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2037 Accepted: 901 Special ...
- What Drives the Need for Database Sharding? DATABASE SHARDING
wIO瓶颈 http://www.agildata.com/database-sharding/ What Drives the Need for Database Sharding? Databas ...
- django-models的get与filter
为了说明它们两者的区别定义2个models class Student(models.Model):name = models.CharField('姓名', max_length=20, defau ...
- SQL Server批量数据导出导入BCP&Bulk使用
数据导出导入,首先考虑使用什么技术实现导出与导入利用BCP结合Bulk技术实现数据的导出与导入 1.bcp数据导出(这里是命令行方式),导出的数据需是格式化的,有两种方式可选 a.对传输的数据格式要求 ...
- Linux查看系统版本信息
1.查看操作系统相关信息 uname -a 2.查看正在运行的内核版本信息 cat /proc/version //uname -r 3.查看发行版本号 (适用于所有的linux,包括Redhat. ...
- 转载Liferay PortletPreference store()方法研究
我们对于PortletPreference 的store()用的非常广泛,很多情况下,我们一般对其进行一些设定,然后最后调用store()存储之,类似以下代码: PortletPreferences ...