Skip to main content
  1. Posts/

hdu 5327 Olympiad (2015 多校 #4 )

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://acm.hdu.edu.cn/showproblem.php?pid=5327 题意:问给出的区间[a,b]中有多少个美丽数,美丽数的定义是所有数字都不相同,如123是,100不是,333也不是。 思路:预处理1..100000的美丽数,可以把每个数字拆开放在set里,比较set的size和位数来实现。 然后用前缀和。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月19日 星期五 13时25分36秒
 4File Name :code/hdu/5327.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=1E5+7;
34int a,b;
35int sum[N];
36int p[N];
37
38bool ok ( int x)
39{
40    set<int>se;
41    se.clear();
42    int cnt  = 0 ;
43    while (x)
44    {
45	int tmp = x % 10;
46	se.insert(tmp);
47	x =  x/10;
48	cnt++;
49    }
50    if (se.size()==cnt) return true;
51    return false;
52}
53int main()
54{
55	#ifndef  ONLINE_JUDGE
56	freopen("code/in.txt","r",stdin);
57  #endif
58
59	for ( int i = 1 ; i <= 100000 ; i ++)
60	{
61	    if (ok(i))
62		p[i] = 1;
63	    else p[i]  = 0;
64	}
65
66	sum[0] = 0 ;
67	for ( int i = 1 ;i  <= 100000 ; i++)
68	{
69	    sum[i] = sum[i-1] + p[i];
70	}
71
72	int T;
73	cin>>T;
74	while (T--)
75	{
76	    scanf("%d %d",&a,&b);
77	    printf("%d\n",sum[b]-sum[a-1]);
78	}
79
80
81
82  #ifndef ONLINE_JUDGE
83  fclose(stdin);
84  #endif
85    return 0;
86}

Related

cf 611 A||codeforces goodbye 2015 C. New Year and Domino

·1 min
http://codeforces.com/contest/611/problem/C 题意:给出一个n*m的地图,.表示可以空,#表示墙。一个东西需要占两个相邻的格子,问给定一个矩形,放一个东西的方案数。 思路:q很大。。应该是先预处理出来直接调用答案。。。计数问题累加性。。应该是前缀和之类。。需要做的就是怎么标记。。我的做法是竖着放和横着放的个数分开来存。从左往右从上往下,每次标记到后一个点。然后二维的前缀和。然后每次询问的时候,去掉最上边和最左边两条边界上对应的多加的点。

codeforces 18 C. Stripe

·1 min
http://codeforces.com/contest/18/problem/C 题意:将一个序列分成两个非空的部分,保证和相等,问有多少种方法。 思路:做过一个三部分的。。。两部分直接一个前缀和就好了把。。。有一个需要注意的是。。判断负数是否是奇数的时候需要加个绝对值。。。

codeforces #336 div 2 B. Hamming Distance Sum

·1 min
http://codeforces.com/contest/608/problem/B 题意:给定两个字符串a,b,问b中的每个连续的长度为a的子串与a的哈密顿距离的和是多少。哈密顿距离是对应位置的字符的差的绝对值的和。由于是01串,也就是字符不同的位置数。 思路:类似前缀和。0和1分别搞。注意开long long