USACO runaround
/*
ID:kevin_s1
PROG:runround
LANG:C++
*/ #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <list>
#include <cmath> using namespace std;
//直接枚举就可以 //gobal variable====
long long M;
int num[100];
int num_size; int hash[10];
int hash1[10];
//================== //function==========
int init(long long i){
int x = 1;
while(i != 0){
num[x++] = i % 10;
i = i / 10;
}
x--;
for(int i = 1; i <= x/2; i++){
int tmp = num[i];
num[i] = num[x - i + 1];
num[x - i + 1] = tmp;
}
return x;
} bool judge(long long x){
for(int i = 1; i <= num_size; i++){
hash1[num[i]]++;
if(hash1[num[i]] > 1 || num[i] == 0){
return false;
}
}
int j = 1;
for(int i = 1; i <= num_size; i++){
int bit = num[j];
j = j + bit;
if(j > num_size && (j % num_size) != 0){
j = j % num_size;
}
if(j > num_size && (j % num_size) == 0){
j = num_size;
}
if(hash[j] == 1){
return false;
}
hash[j] = 1;
}
bool flag = true;
if(j != 1)
flag = false;
for(int i = 1; i <= num_size; i++){
if(hash[i] == 0){
flag = false;
break;
}
}
return flag;
} //================== int main(){
freopen("runround.in","r",stdin);
freopen("runround.out","w",stdout);
cin>>M;
memset(num, 0, sizeof(num));
memset(hash, 0, sizeof(hash));
memset(hash1, 0, sizeof(hash1));
M++;
num_size = init(M);
while(!judge(M)){
M++;
memset(num, 0, sizeof(num));
memset(hash, 0, sizeof(hash));
memset(hash1, 0, sizeof(hash1));
num_size = init(M);
}
cout<<M<<endl;
return 0;
}
USACO runaround的更多相关文章
- USACO Runaround Numbers 模拟
根据题意的 Runaround 规则去找比当前数大的最近的一个 Runaround数字 模拟题~ Source code: /* ID: wushuai2 PROG: runround LANG: C ...
- USACO Runaround Numbers
题目大意:问最近的比n大的循环数是多少 思路:第n遍暴力大法好 /*{ ID:a4298442 PROB:runround LANG:C++ } */ #include<iostream> ...
- USACO 2.2 Runaround Numbers
Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81 ...
- 【USACO 2.2】Runaround Numbers
找出第一个大于n的数满足:每一位上的数都不同,且没有0,第一位开始每次前进当前这位上的数那么多位,超过总位数就回到开头继续往前进,最后能不能每个位都到过一次且回到第一位,$n<10^9$. 暴力 ...
- USACO Section 2.2 循环数 Runaround Numbers
OJ:http://www.luogu.org/problem/show?pid=1467 #include<iostream> #include<vector> #inclu ...
- USACO Section 2.2: Runaround Numbers
简单题 /* ID: yingzho1 LANG: C++ TASK: runround */ #include <iostream> #include <fstream> # ...
- USACO Section2.2 Runaround Numbers 解题报告 【icedream61】
runround解题报告---------------------------------------------------------------------------------------- ...
- 洛谷P1467 循环数 Runaround Numbers
P1467 循环数 Runaround Numbers 89通过 233提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 循环数是 ...
- Luogu USACO Training 刷水记录
开个坑记录一下刷USACO的Training的记录 可能会随时弃坑 只有代码和做法简述 可能没有做法简述 [USACO1.1]你的飞碟在这儿Your Ride Is He… 模拟,细节已忘 #incl ...
随机推荐
- [Node.js] Proxy Requests for Local and Remote Service Parity
High availability apps require that no distinction be made between local and remote services. Attach ...
- Dalvik和ART简单介绍
1.classes.dex文件初识 我们先把QQ_236.apk后缀改为QQ_236.zip,然后解压.发现有一个classes.dex文件,这个classes.dex是java源代码编译后生 ...
- Linux以下基于TCP多线程聊天室(client)
不怎么会弄这个博客的排版,就直接将代码附上: 主要是使用多线程去等待接受数据和发送数据.以下是client的代码: tcpsed.h文件 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...
- Mac OS下PHP开发环境的搭建——基于XAMPP和IntelliJ IDEA
简单记录一下在MacOS下,搭建PHP的开发环境吧.其实,从本质上来说,Mac对于PHP的支持还是很好的,默认带了PHP和Apache,但是由于前期对系统本身不熟悉,所以还是略微走了一些弯路--也就是 ...
- Linux就该这么学 20181011(第十五章邮件)
参考链接:https://www.linuxprobe.com. https://www.linuxprobe.com/chapter-15.html 电子邮箱系统 foxmail MUA 发送 MT ...
- 基本类型转换成NSNumber类型
int i=100; float f=2.34; NSNumber *n1=[NSNumber numberWithInt:i]; NSNumber *n2=[NSNumber numberWithF ...
- HD-ACM算法专攻系列(16)——考试排名
问题描述: 源码: 主要要注意输出格式. #include"iostream" #include"iomanip" #include"algorith ...
- 【转自网络】JS实现保存当前网页HTML到本地
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 双向链表C++实现
双向链表实现,通过C++实现 #ifndef LinkList_hpp #define LinkList_hpp typedef struct Node{ int data; Node* next; ...
- Photoshop保存文件时的选项
以 JPEG 格式存储 您可以使用"存储为"命令以 JPEG (*.jpg) 格式存储 CMYK.RGB 和灰度图像.JPEG 通过有选择地扔掉数据来压缩文件大小.也可以使用&qu ...