码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 3872 Nescafe模拟赛 Laser

时间:2014-11-02 12:20:51      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   os   ar   for   sp   

传送门:http://poj.org/problem?id=3872

K-equivalence
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 117   Accepted: 32

Description

Consider a set K of positive integers.
Let p and q be two non-zero decimal digits. Call them K-equivalent if the following condition applies:


For every n bubuko.com,布布扣 K, if you replace one digit p with q or one digit q with p in the decimal notation of n then the resulting number will be an element of K.


For example, when K is the set of integers divisible by 3, the digits 1, 4, and 7 are K-equivalent. Indeed, replacing a 1 with a 4 in the decimal notation of a number never changes its divisibility by 3.
It can be seen that K-equivalence is an equivalence relation (it is reflexive, symmetric and transitive).
You are given a finite set K in form of a union of disjoint finite intervals of positive integers.
Your task is to find the equivalence classes of digits 1 to 9.

Input

The first line contains n, the number of intervals composing the set K (1 <= n <= 10 000).
Each of the next n lines contains two positive integers ai and bi that describe the interval [ai, bi] (i. e. the set of positive integers between ai and bi, inclusive), where 1 <= ai <= bi <= 1018. Also, for i bubuko.com,布布扣 [2..n]: ai >= b(i-1) + 2.

Output

Represent each equivalence class as a concatenation of its elements, in ascending order.
Output all the equivalence classes of digits 1 to 9, one at a line, sorted lexicographically.

Sample Input

Sample Input #1:
1
1 566

Sample Input #2:
1
30 75

Sample Output

Sample Output #1:
1234
5
6
789

Sample Output #2:
12
345
6
7
89

Source

 
bubuko.com,布布扣

POJ 3872 Nescafe模拟赛 Laser

标签:des   style   blog   http   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/kingnight/p/4068762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!