码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 3443(水题,公式)Shift Number

时间:2015-07-16 09:52:07      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

题意:

给一个数n,求最小的数生成的shift number等于n。
shift number就是一个数x,x*10,x*100…..这样的和。

思路

把那个公式处理一下,其实就是X*(形如11111….)这样的一个式子,那么找一个最大的11111….,x就是最小了。水题

复杂度:

O(len(n))

参考code:

/*
 #pragma warning (disable: 4786)
 #pragma comment (linker, "/STACK:0x800000")
 */
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
using namespace std;

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }


#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define F(i, n) for(int (i)=0;(i)<(n);++(i))
#define rep(i, s, t) for(int (i)=(s);(i)<=(t);++(i))
#define urep(i, s, t) for(int (i)=(s);(i)>=(t);--(i))
#define repok(i, s, t, o) for(int (i)=(s);(i)<=(t) && (o);++(i))            
#define MEM0(addr) memset((addr), 0, sizeof((addr)))
#define MP(x, y) make_pair(x, y)
#define REV(s, e) reverse(s, e)
#define SET(p) memset(pair, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define SZ(c) (int)c.size()
#define PB(x) push_back(x)
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pii pair< int, int >
#define psi pair< string, int >
#define ls u << 1
#define rs u << 1 | 1
#define lson l, mid, u << 1
#define rson mid, r, u << 1 | 1

const int maxn = 1e6+5;
const ll INF = 0x3f3f3f3f3f3fLL;

int main(){
    //READ("in.txt");
    ll n;
    while(scanf("%lld",&n)!=EOF && n){
        ll x = 1;
        while(x <= n) x = x * 10 + 1;
        while(n % x != 0) x /= 10;
        printf("%lld\n",n / x);
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu 3443(水题,公式)Shift Number

标签:

原文地址:http://blog.csdn.net/notdeep__acm/article/details/46900663

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!