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 3745 [Coci2015]Norma——序列分治
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3745 如果分治,就能在本层仅算过 mid 的区间了. 可以从中间到左边地遍历左边,给右边两个 ...
- bzoj2330糖果——差分约束
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2330 差分约束,再建立一个源点0,向所有点连边权为1的边,表示每个人都会分到糖果: 答案较大 ...
- CF-805D
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...
- 3-2if条件结构
不同条件做不同的操作.例如满100就减去20 条件结构 package com.imooc.operator; public class ConditionDemo1 { public static ...
- Identity Server 4 原理和实战(完结)_Implicit Flow 实例
oidc-client.js貌似是IdentityServer4的团队开发的 服务端的设置 在服务端新增一个Client 之后需要在angular客户端页建两个页面,对应这两个url才行 登出之后要跳 ...
- python 并发编程之IO 模型
首先说一下 IO 发生时涉及的对象和步骤.以read 为例,会经历两个阶段: 1)等待数据准备 2)将数据从内核拷贝到进程中 二,阻塞Io(blocking IO) 在 Linux中 默认情况下所有 ...
- 7.11实习培训日志-Git Linux
Git git子模块 先在GitHub创建两个空的respository,一个super_project和一个sub_project. 然后在git bash中向库中写入一些文件. 在super_pr ...
- HDU - 2036 改革春风吹满地 叉乘法求多边形面积
改革春风吹满地 “ 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟 ...
- 【WIP】LaTex入门
创建: 2018/06/15 说明: 这鸟东西实在没什么用的感觉,无奈学校报告要用这个写.无奈抽点时间学一下.
- OPENGL_单位长度对应屏幕像素
gluPerspective(GLdouble fovy,GLdouble aspect,GLdouble zNear,GLdouble zFar) fovy:视角,指定视景体的视野的角度,以度数为单 ...