思路:

构造。

实现:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum[];
int main()
{
int cnt = ;
for (int i = ; i <= ; i++)
{
sum[i] = (sum[i - ] + (1ll << cnt));
cnt += ;
}
int t;
ll n, k;
cin >> t;
while (t--)
{
cin >> n >> k;
if (n >= ) { cout << "YES " << n - << endl; continue; }
if (n == )
{
if (k == ) cout << "YES 0" << endl;
else cout << "NO" << endl;
continue;
}
ll minn = , d = , s1 = , s2 = ;
bool flg = false;
int i = n - ;
for ( ; i >= ; i--)
{
minn += (1ll << s1) - ;
s1++;
d += ((1ll << s2) - ) * sum[i];
s2++;
ll maxn = minn + d;
if (k >= minn && k <= maxn) { flg = true; break; }
}
if (flg) cout << "YES " << i << endl;
else cout << "NO" << endl;
}
return ;
}

CF1080D Olya and magical square的更多相关文章

  1. 竞赛题解 - [CF 1080D]Olya and magical square

    Olya and magical square - 竞赛题解 借鉴了一下神犇tly的博客QwQ(还是打一下广告) 终于弄懂了 Codeforces 传送门 『题目』(直接上翻译了) 给一个边长为 \( ...

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

    D. Olya and magical square 题目链接:https://codeforces.com/contest/1080/problem/D 题意: 给出一个边长为2n的正方形,每次可以 ...

  3. codeforces round#524 D - Olya and magical square /// 大概算是数学规律题?

    题目大意: t 个测试用例  (1≤t≤103) 给定n k  (1≤n≤10^9,1≤k≤10^18) 表示有一个边长为2^n的正方形格子 每次操作只能将一个格子切割为左上左下右上右下的四等分格子 ...

  4. Codeforces Round #524 (Div. 2) Solution

    A. Petya and Origami Water. #include <bits/stdc++.h> using namespace std; #define ll long long ...

  5. CodeForces-Round524 A~D

    A. Petya and Origami time limit per test  1 second   memory limit per test  256 megabytes input stan ...

  6. 竞赛题解 - CF Round #524 Div.2

    CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...

  7. codeforce 270C Magical Boxes

    C. Magical Boxes Emuskald is a well-known illusionist. One of his trademark tricks involves a set of ...

  8. [LeetCode] Matchsticks to Square 火柴棍组成正方形

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

  9. [LeetCode] Valid Word Square 验证单词平方

    Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...

随机推荐

  1. BZOJ_1941_[Sdoi2010]Hide and Seek_KDtree

    BZOJ_1941_[Sdoi2010]Hide and Seek_KDtree Description 小猪iPig在PKU刚上完了无聊的猪性代数课,天资聪慧的iPig被这门对他来说无比简单的课弄得 ...

  2. css font-family(字体样式)

    之前因为用的很少,所以没注意,最近做APP混合开发, 给字体一个样式    font-family:" 微软雅黑": 发现在有的手机上有效,但是在有的手机上是无效的, 解决方法:  ...

  3. vue watch 深度监听以及立即监听

    vue watch对象可以监听数据,数据发生变化,处理函数 watch虽可以监听,但只是浅监听,只监听数据第一层或者第二层.比如对于整个对象的监听,需要用到深度监听 vm.$watch('obj',f ...

  4. 利用Dockerfile文件创建带有sshd服务的centos镜像

    利用Dockerfile文件创建带有sshd服务的centos镜像 标签:dockerfile 1.安装docker并启动docker,不在赘述 2.创建使用Dockerfile安装sshd服务的目录 ...

  5. 4-3逻辑非运算符及案例 & 4-4

    创建类 LoginDemo3 这里取反 !(n%3==0) package com.imooc.operator; import java.util.Scanner; public class Log ...

  6. FileWriter 写文件

    FileWriter fw = new FileWriter("C://Users//pc//Desktop//aaa.txt",true); fw.write("201 ...

  7. ssl 证书申请

    https(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的 http 通道,简单讲是 http 的安全版.即 ht ...

  8. E20190414-hm

    ease  n. 安逸; 容易; 轻松,舒适; 不拘束,自在; (for/with ease of) repetition n. 重复,反复; 背诵; 复制品,副本; [乐] 复唱,复奏,重奏; gl ...

  9. CSS小技巧收藏

    居中对齐 很多时候我们需要把一个元素在其父级容器里水平.垂直居中对齐.以下我列出了常用的几种方法: 1.在知道子元素宽度与高度的情况下进行居中,采用位置定位:absolute + margin .pa ...

  10. POJ2406【KMP-next数组】

    关于next的解释原文:点点点 //#include <bits/stdc++.h> #include<cstdio> #include<string.h> #in ...