nyoj-975-关于521

来源:互联网 发布:吉林大学网络自助中心 编辑:程序博客网 时间:2024/05/21 12:49

关于521

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描述

Acm队的流年对数学的研究不是很透彻,但是固执的他还是想一头扎进去。

浏览网页的流年忽然看到了网上有人用玫瑰花瓣拼成了521三个数字,顿时觉得好浪漫,因为每个男生都会不经意的成为浪漫的制造者。此后,流年走到哪里都能看到521三个数字,他怒了,现在他想知道在连续的数中有多少数全部包含了这三个数字。例如12356就算一个,而5111就不算。特别的,如果他看到了521三个数连续出现,会特别的愤怒。例如35210

输入
多组测试数据:
一行给定两个数a,b(0<a,b<1000000),表示数字的开始和结束。
输出
一行显示他想要知道的数有几个及显示有多少个数字令他特别的愤怒。用空格隔开。
样例输入
200 500300 9001 600
样例输出
Case 1:2 0Case 2:2 1Case 3:6 1
来源
流年
上传者

ACM_安鹏程


#include <iostream>#include <string.h>using namespace std;int array[2][1000010];int main(){    int a, b, c;    int cnt = 0, cntp = 0;    memset(array, 0, sizeof(array));    for (int i = 1; i <= 1000000; i++)    {        a = b = c = 0;        if ((i/100000)%10 == 1 || (i/10000)%10 == 1                || (i/1000)%10 == 1 || (i/100)%10 == 1 || (i/10)%10 == 1 || i%10 == 1)            a = 1;        if ((i/100000)%10 == 2 || (i/10000)%10 == 2                || (i/1000)%10 == 2 || (i/100)%10 == 2 || (i/10)%10 == 2 || i%10 == 2)            b = 1;        if ((i/100000)%10 == 5 || (i/10000)%10 == 5                || (i/1000)%10 == 5 || (i/100)%10 == 5 || (i/10)%10 == 5 || i%10 == 5)            c = 1;        if (a && b && c)            ++cnt;        if ((i/1000)%1000 == 521 || (i/100)%1000 == 521                || (i/10)%1000 == 521 || (i%1000) == 521)            ++cntp;        array[0][i] += cnt;        array[1][i] += cntp;    }    int x, y, ca = 0;    while (cin >> x >> y)    {        cout << "Case " << ++ca << ":";        cout << array[0][y] - array[0][x-1] << " "             << array[1][y] - array[1][x-1] << endl;    }    return 0;}
#include <string.h>//超时#include <stdio.h>int main(){    char s[100];    int i,a,b,t=0;    while(2==scanf("%d%d",&a,&b))    {        int x=0,y=0;        for(i=a; i<=b; i++)        {            sprintf(s,"%d",i);            if(strstr(s,"1")&&strstr(s,"2")&&strstr(s,"5"))                x++;            if(strstr(s,"521"))                y++;        }        t++;        printf("Case %d:",t);        printf("%d %d\n",x,y);    }    return 0;}



0 0
原创粉丝点击