UVA 4855 Hyper Box 斐波那契
来源:互联网 发布:网络审查 论文 编辑:程序博客网 时间:2024/06/15 17:02
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2856
比赛的时候和陈看了好长时间才看明白题意,和吴讨论做了出来,其实吴确实聪明,脑袋瓜子比较灵活
题意:有一个N维的空间,给你各维的长度,有一些n维的砖块,把空间填满,砖块不能交叉,空间不能一部分为空;求最少用的砖块
砖块各维都必须为斐波那契长度
思路:
空间各维分解,若是斐波那契数,不处理,若不是,求出最少用几个斐波那契数组成,最后相 乘就是结果
难点在一个数最少由几个斐波那契数组成;
求出2.1亿内的所有斐波那契数,map映射为1,数组最少46;
初始为x,其实每次取不大于它的斐波那契数,并减去,更新x,重复上述;
代码:
#include<iostream>#include<map>#include<cstdio>#include<cstring>using namespace std;long long a[20];long long b[49];int find(long long x){ bool str=true; int num=0; while(str) { int i=45; while(i!=-1) { i--; if(b[i]<=x) { x-=b[i]; num++; break; } } if(x==0) break; } //cout<<"num== "<<num<<endl; return num;}int main(){ int t,i,j; b[0]=1; b[1]=2; map<long long ,int> s; s[1]++; s[2]++; for(i=2;i<47;i++) { b[i]=b[i-1]+b[i-2]; s[b[i]]++; } //cout<<"b[45]== "<<b[45]<<endl; // cout<<find(4)<<endl; //cout<<find(6)<<endl; while(cin>>t) { int p=1; while(t--) { int n; cin>>n; int i,j; long long k=1; for(i=0;i<n;i++) { cin>>a[i]; if(s[a[i]]==0) { k*=find(a[i]); } } cout<<"Case "<<p++<<": "<<k<<endl; } }}
0 0
- UVA 4855 Hyper Box 斐波那契
- UVA 4855 Hyper Box
- UVALive 4855 Hyper Box
- UVALive 4855 Hyper Box
- UVA 10183 斐波那契数列
- UVa 11069 A Graph Problem (斐波那契)
- UVa 10334 Ray Through Glasses (斐波那契&高精度)
- UVa 11069 A Graph Problem (斐波那契)
- uva 763 - Fibinary Numbers(斐波那契数)
- UVA 10334 - Ray Through Glasses(高精度斐波那契)
- UVA 763 - Fibinary Numbers(高精度斐波那契)
- UVa 10236 The Fibonacci Primes (斐波那契素数)
- UVA 11885 - Number of Battlefields(斐波那契)
- uva 11582 lrj-P316 斐波那契大数
- Box UVA
- Uva-11488-Hyper Prefix Sets
- UVa:11488 Hyper Prefix Sets
- UVA - 11488 Hyper Prefix Sets
- 839 合并
- Flume-ng 自定义sink实现和属性注入
- Linux脚本牛刀小试
- unity3d编辑器界面扩展,编辑状态下显示选择对象的所有脚本组件代码内容
- 黑马程序员——001——初识Java
- UVA 4855 Hyper Box 斐波那契
- 第二天
- 要认清自己的位置——在我断开之前
- 【ODPS】UDF基础
- linux版本FTP下载
- iOS Provisioning Profile(Certificate)与Code Signing详解
- windbg 查看参数应用方法
- Linux 设备文件分类
- android相关面试题