hdu 5327 Olympiad (多校联赛) ——模拟

here

题意:给你两个数,让你求出这两个数之间有多少个数,这个数满足他的每一位的数都不相同。例如 113 不满足 143 满足。

Problem Description

You are one of the competitors of the Olympiad in numbers. The problem of this year relates to beatiful numbers. One integer is called beautiful if and only if all of its digitals are different (i.e. 12345 is beautiful, 11 is not beautiful and 100 is not beautiful).
Every time you are asked to count how many beautiful numbers there are in the interval [a,b] (a≤b).
Please be fast to get the gold medal!

Input

The first line of the input is a single integer T (T≤1000),
indicating the number of testcases.

For each test case, there are two numbers a and b,
as described in the statement. It is guaranteed that 1≤a≤b≤100000.

我的思路直接暴力打表,都是打表,但是想法太有差距了,从这两段代码中可以看出。自省~~

code:

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
#include<vector>
#include<math.h>
#define max1(a,b) a>b?a:b
using namespace std;
bool is(int i)
{
    int a,b,c,d,e;
    a=i%10;
    b=i%100/10;
    c=i%1000/100;
    d=i%10000/1000;
    e=i%100000/10000;
    if(e==0&&d==0&&c==0&&b==0)
    {
        return true;
    }
    else if(e==0&&d==0&&c==0&&b!=0)
    {
        if(b!=a)
            return true;
    }
    else if(e==0&&d==0&&c!=0)
    {
        if(a!=b&&a!=c&&b!=c)
            return true;
    }
    else if(e==0&&d!=0)
    {
        if(a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d)
            return true;
    }
    else if(e!=0)
    {
        if(a!=b&&a!=c&&a!=d&&a!=e&&
                b!=c&&b!=d&&b!=e&&
                c!=d&&c!=e&&
                d!=e)
            return true;
    }
    return false;
}
int a[100005];
int main()
{
    a[1]=1;
    for(int i=2; i<=99999; i++)
    {
        if(is(i))
            a[i]=a[i-1]+1;
        else
            a[i]=a[i-1];
    }
    a[100000]=a[99999];
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int c,b;
        scanf("%d%d",&c,&b);
        printf("%d\n",a[b]-a[c-1]);
    }
}

优秀代码:这就是思想的差距。

#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int temp[10];
int ans[100001];
int i,j,n,a,b;

int fun1(int x)//用于判断数字是否满足条件
{
    int mod;
    memset(temp,0,sizeof(temp));
    while(x != 0)
    {
        mod = x % 10;
        if(temp[mod])
            return 0;
        else
            temp[mod]++;
        x /= 10;
    }
    return 1;
}
int main()
{
    for(i = 1;i < 100001;i++)
    {
        if(fun1(i))
            ans[i] = ans[i-1] + 1;
        else
            ans[i] = ans[i-1];
    }

    scanf("%d",&n);
   while(n--)
    {
        scanf("%d%d",&a,&b);
        printf("%d\n",ans[b] - ans[a-1]);
    }
    return 0;
}

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

时间: 2024-07-29 01:20:12

hdu 5327 Olympiad (多校联赛) ——模拟的相关文章

HDU 5327 Olympiad (多校)

Olympiad Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 631    Accepted Submission(s): 436 Problem Description You are one of the competitors of the Olympiad in numbers. The problem of this yea

HDU 5327(2015多校4)-Olympiad(水题)

题目地址:HDU 5327 题意:beautiful numbers的定义:就是一个数的每一位不能有相同的数字,现在给你一个区间,让你求这区间内有多少个这样的漂亮数. #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algori

hdu 5327 Olympiad

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5327 Olympiad Description You are one of the competitors of the Olympiad in numbers. The problem of this year relates to beatiful numbers. One integer is called beautiful if and only if all of its digita

HDU 5327 Olympiad (水题)

题意:beautiful数字定义为该数字中的十进制形式每一位都不同,给一个区间[L,R],求该区间中有多少个beautiful数字. 思路:数字不大,直接暴力预处理,再统计区间[1,i]有多少个,用cnt[R]-cnt[L-1]即可. 1 #include <bits/stdc++.h> 2 #define INF 0x7f7f7f7f 3 #define pii pair<int,int> 4 #define LL long long 5 using namespace std;

2015 HDU 多校联赛 5317 RGCDQ 筛法求解

2015 HDU 多校联赛 5317 RGCDQ 筛法求解 题目  http://acm.hdu.edu.cn/showproblem.php? pid=5317 本题的数据量非常大,測试样例多.数据量大, 所以必须做预处理.也就是用筛法求出全部的F[x],将全部F[x] 打印出来发现.事实上结果不大,最大的数值是7.所以对于每一个区间询问, 直接暴力求取有多少个 1 2 3 4 5 6 7 就可以,从大到小查找.假设出现2个以上 3-7 的数值,那么最大公约数就是该数字. 假设没有出现两个反复

2015 HDU 多校联赛 5326 Work

2015 HDU 多校联赛 5326 Work 题目: http://acm.hdu.edu.cn/showproblem.php?pid=5326 这题应该是本周二多校赛中,最简单的一道题目了. 解题思路: 就是回根. 用一个数组 root[i] = j 表示 i 的上级是 j , 对于每个输入的关系都做这样的处理.然后遍历每个编号直到root[i] 的结果为0 (因为根没有上级,所以根为0),在往根回退的过程中,用一个数组 cnt[i] 表示经过i这个点的次数. 最后就是遍历 cnt[i],

2014多校第三场1005 || HDU 4891 The Great Pan(模拟)

题目链接 题意 : 给你n行字符串,问你有多少种理解方式.有两大类的理解 (1){A|B|C|D|...}代表着理解方式可以是A,可以是B或C或者D. (2)$blah blah$,在$$这两个符号中间,如果是不连续的空格的那个位置就有2种理解方式,可以理解为没有空格也可以理解为有空格.如果有连续N个空格的位置,那里就有N+1种理解方式. 最后所有的理解方式相乘,数据保证$一定与$匹配,{一定与匹配},不会有任何嵌套,类似{$$}或者{{}}或者${}$这种情况都不会出现,也不会有{$}这种情况

2015 HDU 多校联赛 5363 Key Set

2015 HDU 多校联赛 5363 Key Set 题目: http://acm.hdu.edu.cn/showproblem.php?pid=5363 根据前面给出的例子,得出求解公式 fn = 2^(n-1) - 1, 数据量大,实际就是求幂次方. 可用分治法求解,复杂度O(nlogn) // 分治法求快速幂 #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; const int MO

hdu 5344 (多校联赛) MZL&#39;s xor --- 位运算

here:    首先看一下题吧:题意就是让你把一个序列里所有的(Ai+Aj) 的异或求出来.(1<=i,j<=n) Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (Ai+Aj)(1≤i,j≤n) The xor of an array B is defined as B1 xor B2...xor B