根据题意的 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. win7系统无线 VirtualBox rehat 32位linux 下 host-only模式相互通信及上网 配置

    虚拟机环境:virtualBox虚拟环境 redhat 32位 主机环境 : win7 无线路由 模式: host-only win7下nat模式原先的设置基于 有网线连接的情形下,在使用了无线路由之 ...

  2. eclipse编译错误

    ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 JDWP exit error AGE ...

  3. Nginx 的 Echo 模块 —— echo-nginx-module(转)

    Nginx 有个 echo 模块可以用来输出一些简单的信息,例如: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 ...

  4. 宣布与 NBC 合作直播索契冬季奥运

     奥运开始的那天早些时候,NBC 和 Microsoft 宣布选择 Windows Azure 媒体服务为 2014 年俄罗斯索契冬奥会提供现场直播.与以往不同,以往的冬奥会采用了有限的流,但本届 ...

  5. Android Animations动画使用详解

    一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...

  6. 没有login页面

    "/"应用程序中的服务器错误. 无法找到资源. 说明:HTTP 404.您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用.请检查以下 URL 并确保 ...

  7. Ext.MessageBox.Show使用Progress

    在此之前,先添加引用:以下引用方式仅供参考:由于我的extjs文件夹放在script文件夹下 <link href="~/Scripts/extjs/resources/ext-the ...

  8. ie调试控制台

    function initConsole() { var console = document.createElement('div'); console.id = 'errorConsole'; d ...

  9. jQuery 1.9+ ajaxStart事件无效,无法被触发的原因。

    AJAX 事件需要绑定到document 在jQuery 1.9中, 全局的AJAX事件(ajaxStart, ajaxStop, ajaxSend, ajaxComplete, ajaxError, ...

  10. Enze fifth day(循环语句2)

    又是新的一周开始了,我还在云和学院继续学习.因为想要急切的想学会更多的知识,所以我有些急.可是我越急就越容易出错,这应该就是所谓的欲速则不达吧.这一周,我要重新把控好自己的一切,尽我最大的努力来学习! ...