zoj 3622 Magic Number(找规律)

唉………………写的相当的乱,状态十分不好。

可以求每个数前面有多少个magic number,然后相减即可。

#include<iostream>
#include<cmath>
using namespace std;

int num(int x)
{
    int sum=0;
    while(x>0)
    {
        sum++;
        x/=10;
    }
    return sum-3;
}

double pow(int b)
{
    double s=1;
    for(int i=1; i<=b; i++)
        s*=10;
    return s;

}
int solve(int x)
{
    int s=0;
    if(x==1)
        return 1;

    s=log10(x);
    if(int(pow(s))==x)
    {
        if(x==10||x==100)
            return s*4;
        else
            return s*5-2;
    }
    if(x<10)
    {
        if(x>=5)
            s+=3;
        else if(x>=2)
            s+=2;
        else if(x>=1)
            s+=1;

    }
    else if(x<100)
    {
        s*=4;
        if(x>=50)
            s+=3;
        else if(x>=25)
            s+=2;
        else if(x>=20)
            s+=1;
    }
    else
    {
        int n=num(x);
        s=5*s-2;
        if(x>=500*pow(n))
        {
            s+=4;
        }
        else if(x>=250*pow(n))
            s+=3;
        else if(x>=200*pow(n))
            s+=2;
        else if(x>=125)
            s+=1;
    }
    return s;
}

int main()
{
    int m,n;
    while(cin>>m>>n)
    {
        int km,kn;
        if(m>n)
            swap(m,n);
        if(m==1)
        {
            km=1;
            kn=solve(n);
            cout<<kn-km+1<<endl;
            continue;
        }
        else
            km=solve(m-1);
        kn=solve(n);
        cout<<kn-km<<endl;
    }
    return 0;
}
时间: 2024-11-10 11:49:11

zoj 3622 Magic Number(找规律)的相关文章

zoj 3622 Magic Number 【规律】

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3622 题目大意: 如果一个数字x满足如下条件: 任意加一个数字y在x的左边,都能是yx是x的倍数,比如1满足,2满足,5满足条件. 然后最开始以为1 2 5 的十倍数10 20 50 , 100 200 500 以及很多,然后后来发现了一个bug就是25 ,发现找的规律是有问题的. 后来发现是10 100 1000 10000 分别除以1 2 3 4 5 6 7

ZOJ 3622 Magic Number 打表找规律

A - Magic Number Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3622 Appoint description: Description A positive number y is called magic number if for every positive integer x it satisfies that

ZOJ 3622 Magic Number(数)

题意  假设一个正整数y满足  将随意正整数x放到y的左边得到的数z满足 z%y==0  那么这个数就是个Magic Number   给你一个范围  求这个范围内Magic Number的个数 令 l表示y的位数  ly=10^l  那么z=x*ly + y  要z%y==0   easy看出  仅仅需 x*ly%y==0 又由于x是随意的  所以一个Magic Number必须满足 ly%y==0 y<2^31  所以l最大为10 直接枚举l  找到全部符合的y即可了 当 ly%y==0  

【ZOJ】3785 What day is that day? ——浅谈KMP应用之ACM竞赛中的暴力打表找规律

首先声明一下,这里的规律指的是循环,即找到最小循环周期.这么一说大家心里肯定有数了吧,“不就是next数组性质的应用嘛”. 先来看一道题 ZOJ 3785 What day is that day? Time Limit: 2 Seconds      Memory Limit: 65536 KB It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input There are multiple tes

ZOJ 3629(找规律)

Treasure Hunt IV Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled afrom b in front of her. Alice was very excited but

ZOJ 3768Continuous Login(找规律然后二分)

Continuous Login Time Limit: 2 Seconds      Memory Limit: 131072 KB      Special Judge Pierre is recently obsessed with an online game. To encourage users to log in, this game will give users a continuous login reward. The mechanism of continuous log

zoj 3629 Treasure Hunt IV(找规律)

Alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled a fromb in front of her.Alice was very excited but unfortunately not all of the treasures are real, some are fake.Now w

hdu 4952 Number Transformation (找规律)

题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值,求出这个固定的值和K相乘就可以了, 为什么会趋于固定的值呢,因为最后虽然i在不断增长,但是x也是在增长的,每次的倍数会回退一个发现 有余数,然后再加上一个,所以趋于稳定. 官方题解: 1 #include <iostream> 2 #include <cstdio> 3 #includ

HDU 4279 Number(找规律)

Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4288    Accepted Submission(s): 1066 Problem Description Here are two numbers A and B (0 < A <= B). If B cannot be divisible by A, and A