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;
} 
时间: 2024-11-05 01:57:54

UVA 4855 Hyper Box的相关文章

UVA 4855 Hyper Box 斐波那契

题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2856 比赛的时候和陈看了好长时间才看明白题意,和吴讨论做了出来,其实吴确实聪明,脑袋瓜子比较灵活 题意:有一个N维的空间,给你各维的长度,有一些n维的砖块,把空间填满,砖块不能交叉,空间不能一部分为空:求最少用的砖块 砖块各维都必须为斐波那契长度 思路: 空间各维分

uva 501 - Black Box(优先队列)

题目链接:uva 501 - Black Box 题目大意:有一个集合,给定元素进入集合的顺序,现在有Q次查询,给定每次查询在第几个元素进入集合后,对于每i次查询,输出集合中第i小的数. 解题思路:用两个优先队列维护,队列a优先出值大的,队列b优先出值小的,在第i次询问前,保证a队列中有i-1个元素元素,并且抱枕都比b中的小,然后每次询问输出b队列的首元素,并且将它放到a队列中. #include <cstdio> #include <cstring> #include <q

uva 11488 - Hyper Prefix Sets(字典树)

H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of strings in the set. For example the prefix goodness of the set {000,001,0011} is 6.You are given a set of binary strings. Find the maximum prefix goodnes

UVA - 501 Black Box (优先队列或vector)

Description  Black Box  Our Black Box represents a primitive database. It can save an integer array and has a special i variable. At the initial moment Black Box is empty and i equals 0. This Black Box processes a sequence of commands (transactions).

UVA 11488 Hyper Prefix Sets (Trie)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2483 Hyper Prefix Sets Prefix goodness of a set string islength of longest common prefix*number of strings in the set.For example the prefix goodnes

UVa 11488 Hyper Prefix Sets

方法:Trie 本题其实就是trie的实现,每个节点需要记录两个值,深度 和 visit的次数,答案便是 max(深度 * visit的次数). 数组实现code: #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <string> #include <vector> #include <stack>

UVA 11488(Hyper Prefix Sets-Trie统计)

Pre x goodness of a set string is length of longest common pre x*number of strings in the set. For example the pre x goodness of the set f000,001,0011g is 6.You are given a set of binary strings. Find the maximum pre x goodness among all possible sub

UVA 11488 Hyper Prefix Sets 字典树

模板题,字典树最基本的操作 在看别人的板子的时候学到了一点小技巧 下面贴AC代码,顺便补一补字典树相关,顺便放一下橙子讲课的笔记 Trie三兄弟--标准Trie.压缩Trie.后缀Trie 字符串模式匹配算法--BM.Horspool.Sunday.KMP.KR.AC算法一网打尽 #include<bits/stdc++.h> using namespace std; const int MAX = 5e4 + 5; string s; int n, t, ans; struct Trie {

Trie 字典树

1.UVa 1401 Remember the Word 题意:给出n个字符串集合,问其有多少种组合方式形成目标字符串. 思路:对n个字符串集合建立Trie树,保存每个结点的字符串的顺序编号.然后对这棵树查找目标字符串每一个后缀的前缀字符串,累加. 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 #include<vector>