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 ...
随机推荐
- HDU2586(LCA应用:在带权树中求任意两点之间的距离)
How far away ? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- CF-799A
A. Carrot Cakes time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 怎样让自定义Cell的图片和文本自适应高度
Let's do it! 首先创建一个Model类 包括一个图片名称属性 还有文字内容属性 #import <Foundation/Foundation.h> @interface Mod ...
- 简单介绍Git两种拉取代码的方式
first: 1.通过git clone 命令克隆git库中的项目 注意:通过 git clone方式克隆的代码会在服务器上自动建一个与git库名相同的文件夹,所以有两种思路,第一种就是直接在wwwr ...
- 51nod1212【最小生成树kruskal算法】
思路: 利用破圈法. #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=1e3 ...
- 删除node_modul模块
npm安装rimraf ,npm版本号要是低于5.x.x 具体不记得了,不然就安装不了这个工具 npm install rimraf -g 然后: rimraf node_modules 在这里学到的 ...
- android摄像头获取图像——第二弹
使用android内的Camera对象 (1)Camera是控制着摄像头的api,拥有一系列控制摄像头的上层方法:camera类能够调用底层的摄像头接口,完成启动摄像头.预 览摄像头图像.拍照等功能: ...
- [Xcode 实际操作]九、实用进阶-(18)图像人脸识别:对图片中的人像进行面部检测
目录:[Swift]Xcode实际操作 本文将演示对图片中的人像,进行面部检测. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit //导入 ...
- 多线程中join()
这个鬼东西百度了好久没弄明白,大佬们代码一粘贴好了完事,借助官方api终于是理解了,当然如果有问题欢迎大家用键盘来羞辱我. 首先 join有什么用? 他是用来确定线程何时结束的 , Thread ...
- AVAudioPlayer 如何在页面呈现之后按需初始化
在页面中按需初始化 AVAudioPlayer 很多时候我们需要根据页面上内容的情况创建 AVAudioPlayer 对象,已达到降低无谓资源占用等目的.下面我们来看一段代码看起来正确的代码: ove ...