洛谷P1467 循环数 Runaround Numbers
P1467 循环数 Runaround Numbers
- 89通过
- 233提交
- 题目提供者该用户不存在
- 标签USACO
- 难度普及/提高-
提交 讨论 题解
最新讨论
- 暂时没有讨论
题目描述
循环数是那些不包括0且没有重复数字的整数(比如81362)并且还应同时具有一个有趣的性质, 就像这个例子:
如果你从最左边的数字开始(在这个例子中是8)向右数最左边这个数(如果数到了最右边就回到最左边),你会停止在另一个新的数字(如果停在一个相同的数字上,这个数就不是循环数).就像: 8 1 3 6 2 从最左边接下去数8个数字: 1 3 6 2 8 1 3 6 所以下一个数字是6
重复这样做 (这次从“6”开始数6个数字) 并且你会停止在一个新的数字上: 2 8 1 3 6 2, 也就是2
再这样做 (这次数两个): 8 1
再一次 (这次一个): 3
又一次: 6 2 8 这时你回到了起点,在经过每个数字一次后回到起点的就是循环数。如果你经过每一个数字一次以后没有回到起点, 你的数字不是一个循环数。
给你一个数字 M (在1到9位之间), 找出第一个比 M大的循环数, 输出数据保证结果能用一个无符号长整型数(21亿)装下。 (追加提醒:循环数每个数位都必须要访问到)
输入输出格式
输入格式:
仅仅一行, 包括M.
输出格式:
仅仅一行,输出第一个比M大的循环数。
输入输出样例
81361
81362
说明
翻译来自NOCOW
USACO 2.2
分析:这道题有一半是在考语文......其实读懂了就会发现这道题就是一道枚举的水题,因为没告诉范围,所以只要找到符合条件的数就可以,关键是怎么判断,首先判重,并在判重中看看原数有没有0,然后按照题目说的性质一步一步来,注意取模就行.不过要注意的是,因为要对多个数进行处理,每次进行处理之前要先初始化数组!
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,num[],vis1[],vis2[],temp,cur;
bool flag = true; void fanzhuan()
{
int j = temp;
for (int i = ; i < j; i++)
swap(num[i], num[j--]);
} bool panchong(int x)
{
int vis[];
memset(vis, , sizeof(vis));
while (x)
{
if (x % == )
return false;
if (vis[x % ])
return false;
vis[x % ] = ;
x /= ;
}
return true;
} bool check(int x)
{
memset(num, , sizeof(num));
memset(vis1, , sizeof(vis1));
memset(vis2, , sizeof(vis2));
temp = ;
while (x) {
if (vis1[(num[temp] = x % )])
return false;
vis1[num[temp++]] = true;
x /= ;
}
temp--;
fanzhuan();
cur = ;
while (!vis2[num[cur]])
{
vis2[num[cur]] = ;
cur += num[cur] % temp;
if (cur > temp)
cur %= temp;
}
if (num[cur] != num[])
return false;
for (int i = ; i <= temp; i++)
if (!vis2[num[i]])
return false;
return true;
} int main()
{
scanf("%d", &n);
int i = n + ;
while ()
{
if (panchong(i))
if (check(i) == true)
break;
i++;
}
printf("%d\n", i); return ;
}
洛谷P1467 循环数 Runaround Numbers的更多相关文章
- 洛谷 P6218 [USACO06NOV] Round Numbers S
洛谷 P6218 [USACO06NOV] Round Numbers S 题目描述 如果一个正整数的二进制表示中,\(0\) 的数目不小于 \(1\) 的数目,那么它就被称为「圆数」. 例如,\(9 ...
- USACO Section 2.2 循环数 Runaround Numbers
OJ:http://www.luogu.org/problem/show?pid=1467 #include<iostream> #include<vector> #inclu ...
- 洛谷P3459 [POI2007]MEG-Megalopolis [树链剖分]
题目传送门 MEG 题目描述 Byteotia has been eventually touched by globalisation, and so has Byteasar the Postma ...
- 洛谷 P3478 [POI2008]STA-Station
题目描述 The first stage of train system reform (that has been described in the problem Railways of the ...
- 【题解】洛谷P3952 [NOIP2017TG] 时间复杂度(模拟)
题目来源:洛谷P3952 思路 纯模拟没啥可说的了 果然好复杂 参考了你谷一个40行代码 代码 #include<iostream> #include<cstdio> #inc ...
- [洛谷P3527] [POI2011]MET-Meteors
洛谷题目链接:[POI2011]MET-Meteors 题意翻译 Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1 ...
- [洛谷P3444] [POI2006]ORK-Ploughing
洛谷题目链接[POI2006]ORK-Ploughing 题目描述 Byteasar, the farmer, wants to plough his rectangular field. He ca ...
- COCI2017-2018#3 Dojave || 洛谷P4443
题目传送门............................................................................................... ...
- 洛谷 P3048 [USACO12FEB]牛的IDCow IDs
题目描述 Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, ...
随机推荐
- CSS图片垂直居中方法
让div里面的多行文本垂直居中的方法: div{height:100px;width:100px;border:solid 1px red;text-align:center; display:tab ...
- OpenCV中Delaunay三角网算法例子
#include <opencv2/opencv.hpp> #include <vector> using namespace cv; using namespace std; ...
- SparkSql官方文档中文翻译(java版本)
1 概述(Overview) 2 DataFrames 2.1 入口:SQLContext(Starting Point: SQLContext) 2.2 创建DataFrames(Creating ...
- RMAN_学习实验1_RMAN备份标准过程(案例)
2014-12-23 Created By BaoXinjian
- PLSQL_基础系列07_插入方式Pivoting / Unconditional / Conditional ALL / Conditional FIRST INSERT(案例)
2014-12-08 Created By BaoXinjian
- PLSQL_性能优化系列03_Oracle Parallel并发处理
2014-09-25 Created By BaoXinjian
- Educational Codeforces Round 15 Cellular Network
Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...
- Spring的AOP与代理
spring 支持两种注入方式: setter/constructor 支持多种配置方式: xml/java5注解/java类配置 支持两种事务管理: 声明性/编程性 实际上上述方式只有一个就能保证系 ...
- keil中的串口调试:
keil中串口的虚拟调试信息在通过View-serial windows-#usart1/2/3/4/debug(printf)可以看到.当然也可以通过虚拟串口VSPD+串口调试助手在外部实现,方法如 ...
- java普通servlet三层开发模式图