根据题意的 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 模拟的更多相关文章

  1. USACO Runaround Numbers

    题目大意:问最近的比n大的循环数是多少 思路:第n遍暴力大法好 /*{ ID:a4298442 PROB:runround LANG:C++ } */ #include<iostream> ...

  2. USACO 2.2 Runaround Numbers

    Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81 ...

  3. 洛谷P1467 循环数 Runaround Numbers

    P1467 循环数 Runaround Numbers 89通过 233提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 循环数是 ...

  4. USACO Humble Numbers

    USACO  Humble Numbers 这题主要是两种做法,第一种是比较常(jian)规(dan)的-------------用pq(priority_queue)维护,每次取堆中最小值(小根堆) ...

  5. 【USACO 2.2】Runaround Numbers

    找出第一个大于n的数满足:每一位上的数都不同,且没有0,第一位开始每次前进当前这位上的数那么多位,超过总位数就回到开头继续往前进,最后能不能每个位都到过一次且回到第一位,$n<10^9$. 暴力 ...

  6. USACO Section 2.2 循环数 Runaround Numbers

    OJ:http://www.luogu.org/problem/show?pid=1467 #include<iostream> #include<vector> #inclu ...

  7. USACO Section 2.2: Runaround Numbers

    简单题 /* ID: yingzho1 LANG: C++ TASK: runround */ #include <iostream> #include <fstream> # ...

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

    runround解题报告---------------------------------------------------------------------------------------- ...

  9. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

随机推荐

  1. tomcat远程debug端口开启

    declare -x CATALINA_OPTS="-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt ...

  2. Android UiAutomator 自动化测试环境搭建---新手1

    1.首先需要准备的工具有 1.java jdk 2. android开发工具 adt 3.ant 安装包(如果下载adt里面有) 2.首先安装java环境,jdk这个百度就可以了. 3.android ...

  3. 应用 Valgrind 发现 Linux 程序的内存问题

    如何定位应用程序开发中的内存问题,一直是 inux 应用程序开发中的瓶颈所在.有一款非常优秀的 linux 下开源的内存问题检测工具:valgrind,能够极大的帮助你解决上述问题.掌握 valgri ...

  4. HDU 2108 Shape of HDU

    题解:按照输入顺序依次将点连接起来,对于连续的三个点p0,p1,p2,令向量a=p1-p0,b=p2-p1 若是凸多边形,那么b相对于a一定是向逆时针方向旋转的 判断两向量的旋转方向,可以使用向量的叉 ...

  5. vector数据查找方法

    用STL编敲代码时常常使用vector容器来存储数据.当容器中的数据有序时我们能够採取两种方式: (1) 利用<algorithm>中的find函数进行查找: (2) 折半查找. 另外也能 ...

  6. 正则RegEXp

    JavaScript RegExp 对象 RegExp 对象 RegExp 对象表示正则表达式,它是对字符串执行模式匹配的强大工具. 直接量语法 /pattern/attributes 创建 RegE ...

  7. Group By 多个分组集小结 --GROUPING SETS,GROUP BY CUBE,GROUP BY ROLLUP,GROUPING(),GROUPING_ID()

    T-SQL 多个分组集共有三种 GROUPING SETS, CUBE, 以及ROLLUP, 其中 CUBE和ROLLUP可以当做是GROUPING SETS的简写版 示例数据库下载: http:// ...

  8. mac安装office2011,提示无法打开文件Normal.dotm,因为内容有错误

    最近使用mac上的office,发现一个问题,每次打开office11都会报错,提示“无法打开文件Normal.dotm,因为内容有错误”,于是就在网络上搜索了一下,找到如下一段话, I just f ...

  9. POJ 3903 Stock Exchange (E - LIS 最长上升子序列)

    POJ 3903    Stock Exchange  (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action ...

  10. git从github下载代码

    Github作为远程仓库的使用详解  http://blog.csdn.net/djl4104804/article/details/50778717 centos local:        通过g ...