UVA 4855 Hyper Box
You live in the universe X where all the
physical laws and constants are different
from ours. For example all of their objects
are N-dimensional. The living beings
of the universe X want to build an
N-dimensional monument. We can consider
this N dimensional monument as an
N-dimensional hyper-box, which can be
divided into some N dimensional hypercells.
The length of each of the sides of
a hyper-cell is one. They will use some
N-dimensional bricks (or hyper-bricks) to
build this monument. But the length of
each of the N sides of a brick cannot be
anything other than fibonacci numbers. A
fibonacci sequence is given below:
1, 2, 3, 5, 8, 13, 21, . . .
As you can see each value starting from 3 is the sum of previous 2 values. So for N = 3 they can
use bricks of sizes (2,5,3), (5,2,2) etc. but they cannot use bricks of size (1,2,4) because the length 4
is not a fibonacci number. Now given the length of each of the dimension of the monument determine
the minimum number of hyper-bricks required to build the monument. No two hyper-bricks should
intersect with each other or should not go out of the hyper-box region of the monument. Also none of
the hyper-cells of the monument should be empty.
Input
First line of the input file is an integer T (1 ≤ T ≤ 100) which denotes the number of test cases. Each
test case starts with a line containing N (1 ≤ N ≤ 15) that denotes the dimension of the monument
and the bricks. Next line contains N integers the length in each dimension. Each of these integers will
be between 1 and 2000000000 inclusive.
Output
For each test case output contains a line in the format Case x: M where x is the case number (starting
from 1) and M is the minimum number of hyper-bricks required to build the monument.
Sample Input
2
2
4 4
3
5 7 8
Sample Output
Case 1: 4
Case 2: 2
题意: 给一个n维空间的的物体,给出每一维的长度。问有最少几个比它体积小的物体组成它,要求这些物体的边必须是斐波那契数列
里边的数。
思路: 假设边长是斐波那契数就无论他,假设不是,比这个边长小的最大的斐波数减起,一直减到0。减了几个斐波数。也就是这条边
最少分解成几个斐波数,最后每一维相乘即为结果。
#include<stdio.h>
#include<string.h>
int fb[60];
int main(){
int t,ok,n,cas=1;
int a[20];
fb[1]=1; fb[2]=2;
for(int i=3;i<55;i++)
fb[i]=fb[i-1]+fb[i-2];
scanf("%d",&t);
while(t--){
int cnt=0;
long long sum=1;//结果不用long long 会错
scanf("%d",&n);
for(int i=0;i<n;++i)
scanf("%d",&a[i]);
for(int i=0;i<n;++i){
cnt=ok=0; int k;
for(int j=1;j<55;j++){
if(a[i]==fb[j]){
ok=2;
break;
}
if(a[i]<fb[j]){
ok=1;
k=j;
break;
}
}
if(ok==1){
int x=a[i];
while(x){
while(fb[k]>x)
k--;
x-=fb[k];
cnt++;
}
}
if(ok!=2)//ok==2时证明这条边是斐波数
sum*=cnt;//注意是相乘。,
}
printf("Case %d: %lld\n",cas++,sum);
}
return 0;
}
UVA 4855 Hyper Box的更多相关文章
- UVA 11488 Hyper Prefix Sets (Trie)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11488 Hyper Prefix Sets (字典树)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- uva 11488 - Hyper Prefix Sets(字典树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- UVA 11488 Hyper Prefix Sets (字典树)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva 11488 Hyper Prefix Sets(狂水)
题意: 获得集合中最长前缀长度*有该前缀个数的最大值 Prefix goodness of a set string is length of longest common prefix*number ...
- UVa 11488 - Hyper Prefix Sets
找 前缀长度*符合该前缀的字符串数 的最大值 顺便练了一下字典树的模板 #include <iostream> #include <cstdio> #include <c ...
- UVA - 11488 Hyper Prefix Sets(trie树)
1.给n个只含0.1的串,求出这些串中前缀的最大和. 例1: 0000 0001 10101 010 结果:6(第1.2串共有000,3+3=6) 例2: 01010010101010101010 1 ...
- 【习题 3-10 UVA - 1587】Box
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举某个顶角的三个相邻面就好. 看看这三个相邻面有没有对应的面. 以及3个相邻面的6个边. 能否分成2个a,2个b,2个c 也即每个 ...
- Mango Weekly Training Round #3 解题报告
A. Codeforces 92A Chips 签到题.. #include <iostream> #include <cstdio> #include <cstring ...
随机推荐
- Mysql数据库系列
详情点击 MySQL基础 Mysql表操作 Mysql插入 更新 删除 查询操作 Mysql创建用户和授权 基本的Mysql语句 Mysql库的操作 Mysql表的操作 Mysql数据类型(一) My ...
- Hibernate基础(二)
Hibernate中的实体规则 创建实体类注意事项: 1.持久化类提供无参构造函数 2.成员变量私有 提供共有get set 方法 3.属性应尽量使用包装类 Integer.Float.Double等 ...
- 前端性能优化---DOM操作
小结 1缓存DOM对象 场景:缓存DOM对象的方式也经常被用在元素的查找中,查找元素应该是DOM操作中最频繁的操作了,其效率优化也是大头.在一般情况下,我们会根据需要,将一些频繁被查找的元素缓存起来, ...
- P1146 硬币翻转
题目描述 在桌面上有一排硬币,共N枚,每一枚硬币均为正面朝上.现在要把所有的硬币翻转成反面朝上,规则是每次可翻转任意N-1枚硬币(正面向上的被翻转为反面向上,反之亦然).求一个最短的操作序列(将每次翻 ...
- hibernate_06_单表操作_组件属性
什么是组件属性? 比如address是students的其中一个属性,而address又有三个属性:邮编.电话和地址.address就是hibernate的组件属性. 首先建立Address类: pa ...
- Docker系列之入门
Docker基本介绍 一.什么是Docker 在docker的官方之什么是docker中提到了一句话:“当今各大组织或者团体的创新都源于软件(例如OA.ERP等),其实很多公司都是软件公司" ...
- ffmpeg中关于EAGAIN的理解及非阻塞IO
ffmpeg为在linux下开发的开源音视频框架,所以经常会碰到很多错误(设置errno),其中EAGAIN是其中比较常见的一个错误(比如用在非阻塞操作中). try again,从字面上来看,是提 ...
- Linux+Apache下如何安装SSL证书
最近很多站长在问linux系统平台下如何安装SSL证书?Linux+Apache下如何安装SSL证书?本文整理了关于Linux+Apache下如何安装SSL证书的相关教程供大家参考,更多SSL证书安装 ...
- [系统资源攻略]IO第一篇-磁盘IO,内核IO概念
几个基本的概念 在研究磁盘性能之前我们必须先了解磁盘的结构,以及工作原理.不过在这里就不再重复说明了,关系硬盘结构和工作原理的信息可以参考维基百科上面的相关词条--Hard disk drive(英文 ...
- 为什么多 TCP 连接比单 TCP 连接传输快
转自: 我观察到,客户端机器从单一服务器使用 HTTP 下载一个文件:1. 单连接下载,速度没有达到客户端网络的最大带宽:2. 多连接同时下载,传输速度有极大的提高,带宽被占满. 假设如下前提:1. ...