思路:

构造。

实现:

 #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. codevs 1143 纪念品分组

    1143 纪念品分组 2007年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解       题目描述 Description ...

  2. 为Xen虚拟机扩容根文件系统(LVM)

    ===== 为Xen虚拟机扩容根文件系统(LVM) ===== 1. 增加1个4G的映像文件 # dd if=/dev/zero of=data.img bs=4k seek=1024k count= ...

  3. project工期出现小数问题

    进入“选项”,点击“日程”,将默认“开始”.“结束”时间调整为“9点~18点.原为PREJECT 日历 (注意是日历~!!)默认的“8点~17点”,与preject系统默认时间“9点~18点”有差别~ ...

  4. int和Integer及拆箱与装箱

    int和Integer 如果面试官问Integer与int的区别:估计大多数人只会说道两点,Ingeter是int的包装类,int的初值为0,Ingeter的初值为null.但是如果面试官再问一下In ...

  5. POJ-3629

    Card Stacking Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3927   Accepted: 1541 Des ...

  6. TP5之使用layui分页样式

    1.首先你得引入layui文件吧 2.在 application\config.php 中配置,像这样,,, 3.controller中这样写 $data = Db::table($table) -& ...

  7. lightoj1145 【DP优化求方案】

    题意: 有一个k面的骰子,然后问你n个骰子朝上的面数字之和=s的方案: 思路: dp[i][j] 代表 前 i 个骰子组成 j 有多少种方案: 显然 dp[i][j] = dp[i - 1][j - ...

  8. Lightoj1013【DP_LCS】

    题意: 给你两个字符串,让你求一个最短字符串,其中存在给出串的种类: 求这个字符串的长度和种类: 思路: //dp[i,j,k]表示前i个字符,包含s1串前j个字母,包含s2串前k个字符时的方案数. ...

  9. Unity3D研究院之手游开发中所有特殊的文件夹

    这里列举出手游开发中用到了所有特殊文件夹. 1.Editor Editor文件夹可以在根目录下,也可以在子目录里,只要名子叫Editor就可以.比如目录:/xxx/xxx/Editor  和 /Edi ...

  10. IT兄弟连 JavaWeb教程 Servlet会话跟踪 经典面试题

    1.描述Cookie的作用 Cookie是网站保存在浏览器客户端的信息,也就是说保存在访客的机器里的变量,一般随着HTTP头发送到客户端.在Cookie生效之后及失效之前,客户每次发出页面请求的时候, ...