#include<bits/stdc++.h>
using namespace std;
long long dp[107];
int main(){
    int cnt=1;
    dp[1]=1;
    for(int i=2;i<=1e9;i*=2){
        dp[++cnt]=dp[cnt-1]*4+1;//记录长度为2^cnt的正方形最多能被切割的次数
    }
    //for(int i=1;dp[i]!=0;i++)
        //printf("%lld\n",dp[i]);//此处是为什么n>=32就可以稳切割的原因,超出了题目的极限数据
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++){
        int a;
        long long b;
        scanf("%d%lld",&a,&b);
        int tmp=a;
        if(a>=32){
            printf("YES %d\n",a-1);//切一次剩下切右下角就行,不会对路径产生影响
            continue;
        }
        long long next=1;
        long long sum=0;
        long long extra=0;
        while(a){
            sum+=next;//记录已经切割的次数
            next=next*2+1;//计算即将切割的次数
            a--;//每切一次就--
            extra+=dp[a]*(next-2);//根据画图得到的路径之外的切割次数
            if(b<sum+next)//此时切这次就搞定,不用继续缩小a了
                break;
        }
        if(b<=extra+sum)//如果b太大说明这个次数是切不出来的
            printf("YES %d\n",a);
        else
            printf("NO\n");
    }
    return 0;
}

Codeforces Round #524 (Div. 2) D(思维,构造)的更多相关文章

  1. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  2. Codeforces Round #524 (Div. 2) C. Masha and two friends(思维+计算几何?)

    传送门 https://www.cnblogs.com/violet-acmer/p/10146350.html 题意: 有一块 n*m 的棋盘,初始,黑白块相间排列,且左下角为白块. 给出两个区间[ ...

  3. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  4. Codeforces Round #542(Div. 2) CDE 思维场

    C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...

  5. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  6. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

  7. Codeforces Round #181 (Div. 2) A. Array 构造

    A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n ...

  8. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  9. Codeforces Round #395 (Div. 2)(A.思维,B,水)

    A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...

随机推荐

  1. Django-02

    知识预览 Ajax前戏:json Ajax简介 jquery实现的ajax JS实现的ajax 回到顶部 Ajax前戏:json 什么是json? 定义: JSON(JavaScript Object ...

  2. 七 Django框架,models.py模块,数据库操作——F和Q()运算符:|或者、&并且——queryset对象序列化

    F()可以将数据库里的数字类型的数据,转换为可以数字类型 首先要导入 from django.db.models import F from django.shortcuts import rende ...

  3. Unity3D连接WCF

    Unity3D连接WCF: 一.最简单的案例 1.VS2015中: (1)建立WCF应用服务程序ForUnity: (2)将自动生成的IService1.cs与Service1.svc删除:   (3 ...

  4. vscode 小笔记

    用户设置: { "git.ignoreMissingGitWarning": true, "workbench.statusBar.feedback.visible&qu ...

  5. OpenCV——黑白调整

    参考算法: 闲人阿发伯的博客 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUD ...

  6. Convolutional Neural Networks for Visual Recognition 7

    Two Simple Examples softmax classifier 后,我们介绍两个简单的例子,一个是线性分类器,一个是神经网络.由于网上的讲义给出的都是代码,我们这里用公式来进行推导.首先 ...

  7. 利用perlin noise 生成 wood texture

    %%% Perlin Noise %%% Wood_texture clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image P ...

  8. ACM学习历程—ZOJ 3777 Problem Arrangement(递推 && 状压)

    Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...

  9. 洛谷 P2777 [AHOI2016初中组]自行车比赛

    题目描述 小雪非常关注自行车比赛,尤其是环滨湖自行车赛.一年一度的环滨湖自行车赛,需要选手们连续比赛数日,最终按照累计得分决出冠军.今年一共有 N 位参赛选手.每一天的比赛总会决出当日的排名,第一名的 ...

  10. binlog之二:怎么样安全删除mysql下的binlog日志

    删除binlog方法 第一种方法: mysql> show binary logs; 查看mysql bin-log日志,除了这个以外的,其它都可以使用删除.mysql> purge bi ...