Codeforces Round #524 (Div. 2) D(思维,构造)
#include<bits/stdc++.h>
using namespace std;
long long dp[107];
int main(){
int cnt=1;
dp[1]=1;
for(int i=2;i<=1e9;i*=2){
dp[++cnt]=dp[cnt-1]*4+1;//记录长度为2^cnt的正方形最多能被切割的次数
}
//for(int i=1;dp[i]!=0;i++)
//printf("%lld\n",dp[i]);//此处是为什么n>=32就可以稳切割的原因,超出了题目的极限数据
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++){
int a;
long long b;
scanf("%d%lld",&a,&b);
int tmp=a;
if(a>=32){
printf("YES %d\n",a-1);//切一次剩下切右下角就行,不会对路径产生影响
continue;
}
long long next=1;
long long sum=0;
long long extra=0;
while(a){
sum+=next;//记录已经切割的次数
next=next*2+1;//计算即将切割的次数
a--;//每切一次就--
extra+=dp[a]*(next-2);//根据画图得到的路径之外的切割次数
if(b<sum+next)//此时切这次就搞定,不用继续缩小a了
break;
}
if(b<=extra+sum)//如果b太大说明这个次数是切不出来的
printf("YES %d\n",a);
else
printf("NO\n");
}
return 0;
}
Codeforces Round #524 (Div. 2) D(思维,构造)的更多相关文章
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends(思维+计算几何?)
传送门 https://www.cnblogs.com/violet-acmer/p/10146350.html 题意: 有一块 n*m 的棋盘,初始,黑白块相间排列,且左下角为白块. 给出两个区间[ ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #542(Div. 2) CDE 思维场
C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...
- Codeforces Round #339 (Div. 1) C. Necklace 构造题
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...
- 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...
- Codeforces Round #181 (Div. 2) A. Array 构造
A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n ...
- Codeforces Round #306 (Div. 2) ABCDE(构造)
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...
- Codeforces Round #395 (Div. 2)(A.思维,B,水)
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...
随机推荐
- 如何设置minSdkVersion和targetSdkVersion
转http://www.07net01.com/2015/07/878098.html minSdkversion和targetSdkVersion相信很多人都不太理解,我在网上也看了许多关于这两者区 ...
- 仿联想商城laravel实战---1、仿联想商城需求和数据库设计(lavarel如何搭建项目)
仿联想商城laravel实战---1.仿联想商城需求和数据库设计(lavarel如何搭建项目) 一.总结 一句话总结: composer引入lavarel.配置域名.配置apache 1.项目名 le ...
- hdu 2955 Robberies(01背包)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- QListWidget拖放
setDragEnabled() 允许拖 setAcceptDrops()允许放 setDragDropMode(QAbstractItemView.DragDrop)设置拖拽模式 setSelect ...
- 1_Command 游戏开发命令模式
A dead simple implementation looks like: ``` // simple void InputHandler::handleInput() { if (isPres ...
- codeforces 29D Ant on the Tree (dfs,tree,最近公共祖先)
D. Ant on the Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Mybatis学习--Java API
学习笔记,选自Mybatis官方中文文档:http://www.mybatis.org/mybatis-3/zh/java-api.html#directoryStructure 既然你已经知道如何配 ...
- 【LeetCode】033. Search in Rotated Sorted Array
题目: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. ( ...
- poj 1208 Web Navigation(堆栈操作)
一.Description Standard web browsers contain features to move backward and forward among the pages re ...
- Java应用中使用ShutdownHook友好地清理现场、退出JVM的2种方法
Runtime.getRuntime().addShutdownHook(shutdownHook); 这个方法的含义说明: 这个方法的意思就是在jvm中增加一个关闭的钩子,当jv ...