HDU5327(基础题)
来源:互联网 发布:淘宝大码孕妇装排行 编辑:程序博客网 时间:2024/06/07 18:32
题目:
G - Olympiad
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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
Input
The first line of the input is a single integer
For each test case, there are two numbers
Output
For each testcase, print one line indicating the answer.
Sample Input
2
1 10
1 1000
Sample Output
10
738
题意:
找出所给范围的漂亮数(每个数位上的数互不相同)
思路:
数据范围会很大,暴力的话会重复多次求解,那么打表,表中每个arr[i]记录前i个数中有多少个漂亮数,并且判断i是不是漂亮数,一直累加,求解时区间相减,注意还有判断区间起始值a是否为漂亮数,并且加上。
代码:
#include <iostream>#include <cstring>const int maxn = 100000+10;int arr[maxn];int node[10];using namespace std;int check(int a){ memset(node, 0, sizeof(node)); while(a){ node[a%10]++; if(node[a%10]>1) return 0; a = a/10; } return 1;}void printList(){ memset(arr, 0, sizeof(arr)); for(int i=0; i<=100010; i++){ if(check(i)){ //cout<<"i is:"<<i<<endl; arr[i] = arr[i-1] + 1;} else arr[i] = arr[i-1]; }}int main(){ int n, a, b; while(cin>>n){ printList(); for(int i=0; i<n; i++){ cin>>a>>b; cout<<arr[b]-arr[a]+check(a)<<endl; } } return 0;}
check()函数判断是否为漂亮数,printList()函数打表,其中check()函数返回值设为int,返回值为1或0,可以在最后区间相减的时候判断区间开始的数是否为漂亮数。
- HDU5327(基础题)
- HDU5327
- hdu5327 Olympiad(简单题:打表+模拟)
- hdu5327 水题
- HDU5327 Olympiad
- HDU5327(数位DP)
- 解题报告 之 HDU5327 Olympiad
- 数组前缀和 & 计数排序 uva10474 hdu5327
- [模拟] 多校联合第四场 HDU5327 Olympad
- 2015年多校联合训练第四场(Olympiad)hdu5327
- hdu5327 Olympiad(数组前缀和+set判重)
- 基础题
- 基础题
- 基础题
- 基础题
- 面试基础题--J2SE基础
- Java基础-day01-基础题
- poj2524(并查集基础基础基础题)
- 2015.8.26小记
- ubuntu目录结构
- CentOS 7 安装出现 /dev/root does not exits 导致无法安装的问题
- socket编程总结(一)getaddrinfo()函数详解
- 插入U盘,自动复制数据库信息和相关文件
- HDU5327(基础题)
- jmeter使用--1、window7环境下jmeter安装配置
- Junit4测试出现initializationerror错误
- 【ReactNative】react native 中es6语法解析
- 编程的智慧
- Android Studio系列教程三--快捷键
- IOS Dev Intro - Message Transfer Mechanism
- Android Studio系列教程四--Gradle基础
- 【打CF,学算法——四星级】CodeForces 86D Powerful array (莫队算法)