USACO section 2.2 Runaround Numbers

三相SVPWM逆变器双闭环PI解耦控制:从dq坐标系到参数整定实战 本文深入解析了三相SVPWM逆变器的双闭环PI解耦控制技术。通过引入dq坐标系,将交流量转换为直流量,并结合前馈补偿实现电流环的解耦控制。文章详细阐述了从数学模型推导、控制器设计到参数整定与SVPWM实现的完整流程,为工程师提供了从理论到实战的系统性指导。 阅读详情
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

 

Android TV 遥控器全链路按键适配指南:从物理按键到应用响应 本文深入探讨了Android TV遥控器按键适配方案,涵盖红外和蓝牙遥控器的工作原理及完整适配流程。红外遥控部分详细介绍了从硬件调试、驱动适配到键值映射配置的方法,并提供了实用的调试命令。蓝牙遥控器部分解析了HID协议和报告描述符,给出内核层与Android层的适配代码示例。文章还介绍了游戏手柄、语音遥控器等特殊外设的适配技巧,并提供了系统级调试工具和内核级调试方法,为开发者提供了一套完整的Android TV输入设备适配解决方案。 阅读详情

相关推荐

PP触发EWM产生PMR捡配

PP触发EWM产生PMR捡配 前言 PMR: Production Material Request 在流程订单/生产订单下达后,可以在EWM中产生PMR,在EWM中, PMR其实代表了ERP中的流程订单/生产订单。 You can use SAP EWM in conjunction with the following PP application components: • Production Orders • Process Orders • Repetitive Manufacturing •

ZevYang的博客 1918

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

全面分析总结解决Could not transfer artifact org.apache.maven.plugins等此类问题的方法

全面分析总结解决Could not transfer artifact org.apache.maven.plugins,Could not transfer artifact xxx from/to xxx等此类问题的方法

ccjjjjdff的博客 1万+

[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

从315MHz到125kHz:手把手教你用Arduino模拟汽车钥匙的RKE/PKE信号(附代码)

本文详细介绍了如何使用Arduino开发板和射频模块模拟汽车钥匙的RKE/PKE信号,包括硬件准备、代码实现和安全机制。通过实践教程,读者可以深入理解315MHz和125kHz信号在汽车电子领域的应用,掌握无钥匙进入系统的核心技术。

weixin_30945039的博客 223

深度学习图神经网络 (GNN) —— 处理图结构数据(六十九)

本文系统介绍了图神经网络(GNN)的核心概念、主流模型及其应用。主要内容包括: GNN基础:阐述了图结构数据的特性(节点数不定、连接不规则),以及GNN相比CNN/RNN的优势在于处理非欧式空间的图数据。 核心机制:重点讲解了消息传递框架(MPNN),通过聚合邻居信息迭代更新节点表示,并分析了GCN的归一化邻接矩阵计算和GAT的注意力权重机制。 典型模型: GCN:基于归一化邻接矩阵的特征传播 GAT:引入注意力机制区分邻居重要性 GraphSAGE:通过采样解决大图扩展性问题 GIN:理论表达能力最强的图

hello.reader 300

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

这才是 Python 的正确玩法!用强化学习 (RL) 训练 AI 玩《王者荣耀》,胜率 90%!

大家打排位时,一定遇到过那种“意识神级、操作零失误”的对手,或者“走位呆滞、送人头”的队友。以前的“人机”是程序员写死的脚本(If 血量<20% Then 回城)。而现在的顶级 AI(如腾讯绝悟、OpenAI Five),是靠强化学习 (Reinforcement Learning)自己“左右互搏”练出来的。今天,我们不谈枯燥的数学公式,我将手把手教你用,搭建一个能玩 MOBA 游戏的 AI Agent。即使不能去 KPL 打职业,虐一下钻石局还是绰绰有余的!

BUG猿的博客 1182

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

【unity实战】Unity手搓脚本工具实现合并网格功能

本文介绍了在Unity中优化网格性能的方法,通过合并重复网格减少绘制调用。主要使用Mesh.CombineMeshes方法实现网格合并,支持统一材质和多材质处理。核心内容包括:1)基础合并脚本实现,将子网格合并到父对象并禁用原网格;2)统一材质设置,支持自定义或默认材质;3)多材质合并方案,通过设置mergeSubMeshes=false保留子网格材质索引。文章还提供了完整代码示例和操作演示,适用于实际项目中的网格优化需求。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 558

【WRF理论第十九期】内陆湖泊、水体的处理方式

【WRF理论第十九期】内陆湖泊、水体的处理方式

WW、forever的博客 358

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

数据分享:中国历年省、市、县行政区划shp(1949~2023年共计75年)

中华人民共和国县级以上行政区沿革》(三册,1949-1983年)“The Atlas of Changes of Administrative Regions of China”;《中华人民共和国行政区划沿革地图集》The yearly publications of “The Administrative Regions”, 1985-2014;每年的出版行政区划简册(1985-2014年)行政区划网:www.xzqh.org。行政区划网:www.xzqh.org。

J_Giser的博客 3687

USACO - Chapter2 Section 2.2 - Runaround Numbers

Runaround Numbers

zhuo1ang的博客 382

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

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

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Usaco Training Section 2.2 Runaround Numbers

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

Monster的博客 208

计算机控制技术及应用

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

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、付费专栏及课程。

余额充值