CF1080D Olya and magical square
思路:
构造。
实现:
#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的更多相关文章
- 竞赛题解 - [CF 1080D]Olya and magical square
Olya and magical square - 竞赛题解 借鉴了一下神犇tly的博客QwQ(还是打一下广告) 终于弄懂了 Codeforces 传送门 『题目』(直接上翻译了) 给一个边长为 \( ...
- Codeforces Round #524 (Div. 2) D. Olya and magical square
D. Olya and magical square 题目链接:https://codeforces.com/contest/1080/problem/D 题意: 给出一个边长为2n的正方形,每次可以 ...
- codeforces round#524 D - Olya and magical square /// 大概算是数学规律题?
题目大意: t 个测试用例 (1≤t≤103) 给定n k (1≤n≤10^9,1≤k≤10^18) 表示有一个边长为2^n的正方形格子 每次操作只能将一个格子切割为左上左下右上右下的四等分格子 ...
- Codeforces Round #524 (Div. 2) Solution
A. Petya and Origami Water. #include <bits/stdc++.h> using namespace std; #define ll long long ...
- CodeForces-Round524 A~D
A. Petya and Origami time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 竞赛题解 - CF Round #524 Div.2
CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...
- codeforce 270C Magical Boxes
C. Magical Boxes Emuskald is a well-known illusionist. One of his trademark tricks involves a set of ...
- [LeetCode] Matchsticks to Square 火柴棍组成正方形
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
- [LeetCode] Valid Word Square 验证单词平方
Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...
随机推荐
- bzoj 4827 [Hnoi2017] 礼物 —— FFT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4827 首先,旋转对应,可以把 b 序列扩展成2倍,则 a 序列对应到的还是一段区间: 再把 ...
- PHPstorm相同变量标识
setting-> plugins-> Browse Repositories 输入BrowseWordAtCaret 搜索,安装,然后重启
- SQL repeat()函数
转自:https://www.yiibai.com/sql/sql-repeat-function.html REPEAT(str,count) 返回一个字符串组成的字符串STR重复的次数.如果计数小 ...
- 转 vs2008使用技巧推荐
Visual Studio 2008自带的1000多个 Windows 系统使用的各种图标.光标和动画文件在Visual Studio 2008的安装目录下,\Microsoft Visual Stu ...
- HDOJ-1004(map)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU - 1016 Prime Ring Problem 经典素数环
Prime Ring Problem A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., ...
- Android NDK开发指南(一) Application.mk文件
http://www.cnblogs.com/yaozhongxiao/archive/2012/03/06/2381586.html Application.mk目的是描述在你的应用程序中所需要的模 ...
- c# IOCP.ClientEx2.ReadWrite 加断点遭遇System.AccessViolationException 问题
起因: 如果在Debug模式下,在IOCP.ClientEx2.ReadWrite.cs while (0 > (nPackSize = _ipcp.Pack(arg_n64PackId, ar ...
- 51nod1625(枚举&贪心)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...
- IT兄弟连 JavaWeb教程 JSP中的注释
由于JSP页面由HTML.JSP.Java脚本等组成,所以在其中可以使用多种注释格式 HTML中的注释 HTML语言的注释不会被显示在网页中,但是在浏览器中选择查看网页源代码时,还是能够看到注释的信息 ...