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 ...
随机推荐
- phplib系统开发经验总结
数据库设计: 数据库的设计一定要在了解整个系统需求的情况下,把数据库设计,及ER图画出来,数据库字典也要及时把握,只有掌握了这些才能下手开始设计界面,后期如果有需要,可以在数据库中添加数据,但要及时更 ...
- ie浏览器css中的行为expression详解
CSS中的行为——expression (ie only) 最近对CSS中的行为比较感兴趣,虽然是不符合标准的也只有ie才能识别,但是他确实给css的功能扩展了不少.下面是摘自互联网上的文字和例子,因 ...
- docpad建站记录
记一下用docpad建站的过程作为备忘.不定时更新 why docpad wordpress对我来说太过于臃肿,我就想要个代码干净的小站来写东西.想要个markdown为基础的静态站. 比较流行的St ...
- C语言实验——一元二次方程Ⅱ
C语言实验--一元二次方程Ⅱ Time Limit: 1 Sec Memory Limit: 64 MB Submit: 169 Solved: 131 [Submit][Status][Web ...
- 集合ArrayList案例
1.添加元素,读取 ArrayList n = new ArrayList(); n.Add();//集合中添加元素用Add,分别添加了1,2 n.Add(); foreach (int a in n ...
- flash builder 4 编译器参数
accessible=true|false 是否具有可理解性(如为残疾人提供方便的性能) actionscript-file-encoding | 设置文件编码,如Shitf_JIS advanced ...
- MBProgressHUD简单使用
使用HUD最多的情形用于请求等待提示 例如做登录的时候在确认登陆的时候可以用HUD提示正在登陆. 最基本的使用 初始化 //self.view代表在哪个view中显示hud MBProgressHUD ...
- ubuntu中彻底删除nginx
1.先执行一下命令: 1.1 删除nginx,–purge包括配置文件 sudo apt-get --purge remove nginx 1.2 自动移除全部不使用的软件包 sudo apt-get ...
- MVCC 多版本并发控制
关于事务的介绍暂且不谈. InnoDB行级锁,虽然在很大程度上提高了事务的并发性,但是终究还是要耗费很大的.为了更进一步的提高并发性同时降低开销,存储引擎会同时实现MVCC. InnoDB实现MVCC ...
- 深入浅出—JAVA(6)
6.认识JAVA的API Arraylist的操作