WHU 2013 Summer Contest #8 B Dividing a Chocolate
来源:互联网 发布:矩阵相似行列式相等吗 编辑:程序博客网 时间:2024/05/22 04:25
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26275#problem/B
Crawling in process...Crawling failedTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
The boy and Karlsson are dividing a chocolate that the boy's parents have presented him for his birthday. A chocolate is a rectangle that consists ofm × n chocolate squares, separated from each other by cutlines.
Of course, Karlsson does the dividing. First Karlsson divides the chocolate into two rectangular pieces, breaking it along some cutline. Since Karlsson wants to divide chocolate fairly, he would not be satisfied if the two pieces have different sizes. In this case he cuts away the piece equal to the smaller piece out of the larger piece, and eats it. If the pieces are still not equal, he does so again, and so on. After the pieces are finally equal, Karlsson eats one of the pieces, and the boy eats another.
Karlsson wants to make an initial cut in such a way that he would eat as much chocolate as possible. However, the boy knows that Karlsson likes chocolate very much, and he watches for the process closely. Karlsson must be very careful not to offend the boy. So he must not successively cut away and eat chocolate from the same piece --- this would seem too suspicious to the boy.
Help Karlsson to find out how much chocolate he can eat.
Input
There are mutiple cases in the input file.
Each case contains m and n (1 <= m, n <= 109 ).
There is an empty line after each case.
Output
Output one integer number --- how many chocolate squares Karlsson can eat. If Karlsson cannot divide chocolate using his method, output0 instead.
There should be am empty line after each case.Sample Input
6 5
Sample Output
24In the example Karlsson must initially break a chocolate into pieces of sizes 3 × 6 and 2 × 6 . After that he can eat all chocolate but the boy's piece that would finally be1 × 6 . Karlsson cannot, for example, cut a chocolate initially into pieces of sizes5 × 5 and1 × 5 --- after doing so, he would have to successively cut a piece away from the first one several times, that would offend the boy.
思路就是从斐波那契数列出发,推理的过程如图:
最后 a*b a*b
2*a*b a*b
3*a*b 2*a*b
5*a*b 3*a*b....依次类推,要使得a*b最小必须使所取的斐波那契数最大,long long 以内的斐波那契数总共有91个,因此可以使用91以内的斐波那契数来进行计算。
#include<iostream>#include<stdio.h>using namespace std;long long fib[92];int main(){ fib[0]=1;fib[1]=1; for(int i=2;i<92;i++) { fib[i]=fib[i-1]+fib[i-2]; cout<<fib[i]<<endl; } long long m,n; while(cin>>m>>n) { long long maxf=0; for(int i=59;i>=0;i--) { if(m%fib[i]==0||n%fib[i]==0) { maxf=fib[i];break; } } cout<<n*m-n*m/maxf<<endl; cout<<endl; } return 0;}
- WHU 2013 Summer Contest #8 B Dividing a Chocolate
- WHU 2013 Summer random contest #2 F题
- WHU 2013 Summer Team Contest #13 - CERC 2010 [xioumu]
- WHU 2013 Summer Team Contest #14 - NEERC 2009 subregional [xioumu]
- WHU 2013 Summer Team Contest #15 - SWERC 2011[xioumu]
- WHU 2013 Summer Team Contest #16 - 2008 beijing[xioumu]
- WHU 2013 Summer Team Contest #17 - NWERC 2009
- ZOJ2705 Dividing a Chocolate
- zoj 2705 Dividing a Chocolate 斐波那契数列应用 (8-B)
- WHU 2013 Summer Contest #12 - 2013 ACM-ICPC通化邀请赛 [xioumu]
- WHU 2013 Summer Team Contest #18 - 2013 Multi University 4 [xioumu]
- zoj 2705 Dividing a Chocolate
- SDKD Summer Team Contest B
- SDKD Summer Team Contest A
- SDKD 2016 Summer Single Contest #01.B
- SDKD 2016 Summer Single Contest #02.B
- SDKD 2016 Summer Single Contest #03.B
- SDKD 2016 Summer Single Contest #12 .B
- Linux学习方法
- 玩转Kinetis之教你将K60主频超到200MHz以上
- SqlHelper 类实现详细信息
- Linux系统结构及其操作界面
- 整形数组/字符数组/字符串的区别
- WHU 2013 Summer Contest #8 B Dividing a Chocolate
- 嵌入式C语言编程中Inline函数的应用
- 驱动摸索[2]:安装EasySYS
- 用WinHex查看SD卡FAT32文件系统结构
- mvc+mysql实现的分页技术
- C#学习笔记04:函数
- 最大的子序列和问题
- Agilent VSA 89600安装及注册过程
- spoj 227