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 ...
随机推荐
- 部署软件RDMA的步骤
date: 2018-08-28 19:46:56 参考原文原文:http://corasql.blog.51cto.com/5908329/1930455 ...
- linux :故障提示:Error:No suitable device found: no device found for connection "System eth0"
解决:1./etc/udev/rules.d/70-persistent-net.rules 中的mac地址2.网卡配置文件ifcfg-eth0中的mac地址3.ifconfig中的mac地址以上三个 ...
- angularJS中的MVC思想?
mvc 思想: 将应用程序的组成,划分为三个部分:model , controller 和 view ; - 控制器的作用是用来初始化模型用的: - 模型就是用于存储数据的: - 视图是展示数据的: ...
- Centos7更改yum源与更新系统
[1] 首先备份 /etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/Cen ...
- mysql数据库多源复制方案
概述 由于目前生产环境的mysql数据库分布在两台服务器,若从单一主从来看,配置很简单,但是需要将两台服务器的数据库同步到一台从库上面,需要进行更多配置和注意事项.多源复制有两种方案,Binlog+P ...
- Maven搭建Nexus私有仓库
下载压缩包nexus-2.13.0-01-bundle.tar.gz 解压后有两个目录 进入程序目录启动 ./nexus start 启动告警(确认用root启动把以下加入到环境变量) export ...
- 沈阳网络赛G-Spare Tire【容斥】
17.64% 1000ms 131072K A sequence of integer \lbrace a_n \rbrace{an} can be expressed as: \display ...
- ubuntu下完全卸载opencv3.1.0
在ubuntu下删除opencv需要以下步骤: 1.进入opencv的源代码文件夹下的release(这是你在安装opencv时候自己命名的,cmake时候所在的目录) 2.执行以下命令 sudo m ...
- 获取List、Set、Map等字段的泛型参数
测试类加单元测试方法,运行结果在注释里面: package temp; import org.junit.Test; import java.lang.reflect.Field; import ja ...
- 转载:Why using Single Root I/O Virtualization (SR-IOV) can help improve I/O performance and Reduce Costs
Introduction While server virtualization is being widely deployed in an effort to reduce costs and o ...