找规律 SGU 126 Boxes
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126
/*
找规律,智商不够,看了题解
详细解释:http://blog.csdn.net/ahfywff/article/details/7432524
*/
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f; int GCD(int a, int b)
{
return b ? GCD (b, a % b) : a;
} int main(void) //SGU 126 Boxes
{
//freopen ("C.in", "r", stdin); int n, m; while (~scanf ("%d%d", &n, &m))
{
int ans;
if (n == || m == )
{
ans = ;
}
else
{
if (n < m) swap (n, m);
int k = GCD (n, m);
int x = n / k; int y = m / k;
if ((x+y) & )
{
ans = -;
}
else
{
int tmp = x + y;
ans = ;
while (tmp > )
{
if (tmp % == )
{
tmp /= ;
ans++;
}
else
{
ans = -; break;
}
}
}
} printf ("%d\n", ans);
} return ;
}
找规律 SGU 126 Boxes的更多相关文章
- sgu 126 Boxes
题意:较大的容量减较小的容量,较小的容量翻倍.问操作几回其中一个空. 开始用set判重,重复就不可行.不过状态最多有2e18种.不仅爆内存,还超时.然后找规律.发现只有比例为1:1,1:3,1:7,3 ...
- SGU 126 Boxes(模拟题|二进制)
Translate:Sgu/126 126. 盒子 time limit per test: 0.5 sec. memory limit per test: 4096 KB 有两个盒子. 第一个盒子里 ...
- SGU 126. Boxes --- 模拟
<传送门> 126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two b ...
- 找规律 SGU 107 987654321 problem
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=107 /* 题意:n位数的平方的后面几位为987654321的个数 尼玛,我看描述这 ...
- SGU 107 987654321 problem【找规律】
题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=107 题意: 平方后几位为987654321的n位数有多少个 分析: 虽然说是水题 ...
- SGU 169 Numbers (找规律)
题意:中文题,直接忽略... 析:先说说我的思路,我一看这个题第一感觉就是要找规律,要是挨着算,猴年马月都跑不完,更何况时间限制是0.25s,怎么找规律呢,我算了一下前10位,分别是8,1,1,3,1 ...
- 找规律 ZOJ3498 Javabeans
Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. ...
- ZOJ 3498 Javabeans(找规律)
Javabeans Time Limit: 2 Seconds Memory Limit: 65536 KB Javabeans are delicious. Javaman likes t ...
- Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律
题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...
随机推荐
- Hibernate执行原生SQL返回List<Map>类型结果集
我是学java出身的,web是我主要一块: 在做项目的时候最让人别扭的就是hibernate查询大都是查询出List<T>(T指代对应实体类)类型 如果这时候我用的联合查询,那么返回都就是 ...
- STL库函数 持续更新
*容器 (1)顺序容器 vector[顺序表直接访问] depue[前后直接访问] list[双向链表] vector 检索(用operator[ ])速度快 .push_back 在数组的最后添加一 ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- python 的编码问题
老是碰到这个问题,决定好好给整理一番思路. 翻阅资料和实践证明,以下论述为真理: 字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将 ...
- BZOJ 1058
服气!我果然就是个傻逼. 傻兮兮地感觉两个数之间的差距无需删除一些答案,妈个鸡就只加入了一些新的答案忘记了去掉无效的答案.我果然是傻逼,经验不足脑子笨... 这么水的题...不说了,说多了都是泪. 自 ...
- python中import和from...import...的区别
python中import和from...import...的区别: 只用import时,如import xx,引入的xx是模块名,而不是模块内具体的类.函数.变量等成员,使用该模块的成员时需写成xx ...
- Resumable uploads over HTTP. Protocol specification
Valery Kholodkov <valery@grid.net.ru>, 2010 1. Introduction This document describes applicatio ...
- 【Python】python 普通继承方式和super继承方式
Python中对象方法的定义很怪异,第一个参数一般都命名为self(相当于其它语言的this),用于传递对象本身,而在调用的时候则不必显式传递,系统会自动传递.举一个很常见的例子:>>&g ...
- 【Hadoop】HIVE 小结概览
一.HIVE概览小结 二.HIVE安装 Hive只在一个节点上安装即可 .上传tar包 .解压 tar -zxvf hive-.tar.gz -C /cloud/ .配置mysql metastore ...
- cocos2d c++ 代码规范(译文)
原文在http://cocos2d-x.org/projects/cocos2d-x/wiki/Cocos2d_c++_coding_style,我觉得这个规范非常全面,写的非常好,我只捡一些我认为比 ...