洛谷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, ...
随机推荐
- 236. Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...
- [linux basic]--线程
/************************************************************************* > File Name: thread1.c ...
- Tomcat插件与Jetty插件在MyEclipse中的配置
-Djetty.port=8101 jetty:run tomcat6:run <plugin> <groupId>org.apache.tomcat.maven</gr ...
- 在C#中子线程如何操作主线程中窗体上控件
在C#中,直接在子线程中对窗体上的控件操作是会出现异常,这是由于子线程和运行窗体的线程是不同的空间,因此想要在子线程来操作窗体上的控件,是不可能 简单的通过控件对象名来操作,但不是说不能进行操作,微软 ...
- MySQL的时间进位问题
mysql更新到5.6.4 之后 , 新增了一个叫factional seconds的特性 , 可以记录时间的毫秒值. 但是目前的数据库是不记录毫秒值的 , 所以会产生一个java中时间的Millis ...
- ylbtech-dbs:ylbtech-4,PurpleHouse(房地产楼盘销售系统)
ylbtech-dbs:ylbtech-4,PurpleHouse(房地产楼盘销售系统) -- =============================================-- Crea ...
- PHP框架 Laravel Eloquent ORM 批量插入数据 && 批量更新目前没有
foreach ($products as $v=>$a) { $count[] = array('product_name' => $a['name'], 'product_weight ...
- Weblogic重启(转载)
1.用户名密码登录. 2.切换到weblogic的bin目录下: cd /user/local/weblogic/user_projects/domains/base_domain/bin/ 3.先停 ...
- Linux php 中文乱码解决
在ubuntu下php网页输出乱码,在不涉及数据库编码的情况下: 修改“/etc/php5/apache2/php.ini”将 default_charset = "iso-8859-1&q ...
- eclipse导入myeclipse的web项目
1.import> 2.进入项目目录,找到.project文件,打开 3.找到<natures> ...</natures>代码段,添加如下标签内容并保存 <nat ...