CodeForces 70C Lucky Tickets :找到范围最小的区间使1区间找到的a和2区间找到的b使a*b=rev(a)*rev(b)大于等于w个:技巧(尺取)+map...

转化成a/rev(a)==rev(b)/b这样就容易做了

先判断大区间有没有到w个,然后开两个map进行尺取

x=n1 y=1

如果当前对数>=w x--,否则y++,中间有涉及到两个map的删减以及在满足情况下更新答案

 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<string.h>
 4 #include<algorithm>
 5 #include<map>
 6 using namespace std;
 7 #define LL long long
 8 map<double,LL>mp1,mp2;
 9 LL rev(LL x)
10 {
11   LL ans=0;
12   while (x){
13     ans=ans*10+x%10;
14     x/=10;
15   }
16   return ans;
17 }
18 int main()
19 {
20   LL maxx,maxy,w,cnt,i,tx,ty,ax,ay;
21   double tmp;
22   scanf("%I64d%I64d%I64d",&maxx,&maxy,&w);
23   cnt=0;
24   for (i=1;i<=maxx;i++) mp1[1.0*i/rev(i)]++;
25   for (i=1;i<=maxy;i++) cnt+=mp1[1.0*rev(i)/i];
26   if (cnt<w) {printf("-1\n"); return 0; }
27   tx=maxx; ty=1; 
28   cnt=mp1[1.0]; mp2[1.0]++;
29   ax=maxx; ay=maxy;
30   while (tx>=1&&ty<=maxy)
31   {
32     if (cnt>=w){
33       if (tx*ty<ax*ay) ax=tx,ay=ty;
34       tmp=1.0*tx/rev(tx);
35       cnt-=mp2[tmp]; mp1[tmp]--; tx--;
36     }
37     else{
38       ty++;
39       tmp=1.0*rev(ty)/ty;
40       cnt+=mp1[tmp]; mp2[tmp]++;
41     }
42   }
43   printf("%I64d %I64d\n",ax,ay);
44   return 0;
45 }
View Code

题目链接:http://codeforces.com/problemset/problem/70/C

转载于:https://www.cnblogs.com/xiao-xin/articles/4366869.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值