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>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ;
const int MAX_N = ;
const int MAXSIZE = ; ll num;
ll a[]; void toStr(ll num){
int i, j, k;
memset(a, , sizeof(a));
while(num){
a[++a[]] = num % 10LL;
num /= 10LL;
}
for(i = ; i <= a[] / ; ++i){
swap(a[i], a[a[] - i + ]);
}
} void toNum(){
int i, j, k;
num = ;
ll nl = 1LL;
for(i = a[]; i >= ; --i){
num += nl * a[i];
nl *= 10LL;
}
} bool solve(){
int i, j, k, pos;
ll ans[];
ll cur = a[];
ll b[], bigg = ;
bool vis[];
memset(vis, , sizeof(vis));
memset(ans, , sizeof(ans));
for(i = ; i <= a[]; ++i){
checkmax(bigg, a[i]);
if(a[i] == ) return false;
if(ans[a[i]]) return false;
ans[a[i]] = true;
}
for(;;){
memset(b, , sizeof(b));
for(pos = ; pos <= a[]; ++pos){
if(cur == a[pos]) break;
}
for(i = pos; i <= cur + pos - ; ++i){
b[++b[]] = a[i % a[] + ];
}
/*
for(i = 1; i <= b[0]; ++i){
cout << b[i];
}
cout << endl;
*/
if(vis[b[b[]]]) return false;
else vis[b[b[]]] = true;
for(i = ; i <= bigg; ++i){
if(vis[i] != ans[i]) break;
}
if(i == bigg + ) return true;
cur = b[b[]];
}
} int main() {
ofstream fout ("runround.out");
ifstream fin ("runround.in");
int i, j, k, t, n, s, c, w, q;
fin >> num;
++num;
toStr(num);
/*
for(i = 1; i <= a[0]; ++i){
cout << a[i];
}
cout << endl;
*/
while(!solve()){
//cout << num << endl;
toNum();
++num;
toStr(num);
}
fout << num << endl; fin.close();
fout.close();
return ;
}
USACO Runaround Numbers 模拟的更多相关文章
- 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 ...
- 洛谷P1467 循环数 Runaround Numbers
P1467 循环数 Runaround Numbers 89通过 233提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 循环数是 ...
- USACO Humble Numbers
USACO Humble Numbers 这题主要是两种做法,第一种是比较常(jian)规(dan)的-------------用pq(priority_queue)维护,每次取堆中最小值(小根堆) ...
- 【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解题报告---------------------------------------------------------------------------------------- ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
随机推荐
- codeforces 607B. Zuma 区间dp
题目链接 给一个长度为n的序列, 每一次可以消去其中的一个回文串, 问最少几次才可以消完. 代码很清楚 #include <iostream> #include <vector> ...
- ural1057 Amount of degrees 位数统计
#include <iostream> #include <string> using namespace std; ][]; void init(){ f[][] =; ;i ...
- android-意图Intent
Android基本的设计理念是鼓励减少组件间的耦合,因此Android提供了Intent (意图) ,Intent提供了一种通用的消息系统,它允许在你的应用程序与其它的应用程序间传递 Intent 来 ...
- AngularJS Factory Service Provider
先看看http://www.cnblogs.com/mbydzyr/p/3460501.html http://www.oschina.net/translate/angularjs-factory- ...
- 图标字体IcoMoon 使用
IcoMoon 使用官方地址 http://icomoon.io/实际上,它是一种字体,只不过这种字体的字象图标一样,比如windows中自带的MT Extra Webdings Wingdings字 ...
- JQuery 限制文本框只能输入数字和小数点
$(function(){ /*JQuery 限制文本框只能输入数字*/ $(".NumText").keyup(function(){ $(this).val($(this).v ...
- 不用注册热键方式在Delphi中实现定义快捷键(又简单又巧妙,但要当前窗体处在激活状态)
第一步:在要实现快捷键的窗体中更改属性“KeyPreview”为True:第二步:在要实现快捷键的窗体中的OnKeyPress事件中填入一个过程名称(在Object Inspector中),填写好后回 ...
- opencv-python 学习笔记2:实现目光跟随(又叫人脸跟随)
如果机器人的脸能随着前方人脸而转动,你会不会觉得这种互动很有意思.年前的时候,学习了一下opencv,通过opencv可以简单的实现人脸跟随.再加上几个舵机控制头部转动,机器人就可以互动了.呵呵 这里 ...
- JavaScript constructor prototyoe
想加深一下自己对construtcor prototype的印象所以写了这一篇文章 对象的constructor 就是Object 除了通过构造函数创建的对象意外 他的constructor 都是 都 ...
- ServiceBase 类
https://msdn.microsoft.com/zh-cn/library/System.ServiceProcess.ServiceBase%28v=vs.80%29.aspx 为将作为服务应 ...