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,布布扣,bubuko.com

时间: 2024-08-25 09:40:30

USACO runaround的相关文章

USACO Runaround Numbers 模拟

根据题意的 Runaround 规则去找比当前数大的最近的一个 Runaround数字 模拟题~ Source code: /* ID: wushuai2 PROG: runround LANG: C++ */ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream>

usaco Runaround Numbers

题意为一个数从最左边开始,往右数这个位上的个数个,然后这样走一圈,回到起点,每个数字都访问过且只访问一次,这个数字就是循环数 要求找出第一个比N大的循环数 /* ID: modengd1 PROG: runround LANG: C++ */ #include <iostream> #include <math.h> #include <stdio.h> #include <memory.h> using namespace std; bool isarro

USACO Section 2.2 Runaround Numbers

/* ID: lucien23 PROG: runround LANG: C++ */ #include <iostream> #include <fstream> #include <cstring> using namespace std; int main() { ifstream infile("runround.in"); ofstream outfile("runround.out"); if(!infile || !

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

runround解题报告------------------------------------------------------------------------------------------------------------------------------------------------[题目] 给你一个数M,找出第一个比它大的循环数. 循环数:不包括0.没有重复数字,并且有循环性质的正整数. 循环性质:以81362为例 1.找到最高位,是8,那么往下数8位,依次是1,3

【USACO 2.2】Runaround Numbers

找出第一个大于n的数满足:每一位上的数都不同,且没有0,第一位开始每次前进当前这位上的数那么多位,超过总位数就回到开头继续往前进,最后能不能每个位都到过一次且回到第一位,$n<10^9$. 暴力,每次n++后模拟一边判断是否符合条件. /* TASK:runround LANG:C++ */ #include<cstdio> #include<cstring> using namespace std; int n; int get(int now,int step,int l

COGS 696. [IOI1996][USACO 2.3] 最长前缀

★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当于 Pascal 中的 “+” 运算符)组成一个序列 S ,那么我们认为序列 S 可以分解为 P 中的元素.元素不一定要全部出现(如下例中B

USACO prefix TrieTree + DP

/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib>

【USACO 1.3.4】牛式

[題目描述 ] 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ---------- * * * * * * ---------- * * * * 数字只能取代*,当然第一位不能为0,况且给定的数字里不包括0. 注意一下在美国的学校中教的"部分乘积",第一部分乘积是第二个数的个位和第一个数的积,第二部分乘积是第二个数的十位和第一个数的乘积. 写一个程序找出所有的牛式. [格式] INPUT FORMAT: (f

USACO Chapter 1 Section 1.1

USACO的题解和翻译已经很多了... 我只是把自己刷的代码保存一下. 1.PROB Your Ride Is Here 1 /* 2 ID:xiekeyi1 3 PROG:ride 4 LANG:C++ 5 */ 6 7 #include<bits/stdc++.h> 8 using namespace std ; 9 10 int main() 11 { 12 freopen("ride.in","r",stdin); 13 freopen(&quo