bzoj1853 "SCOI2010" lucky numbers

Source: Internet
Author: User

1853: [Scoi2010] Lucky number time limit: 2 Sec Memory Limit: MB
Submit: 1837 Solved: 673
[Submit] [Status] [Discuss] Description in China, many people think of 6 and 8 as lucky numbers! LXHGWW also thought, so he defined his "lucky number" is a decimal representation of only the numbers 6 and 8 of those numbers, such as 68,666,888 are "lucky number"! But this "lucky number" is always too small, for example, in the [1,100] range of only 6 (6,8,66,68,86,88), so he defined a "approximate lucky number." LXHGWW rules that the "lucky number" multiples are "approximate lucky numbers", of course, any "lucky number" is also "approximate lucky number", such as 12, 16,666 are "approximate lucky number." Now LXHGWW want to know the number of "approximate lucky numbers" within a closed interval [a, b]. Input data is a row, including 2 numbers A and boutput output data is a row, including 1 numbers, indicating the number of "approximate lucky numbers" in the closed interval [a, b], sample input"Sample Input 1"
1 10
"Sample Input 2"
1234 4321
Sample Output"Sample Output 1"
2
"Sample Output 2"
809
HINT

"Data Range"
For 30% data, guarantee 1 < =a < =b < =1000000
For 100% data, guarantee 1 < =a < =b < =10000000000

Source

Day1




principle of tolerance and repulsion + Search Pruning

Method with bzoj2393, but this problem data range is slightly large, so Dfs time to go from the forward DFS, so pruning optimization more obvious.




#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long Long#define maxn 3005using namespace Std;int cnt,tot;ll l,r,ans,a[maxn],b[maxn];bool tag[maxn];void Find (l L x) {if (x>r) return;a[++cnt]=x;find (x*10+6); find (x*10+8);} ll GCD (ll A,ll b) {return!b?a:gcd (b,a%b);} void Dfs (int x,int flag,ll t) {if (!x) {if (t!=1) ans+= (r/t-(L-1)/t) *flag;return;} DFS (X-1,FLAG,T); ll TMP=GCD (t,a[x]); if (double) t*a[x]/tmp> (double) r) Return;dfs (X-1,-flag,t/tmp*a[x]);} int main () {scanf ("%lld%lld", &l,&r); find (6); Find (8); sort (a+1,a+cnt+1); F (i,1,cnt) f (j,1,i-1) if (a[i]%a[j]==0) {tag[i]=1;break;} for (int i=1;a[i];i++) if (!tag[i]) B[++tot]=a[i];cnt=tot; F (i,1,cnt) a[i]=b[i];d FS (cnt,-1,1);//To search from large to small, otherwise tle printf ("%lld\n", ans);}


bzoj1853 "SCOI2010" lucky numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.