nyoj 1172 unlucky number

unlucky number

时间限制:1000 ms  |  内存限制:65535 KB

难度:0

描述
我们定义在区间【l,r】之间只出现1和7组合的数是unlucky number,例如:1 、7、 11、17 都是unlucky numbers ,而 13 、27则不是,问在区间【l,r】内有多少 unlucky numbers??

输入
有多组测试数据(不超过100组)

每组输入两个整数l,r( 0 =< l<= r <= 10^18)

输出
每行输入一个结果
样例输入
1 7
样例输出
2
上传者

ACM_张书军

思路:和丑数思路一样 用前面的数便利出后面的数

打个表

然后判断l,r在表中的位置,统计unlucky numbers就行了

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long a[1000000];
int c;
void init()
{
    c=0;
    a[c++]=1;
    a[c++]=7;
    int k=0;
    while(a[c-1]<1e18)
    {
        a[c++]=a[k]*10+1;
        a[c++]=a[k]*10+7;
        k++;
    }
}
int main()
{
    init();
    long long l,r;
    while(cin>>l>>r)
    {
        int L=0,R=0;
        for(int i=0; i<c; i++)
        {
            if(a[i]<=l) L=i;
            if(a[i]>r)
            {
                R=i;
                break;
            }
        }
        if(a[L]==l||l==0) L--;
        printf("%d\n",R-L-1);
    }
}
        

时间: 2024-12-11 13:56:41

nyoj 1172 unlucky number的相关文章

NYOJ 411 Friends number (数论--因子和)

链接:点击打开链接 题意: Friends number 时间限制:2000 ms  |  内存限制:65535 KB 难度:2 描述 Paula and Tai are couple. There are many stories between them. The day Paula left by airplane, Tai send one message to telephone 2200284, then, everything is changing- (The story in

2001年3月英语中级口译真题答案及听力原文

2001.3 上海市英语中级口译资格证书第一阶段考试 参考答案: SECTION 1: LISTENING TEST Part A: Sport Dictation 1. television viewers                           2. recent research 3. more far-reaching                           4. power of authority 5. gets away with              

NYOJ 427 &amp; HDU 1005 Number Sequence(找循环节)

[题目链接]click here~~ [题目大意]已经 f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.求f(n), [解题思路]:此题是大三届的一场比赛题,前几天做了下,结果是不忍直视啊,wa了几乎一页了,最开始想的是用矩阵快速幂,但是想了想,取模数才不到10,7 7=49,也就是说最大结果不超过49种可能,直接模拟递推式试试,结果发现不行,后来想到了用循环节,不难想到: 如果结果有两个答案连着 =1,则后面的全部和

ural 1217. Unlucky Tickets

1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each time in the bus, getting a ticket with a 6-digit number, they try to sum up the first half of digits and the last half of digits. If these two sums ar

NYOJ 587 blockhouses 【DFS】

blockhouses 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse is a small castle th

NYOJ 1103 —— m划分为n个正整数的个数

多边形划分 时间限制:1000 ms  |  内存限制:65535 KB 描述 Give you a convex(凸边形), diagonal n-3 disjoint divided into n-2 triangles(直线), for different number of methods, such as n=5, there are 5 kinds of partition method, as shown in Figure 输入 The first line of the inp

ZOJ 3233 Lucky Number

Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 323364-bit integer IO format: %lld      Java class name: Main Watashi loves M mm very much. One day, M mm gives Watashi a chance to choose a number

NYOJ 293 Sticks 【深搜】+【剪枝】

这是一道让人泪奔的题,它深刻的说明了什么是剪枝,哪怕是再小的一个细节,一旦递归规模增大都会引发巨大的时间消耗,真是神题~ Sticks 时间限制:3000 ms  |  内存限制:65535 KB 难度:5 描述 George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the

NYOJ 1067 Compress String(区间dp)

Compress String 时间限制:2000 ms  |  内存限制:65535 KB 难度:3 描述 One day,a beautiful girl ask LYH to help her complete a complicated task-using a new compression method similar to Run Length Encoding(RLE) compress a string.Though the task is difficult, LYH is