USACO section 2.2 Runaround Numbers

川崎机器人总线通信_三菱PLC和发那科机器人进行CCLINK总线通信 三菱CCLINK主站模块采用QJ61BT11N,该模块用在Q系列PLC上,如果是5U或3UPLC,可用FX5-CNV-BUS加FX3U-16CCL-M或FX5-CCL-M模块。本教程以Q系列为例CCLINK接线方法如下模块拨码含义如下接线和拨码设置好后,接着在编程软件上设置CCLINK通信参数打开编程软件,在工程导航栏打开参数——网络参数,选中CCLINK打开。打开如下画面起始IO为模块本体占用I... 阅读详情
Runaround Numbers

Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration:

  • If you start at the left digit (8 in our number) and count that number of digits to the right (wrapping back to the first digit when no digits on the right are available), you'll end up at a new digit (a number which does not end up at a new digit is not a Runaround Number). Consider: 8 1 3 6 2 which cycles through eight digits: 1 3 6 2 8 1 3 6 so the next digit is 6.
  • Repeat this cycle (this time for the six counts designed by the `6') and you should end on a new digit: 2 8 1 3 6 2, namely 2.
  • Repeat again (two digits this time): 8 1
  • Continue again (one digit this time): 3
  • One more time: 6 2 8 and you have ended up back where you started, after touching each digit once. If you don't end up back where you started after touching each digit once, your number is not a Runaround number.

Given a number M (that has anywhere from 1 through 9 digits), find and print the next runaround number higher than M, which will always fit into an unsigned long integer for the given test data.

PROGRAM NAME: runround

INPUT FORMAT

A single line with a single integer, M

SAMPLE INPUT (file runround.in)

81361

OUTPUT FORMAT

A single line containing the next runaround number higher than the input value, M.

SAMPLE OUTPUT (file runround.out)

81362

没什么好说的神搜一下即可,注意题意;

 

/*
ID:nealgav1
PROG:runround
LANG:C++
*/
#include<fstream>
#include<cstring>
using namespace std;
const int mm=1234;
bool vis[mm];
int len,_num;
int num;
bool flag;
void dfs(char[],int,int);
bool charge(int shu)
{ len=0;
  memset(vis,0,sizeof(vis));
  char s[33];
  while(shu)
  {
   //cout<<shu%10;
   if(shu%10==0||vis[shu%10])return 0;
   vis[shu%10]=1;
    s[len]=shu%10+'0';
    len++;shu/=10;
  }
  int front=0,rear=len-1;char ms;
  while(front<rear)
  {
    ms=s[front];s[front]=s[rear];s[rear]=ms;front++;rear--;
  }
  memset(vis,0,sizeof(vis));
  _num=0;flag=0;
  dfs(s,len,0);
  if(flag)
  return 1;
  else return 0;
}
void dfs(char s[],int lenth,int pos)
{
  int next=s[pos]-'0';
  vis[pos]=1;_num++;
  next=(next+pos)%lenth;
  if(_num==lenth&&next==0){flag=1;return;}
  if(!vis[next])
  dfs(s,lenth,next);
}
int main()
{
  ifstream cin("runround.in");
  ofstream cout("runround.out");
  cin>>num;
 // cout<<num%10<<"OJ";
  for(int i=1;i<=999999;i++)
  if(charge(++num))
  {
    cout<<num<<"\n";
    break;
  }
}


 

 

 

USER: Neal Gavin Gavin [nealgav1]
TASK: runround
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3336 KB]
   Test 2: TEST OK [0.011 secs, 3336 KB]
   Test 3: TEST OK [0.011 secs, 3336 KB]
   Test 4: TEST OK [0.011 secs, 3336 KB]
   Test 5: TEST OK [0.076 secs, 3336 KB]
   Test 6: TEST OK [0.054 secs, 3336 KB]
   Test 7: TEST OK [0.108 secs, 3336 KB]

All tests OK.

Your program ('runround') produced all correct answers! This is your submission #2 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
99
------- test 2 ----
111110
------- test 3 ----
134259
------- test 4 ----
348761
------- test 5 ----
1000000
------- test 6 ----
5000000
------- test 7 ----
9000000
Keep up the good work!


Thanks for your submission!

Runaround NumbersRuss Cox

The trick to this problem is noticing that since runaround numbers must have unique digits, they must be at most 9 digits long. There are only 9! = 362880 nine-digit numbers with unique digits, so there are fewer than 9*362880 numbers with up to 9 unique digits. Further, they are easy to generate, so we generate all of them in increasing order, test to see if they are runaround, and then take the first one bigger than our input.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

int m;
FILE *fout;

/* check if s is a runaround number;  mark where we've been by writing 'X' */
int
isrunaround(char *s)
{
    int oi, i, j, len;
    char t[10];

    strcpy(t, s);
    len = strlen(t);

    i=0;
    while(t[i] != 'X') {
	oi = i;
	i = (i + t[i]-'0') % len;
	t[oi] = 'X';
    }

    /* if the string is all X's and we ended at 0, it's a runaround */
    if(i != 0)
	return 0;

    for(j=0; j<len; j++)
	if(t[j] != 'X')
	    return 0;

    return 1;
}

/*
 * create an md-digit number in the string s.
 * the used array keeps track of which digits are already taken.
 * s already has nd digits.
 */
void
permutation(char *s, int *used, int nd, int md)
{
    int i;

    if(nd == md) {
	s[nd] = '\0';
	if(atoi(s) > m && isrunaround(s)) {
	    fprintf(fout, "%s\n", s);
	    exit(0);
	}
	return;
    }

    for(i=1; i<=9; i++) {
	if(!used[i]) {
	    s[nd] = i+'0';
	    used[i] = 1;
	    permutation(s, used, nd+1, md);
	    used[i] = 0;
	}
    }
}


void
main(void)
{
    FILE *fin;
    char s[10];
    int i, used[10];

    fin = fopen("runround.in", "r");
    fout = fopen("runround.out", "w");
    assert(fin != NULL && fout != NULL);

    fscanf(fin, "%d", &m);

    for(i=0; i<10; i++)
	used[i] = 0;

    for(i=1; i<=9; i++)
	permutation(s, used, 0, i);

    assert(0);	/* not reached */
}

Another look

Diego Exactas from Argentina has a better solution that runs extremely quickly.

This is my solution, with doesn't generate all solutions, but just looks for the next one.

#include <fstream>
#include <string>
#include <vector>
#include <algorithm>

#define INPUT_FILE "runround.in"
#define OUTPUT_FILE "runround.out"

using namespace std;

void NextNumber(std::vector<int>& number, int Digits) {
    number[Digits - 1]++;
    for (int i = Digits - 1; i >= 0; i--) {
        if (number[i] == 10) {
            number[i] = 1;
            if (i == 0) {
                number.insert (number.begin(),1);
                return;
            } else 
                number[i - 1]++;
        }
    }
    return;
}

bool CheckElement(std::vector<int>::iterator first,
    std::vector<int>::iterator last, int val) {
    while (first < last) {
        if (*first == val) 
            return true;
        ++first;
    }
    return false;
}

void NextUniqueNumber(std::vector<int>& number) {
    std::vector<int> old = number;
    for (int i = 1; i < number.size(); ++i) {
        if (number[i] == 0) number[i]++;
        while (CheckElement (number.begin(),number.begin() + i,number[i])) {
            number[i]++;
            if (number[i] == 10) {
                number[i] = 1;
                NextNumber (number,i);
                i = 1;
                continue;
            }
        }
    }
    return;
}

bool IsRoundNumber(std::vector<int>& number) {
    std::vector<bool> used(10,false);
    for (int i = 0, pos = 0, val = number[0]; i < number.size(); i++) {
        pos = (pos + val) % number.size();
        val = number[pos];
        if (used[pos] == true) return false;
        used[pos] = true;
    }
    return true;
}

unsigned int NextRoundNumber(unsigned int numb

 

电磁兼容(EMC)整改案例(七):EFT测试失败都是IC悬空引脚惹的祸 无论任何时候,为了避免这些问题,通常建议对悬空的IO口进行适当的配置,比如设置为强推挽输出低电平、输入带上拉或下拉电阻等,以减少外部电路对IO管脚状态的影响,并提高系统的稳定性和可靠性. 阅读详情

相关推荐

电芯外观及体系设计(Cell Design)-①容量平衡设计(Cell Balance Design)

全面获取并正确解读客户需求,将需求进行分解和预判,结合公司现有资源、技术,给出设计方案。一个优秀的电芯设计方案,应该是稳健的,可操作的,满足客户需求的同时,并能为公司带来较多利润。电芯设计需同时考虑周期,性能,品质,加工性,成本,及安全与稳健性。设计人员时刻要有成本控制观念,但利润则是由公司战略所决定。

FDC1303864002的博客 1352

Runaround Numbers(枚举)

Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration: If you start at ...

Simone chou... 222

树莓派 SPI操作

扩展板配备一款0.96inch,128864分辨率的oled显示屏,通过SPI控制,先上显示效果图。由于程序过长,在这里我就不把代码全部贴出来了,只是简单讲解一下spi的操作函数。管脚如下如所有,左边方框的管脚分别为MOSI MISO SCLK,左边CE0,CE1为两个片选管脚,分别对应上图中的spidev0.0,spidev0.1两个设备。下载spidev库,复制到树莓派,并行运行如下命令解压安装。spi设备,此处设备为/dev/spi-decv0.0。在/dev路径下面,我们可以发现两个spi设备。

weixin_46529898的博客 914

[USACO]Runaround Numbers

Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration: If you start a

newcomer 619

Pascal Context数据集实战:从安装到格式转换的完整指南

本文提供了Pascal Context数据集的完整实战指南,从安装配置到格式转换的详细步骤。Pascal Context是计算机视觉领域重要的语义分割数据集,包含540个精细标注类别。文章涵盖数据集下载、环境配置、预处理技巧和常见问题解决方案,帮助开发者高效利用这一数据集进行场景理解任务。

weixin_30216561的博客 616

【自动驾驶学习笔记——Prescan和Simulink 学习笔记和问题记录(1)】

主要记录一些Prescan/Simulink 联合仿真出现的问题。

ly1336545868的博客 1464

USACO2.2.3 Runaround Numbers

Runaround Numbers Runaround numbers are integers with unique digits, none of which iszero (e.g., 81362) that also have an interesting property, exemplifiedby this demonstration: If you start at

supersnow0622的专栏 1361

超级全的PCB LAYOUT高速信号走线指南——简化应用版

在PCB Layout中,几乎涵盖了所有的高速信号走线指南。包括了TF/SD、HDMI、LVDS、DVP、eDP、MIPI、USB2.0、USB3.0、MAC、BT.1120、PCIE高速信号等等。此版本为简化版。

bhxc809751502的博客 8548

USACO Section 2.2 Runaround Numbers

Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration: If you start

258

【学习系列】SAP RAP 16:RAP应用部署集成至Fiori Launchpad 【On-Premise】

本文详细介绍了如何将开发完成的RAP应用部署到S4HANA 2023 On-Premise环境并集成到Fiori Launchpad的完整流程。主要内容包括:1)通过ADT工具创建Fiori项目并配置外部IDE(VSCode);2)使用npm命令部署应用到系统;3)通过事务代码创建语义对象、磁贴目录和目标映射;4)配置PFCG角色分配;5)补充了部署失败解决方案、翻译问题处理、自定义主题设置以及登录页面LOGO修改等内容。文章提供了step-by-step的操作指南,帮助开发者将预览模式的应用正式部署到生产

DeveloperMrMeng的博客 632

【数据集】全球首个10米分辨率精细分类土地覆盖数据集GLC_FCS10

【数据集】全球首个10米分辨率精细分类土地覆盖数据集GLC_FCS10

WW、forever的博客 1567

USACO SECTION 2.2 Runaround Numbers

Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration: If you start

301

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

USACO - Chapter2 Section 2.2 - Runaround Numbers

Runaround Numbers

zhuo1ang的博客 382

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

USACO section2.2 Runaround Numbers题解&代码

果然大半夜困成狗根本不能做题...用了memset()没加string.h也是醉醉的... 最简单粗暴的暴力...一个小优化或许是如果待检验数字有两个数字相等直接排除... /* ID: rainbow16 LANG: C++ TASK: runround */ #include #include #include using namespace std; int a[10],k[1

Rainbow6174's home 807

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Usaco Training Section 2.2 Runaround Numbers

一个数,它的每个数字互不相同且均不为0,从它的首位出发。若当前位的数字为x,下一次往后数x位。若每个数字都到过一次后,又回到了首位,则该数即为所求数。 求m后第一个这样的数。   审题很关键啊!!! 第一次提交没看到“每个数字都到过一次后”,第二次提交没看到“它的每个数字互不相同且均不为0”。无语了。。。   这题不用想多,直接暴力枚举。 #include&lt;bits/stdc...

Monster的博客 208

USACO-Section 2.2 Runaround Numbers (枚举)

这么快就又是一道简单题,最大的数为987654321,而且相邻两个循环数相差不大,直接枚举即可。

idealism_xxm的专栏 546

USACO Training Section 2.2 Runaround Numbers

[url="http://ace.delos.com/usacoprob2?a=3nbwNTZTBNm&S=runround"]英文原题[/url] [url="http://www.wzoi.org/usaco/12%5C205.asp"]中文题译[/url] 相当简单的逐个查找是否满足要求的数,注意题目里说数字是唯一的。 [code="C++"] /* ID: black...

山中竹笋 195

USACO-Section2.2 Runaround Numbers

USACO-Section2.2 Runaround Numbers

qq_34600424的博客 352

USACO-Section2.2 Runaround Numbers [其他][模拟]

题目大意 循环数是这样的整数:它包含的数字都是独特不相同的,(如1111就是不正确的),而且没有0,例如81362。它有一个有趣的性质: 1.从左端开始,当前的数是多少就往右数几位(首尾相接,即认为最右边的数字之后是左边第一个数),对于81362,你将会停在一个新数字6上 2.重复上述过程,这回数6个数字因为刚刚停在6上。你将会停在2上 3.继续,(数2个数字),停在1

yoer77的博客 402

USACO-Section2.2 Runaround Numbers【暴力枚举】

题目描述:循环数是这样的整数:它包含的数字都是独特不相同的,(如1111就是不正确的),而且没有0,例如81362。它有一个有趣的性质: 1.从左端开始,当前的数是多少就往右数几位(首尾相接,即认为最右边的数字之后是左边第一个数),对于81362,你将会停在一个新数字6上 2.重复上述过程,这回数6个数字因为刚刚停在6上。你将会停在2上 3.继续,(数2个数字),停在1 4.继续,(数1个数

tjj1998的博客 383

USACO Section 2.2 Runaround Numbers - 又一个枚举的思想

题目说的这种数长度最多为9,每位都不重复..并且没有0..所以如果事先枚举所有这些数再判断的话需要枚举的个数是9!=362880...才30多W~~果断先枚举出可能的所有情况~~就按题目要求的判断下~~枚举的同时就能保证是有序的~~所以后来的查找输出就从1开始找到第一个大于输入的数就ok了... Program: /* ID: zzyzzy12 LANG: C++ TASK:

zzyzzy12 773

USACO Section2.2 Runaround Numbers 解题报告 【icedream61】

    runround解题报告------------------------------------------------------------------------------------------------------------------------------------------------【题目】   给你一个数M,找出第一个比它大的循环数。   循环数:不包括0、...

weixin_30311605的博客 311
上一篇: USACO section 2.2 Subset Sums(DP,背包)
下一篇: USACO section 2.2 Party Lamps
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值