Codeforces Round #524 (Div. 2) Olya and magical square CodeForces - 1080D

题意:

给你 2^n * 2^n 的正方形,让你执行恰好 k 次操作,每一次操作将一个大小不为 1 的正方形剪成四个一模一样的正方形,但是正方形不能被移动。
问:k 次操作后,能否从左下角找一条路径到达右上角(只能横着或竖着走),使得经过的正方形大小相同(包含起点与终点)。
如果可以,输出经过的正方形的边长的以 2 为底的对数。
 

枚举路径上正方形的边长,判断是否合法。

 

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
const int maxn =1e9+5;
const int maxm=10000;
const int mod =1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;

ll fpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=ans*a;
		a=a*a;
		b>>=1;
	}
	return ans;
}
int main()
{
	int t;scanf("%d",&t);
	while(t--)
	{
		ll n,k;scanf("%lld%lld",&n,&k);
		if(n==2&&k==3) printf("NO\n");
        else if(n>31) printf("YES %lld\n",n-1ll);
        else{
            ll a=2;
            int flag=0;
            for(ll i=1;i<=n;i++){
                ll len=n-i;
                ll p=a*a-a*2ll+1ll;
                ll k1=(fpow(4ll,i)-1ll)/3ll;
                ll k2=(fpow(4ll,len)-1ll)/3ll;
                if(k<=k1+k2*p){
                    flag=1;
                    printf("YES %lld\n",len);
                    break;
                }
                a*=2ll;
            }
            if(flag==0) printf("NO\n");
        }
	}
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值