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 ...
随机推荐
- POJ 1258 Agri-Net(Prim算法)
题意:n个农场,求把所有农场连接起来所需要最短的距离. 思路:prim算法 课本代码: //prim算法 #include<iostream> #include<stdio.h> ...
- BEC listen and translation exercise 39
What about jigsaw puzzle design for visually handicapped?给视觉障碍人士设计拼图怎么样? Length is 50cm, and then th ...
- freeMarker(八)——程序开发指南之配置(Configuration)
学习笔记,选自freeMarker中文文档,译自 Email: ddekany at users.sourceforge.net 1.基本内容 配置(configuration)就是 freemark ...
- C/C++面试题总结(1)
首先说一下,这些东西,有的是必须掌握的,有的是面试时你讲出来就是闪光点.自己把握.把握不好的都搞懂.实在不行背下来. 由于时间关系,总结的比较随意,有的就直接贴链接了,希望理解一下. 第一篇:基础(必 ...
- android开发 MyEclipse下测试连接MySQL数据库
1.首先要加载MySQL驱动包. 步骤:右击项目找到build path->configure build path->libraries——>add External JARs添加 ...
- redis多机集群部署文档
redis多机集群部署文档(centos6.2) (要让集群正常工作至少需要3个主节点,在这里我们要创建6个redis节点,其中三个为主节点,三个为从节点,对应的redis节点的ip和端口对应关系如下 ...
- RPG游戏地牢设计的29个要点
转自:http://www.gameres.com/491660.html Troy 是一名 RPG 开发者,以整理了一些自己开发地下城 RPG 的经验,开发者不妨参考一下: 1.地下城应该有个地方无 ...
- Python-Redis的发布与订阅
封装的redis_config # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import redis class Redi ...
- C#读写.ini文件
转载来源: http://blog.csdn.net/source0573/article/details/49668079 https://www.cnblogs.com/wang726zq/arc ...
- sql server 2008 开启1433端口,开启远程连接
通常情况下只需要设置两处