hdu 5327 Olympiad (多校联赛) ——模拟
来源:互联网 发布:淘宝千纸鹤什么档次 编辑:程序博客网 时间:2024/06/10 12:49
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 numbersa and b , as described in the statement. It is guaranteed that 1≤a≤b≤100000 .
For each test case, there are two numbers
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:busing 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;}
0 0
- hdu 5327 Olympiad (多校联赛) ——模拟
- 2016HDU多校联赛-HDU-Joint Stacks(模拟)
- 2015 多校联赛 ——HDU5319(模拟)
- 2015 多校联赛 ——HDU5373(模拟)
- 2015 多校联赛 ——HDU5402(模拟)
- HDU 4611 (2013多校联赛1001 数学+模拟)
- hdu 4671(多校联赛7--水模拟)
- HDU 5327 Olympiad
- HDU 5327 Olympiad
- HDU--5327 Olympiad
- HDU 5327 Olympiad
- hdu 5327 Olympiad
- HDU 5327 Olympiad
- HDU 5327 Olympiad
- hdu 5327 Olympiad
- hdu 5327 Olympiad
- HDU 5327 Olympiad
- HDU 5327 Olympiad
- c#常用的数据转换方法以及其他方法
- 日经社説 20150806 被爆70年に改めて核のない世界を誓う
- java中静态代码块的用法 static用法详解
- zabbix登录错误
- Hdu 5347 MZL's chemistry 2015ACM多校对抗赛第五场
- hdu 5327 Olympiad (多校联赛) ——模拟
- cleaning selected projects has encountered a problem errors occurred during build
- HDU 1010 && ZOJ 2110--Tempter of the Bone【DFS && 奇偶剪枝】
- hdu 1010 dfs+剪枝
- MySQL--用户管理和权限
- 线程安全的单例模式
- KeyPress 和KeyDown 、KeyPress的区别
- MFC窗口变化消息( OnSize、OnSizing和OnGetMinMaxInfo)
- ExtJs中组件最好少使用ID属性(推荐更多使用Name属性)