Twin Towers
来源:互联网 发布:js能定义二维数组吗 编辑:程序博客网 时间:2024/05/24 01:18
问题描述:UVA 10066
Problem B
The Twin Towers
Input: standard input
Output: standard output
Once upon a time, in an ancient Empire, there were two towers of dissimilar shapes in two different cities. The towers were built by putting circular tiles one upon another. Each of the tiles was of the same height and had integral radius. It is no wonder that though the two towers were of dissimilar shape, they had many tiles in common.
However, more than thousand years after they were built, the Emperor ordered his architects to remove some of the tiles from the two towers so that they have exactly the same shape and size, and at the same time remain as high as possible. The order of the tiles in the new towers must remain the same as they were in the original towers. The Emperor thought that, in this way the two towers might be able to stand as the symbol of harmony and equality between the two cities. He decided to name them the Twin Towers.
Now, about two thousand years later, you are challenged with an even simpler problem: given the descriptions of two dissimilar towers you are asked only to find out the number of tiles in the highest twin towers that can be built from them.
Input
The input file consists of several data blocks. Each data block describes a pair of towers.
The first line of a data block contains two integers N1 and N2 (1 <= N1, N2 <= 100) indicating the number of tiles respectively in the two towers. The next line contains N1 positive integers giving the radii of the tiles (from top to bottom) in the first tower. Then follows another line containing N2 integers giving the radii of the tiles (from top to bottom) in the second tower.
The input file terminates with two zeros for N1 and N2.
Output
For each pair of towers in the input first output the twin tower number followed by the number of tiles (in one tower) in the highest possible twin towers that can be built from them. Print a blank line after the output of each data set.
Sample Input
7 620 15 10 15 25 20 15
15 25 10 20 15 20
8 9
10 20 20 10 20 10 20 10
20 10 20 10 10 20 10 10 20
0 0
Sample Output
Twin Towers #1Number of Tiles : 4
Twin Towers #2
Number of Tiles : 6
Rezaul Alam Chowdhury
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//此题就是求最长子序列
#include<iostream>#include<fstream>#include<cstdlib>using namespace std;ifstream fin("C:\\data22.in");int N1,N2;int tile1[101];int tile2[101];int sub[101][101];int cnt;void DP(){for(int i=1;i<=N1;++i){for(int j=1;j<=N2;++j){if(tile1[i]==tile2[j])sub[i][j]=sub[i-1][j-1]+1;elsesub[i][j]=sub[i-1][j]>sub[i][j-1]?sub[i-1][j]:sub[i][j-1];}}}void Init(){cnt=0;while(fin>>N1>>N2&&(N1!=0&&N2!=0)){memset(sub,0,sizeof(sub));for(int i=1;i<=N1;++i)fin>>tile1[i];for(int j=1;j<=N2;++j)fin>>tile2[j];DP();cout<<"Twin Towers #"<<++cnt<<endl;cout<<"Number of Tiles = "<<sub[N1][N2]<<endl;cout<<endl;}}int main(){Init();system("pause");return 0;}
Problem B
The Twin Towers
Input: standard input
Output: standard output
Once upon a time, in an ancient Empire, there were two towers of dissimilar shapes in two different cities. The towers were built by putting circular tiles one upon another. Each of the tiles was of the same height and had integral radius. It is no wonder that though the two towers were of dissimilar shape, they had many tiles in common.
However, more than thousand years after they were built, the Emperor ordered his architects to remove some of the tiles from the two towers so that they have exactly the same shape and size, and at the same time remain as high as possible. The order of the tiles in the new towers must remain the same as they were in the original towers. The Emperor thought that, in this way the two towers might be able to stand as the symbol of harmony and equality between the two cities. He decided to name them the Twin Towers.
Now, about two thousand years later, you are challenged with an even simpler problem: given the descriptions of two dissimilar towers you are asked only to find out the number of tiles in the highest twin towers that can be built from them.
Input
The input file consists of several data blocks. Each data block describes a pair of towers.
The first line of a data block contains two integers N1 and N2 (1 <= N1, N2 <= 100) indicating the number of tiles respectively in the two towers. The next line contains N1 positive integers giving the radii of the tiles (from top to bottom) in the first tower. Then follows another line containing N2 integers giving the radii of the tiles (from top to bottom) in the second tower.
The input file terminates with two zeros for N1 and N2.
Output
For each pair of towers in the input first output the twin tower number followed by the number of tiles (in one tower) in the highest possible twin towers that can be built from them. Print a blank line after the output of each data set.
Sample Input
7 620 15 10 15 25 20 15
15 25 10 20 15 20
8 9
10 20 20 10 20 10 20 10
20 10 20 10 10 20 10 10 20
0 0
Sample Output
Twin Towers #1Number of Tiles : 4
Twin Towers #2
Number of Tiles : 6
Rezaul Alam Chowdhury
- Twin Towers
- The Twin Towers
- 10066 - The Twin Towers
- uva_10066The Twin Towers
- 10066 - The Twin Towers
- BNU The Twin Towers
- UVaOJ_10066 - The Twin Towers
- UVA10066 - The Twin Towers
- UVA 10066 - The Twin Towers
- uva 10066 The Twin Towers
- ZOJ2059 The Twin Towers,DP
- zoj 2059 The Twin Towers
- UVA 10066 The Twin Towers
- UVA 10066 The Twin Towers
- UVa 10066 - The Twin Towers
- UVa 10066 - The Twin Towers
- UVa 10066 - The Twin Towers
- UVa 10066 - The Twin Towers
- Delphi XE5应用开发支持的安卓设备
- 【2006】
- JSP(2) - JSP指令 - 小易Java笔记
- 巧用dimens适配多个分辨率
- 在Firefox中使用键盘(F7插入式浏览,可用键盘选中要复制的文字,通过tab切换光标的位置)
- Twin Towers
- 《巨人不死密码》读书笔记
- 越研究这个领域,越觉得一个人伟大,补上一篇迟来的悼文
- XE5安卓手机要求
- Linux常用命令(十) - nl
- LeetCode - Distinct Subsequences 题解
- POJ2184 Cow Exhibition 【01背包】
- 【新博客】重新开通博客的缘由
- gem5中添加调试信息DPRINTF