UVA 4854 A Digital Satire of Digital Age(模拟)

The government of “Moderdesh” is planning to enter the digital age and so people of different profession

and business are proposing different ways to enter that age successfully. The hardware vendors are

saying that we need to provide a laptop for each student, the mobile companies are saying that every

children needs to have a mobile phone in his small hand and talk all night long, the multimedia experts

are crying for Multimedia University and so on. But very few are crying for the overall improvement

of Computer Science education. We do not understand that by being only the consumer of modern

digital technologies we cannot enter the real digital age.

Now as a protest, some local computer geeks are planning to digitize the local vegetable and grocery

markets in a strange way. The local markets generally use weighing balances as shown in the figure-1

and they use conventional weight sets as shown in figure 2. The computer geeks want to introduce a

new type of weight set, where each piece will have the shape of an upper case English alphabet, and

strangely Figure 1: The weighing balance weighing a Figure 2: the weights of these pieces will papaya

using letter shaped weights. Conventional weight set be related with their ASCII valuess. For example

the ASCII value of ‘A’ is 65, which is 10000012 in binary. For each ‘1’ in binary representation a weight

of 500 gms will be added and for each ‘0’ in binary representation a weight of 250 gms will be added.

So a piece with shape ‘A’ actually weighs (250 ? 5 + 2 ? 500) gm = 2250 grams. Note that leading

zeroes in binary representation are not considered. The geeks believe if others are correct about their

ways to enter digital age, they are also correct about digitizing the local markets by introducing new

weight sets related to ASCII characters.

Now in this problem you will be given (i) the picture of a weighing scale and the weight pieces that

it contains in left pan and in the right pan (ii) You will also be informed which pan is heavier and

which pan is lighter (Not necessarily correct). You will have to detect whether the given information

is correct or not. If the given information is not correct you will have to rectify the picture and show

it in the output.

Input

First line of the input file contains a positive integer T (T ≤ 6000) that denotes the number of test

sets. The description of each set of input is given below:

Each set of input is given in a (7 ? 18) grid. This grid actually contains the plain text description

of a weighing scale. Each location of the grid is either a dot ‘.’ (ASCII value 46) or a front slash ‘/’

(ASCII Value 47) or a back slash ‘\’ (ASCII value 92) or an under score ‘_’ (ASCII value 95) or a pipe

‘|’ (ASCII value 124) an upper case English Alphabet (ASCII value 65 to 90). The (7 ? 18) grid is

divided into two equal parts by two vertical lines formed with pipe character. The left part denotes the

status of left pan and right part denotes the status of the right pan. The bottom of the pan is formed

with 6 (six) under score characters and the ropes attached to the pans are formed with front slash and

back slash. The weights on both pans are placed just above the row that denotes bottom of the pan

and they are left justified. There can be maximum 6 weights on a single pan. There are three possible

vertical positioning of the pans (i) Left pan is low and right pan is high (ii) Both pan is in the middle

(iii) Left pan is high and right pan is low. If weight of both pan is same then they should be in state

(ii), if the left pan is heavier then they should be in status (i) and so on. In the input the pans are

always in position (i), (ii) or (iii) but that may not be the correct position according to the weights

they contain.

A line containing 18 (eighteen) ‘-’ (minus) signs follows each set of input.

Output

For each set of input produce two or eight line of output. First line should contain the serial of output.

If the pans in the input figure are in correct position according to the weights they contain then in

the second line print “The figure is correct.” (without the quotes). If the pans are not in correct

position then print the weighing balance again in a (7 ? 18) grid with the pans in the correct position.

Look at the output for sample input for exact formatting.

Sample Input

4

........||.../\...

........||../..\..

.../\...||./....\.

../..\..||/G.....\

./....\.||\______/

/YQYFU.\||........

\______/||........

------------------

.../\...||........

../..\..||........

./....\.||.../\...

/WCGQG.\||../..\..

\______/||./....\.

........||/OYA...\

........||\______/

------------------

.../\...||........

../..\..||........

./....\.||.../\...

/A.....\||../..\..

\______/||./....\.

........||/A.....\

........||\______/

------------------

........||........

.../\...||.../\...

../..\..||../..\..

./....\.||./....\.

/NQ....\||/FG....\

\______/||\______/

........||........

------------------

Sample Output

Case 1:

The figure is correct.

Case 2:

........||.../\...

........||../..\..

.../\...||./....\.

../..\..||/OYA...\

./....\.||\______/

/WCGQG.\||........

\______/||........

Case 3:

........||........

.../\...||.../\...

../..\..||../..\..

./....\.||./....\.

/A.....\||/A.....\

\______/||\______/

........||........

Case 4:

The figure is correct

题意:输入一个天平,以ascii的值的二进制,0表示250,1表示500,问这个天平的两端位置是否正确,

如果正确输出 The figure is correct.不正确,则输出正确的天平位置图。

这题模拟,,有点麻烦。

#include<stdio.h>
#include<string.h>
char mp[10][20];
char s1[8],s2[8];
int vale[30] = {2250,2250,2500,2250,2500,2500,2750,2250,2500,2500,2750,2500,2750,2750,3000,2250,2500,2500,2750,2500,2750,2750,3000,2500,2750,2750,};
int main(){
	int T,a1,a2,sum1,sum2,cas=1;
	scanf("%d",&T);
	while(T--){
		char str1[8][20]={
		"........||........",
		".../\\...||.../\\...",
		"../..\\..||../..\\..",
		"./....\\.||./....\\.",
		"/......\\||/......\\",
		"\\______/||\\______/",
		"........||........" } ;
		char str2[8][20]={
		"........||.../\\...",
		"........||../..\\..",
		".../\\...||./....\\.",
		"../..\\..||/......\\",
		"./....\\.||\\______/",
		"/......\\||........",
		"\\______/||........"};
		char str3[8][20]={
		".../\\...||........",
		"../..\\..||........",
		"./....\\.||.../\\...",
		"/......\\||../..\\..",
		"\\______/||./....\\.",
		"........||/......\\",
		"........||\\______/"};
		int k1=0,k2=0,i,j;
		sum1=sum2=0;a1=a2=-1;
		memset(s1,'\0',sizeof(s1));
		memset(s2,'\0',sizeof(s2));
		for(i=0;i<8;++i){
			scanf("%s",mp[i]);
			for(j=0;j<18;++j){
				if(mp[i][j]=='/' && j<8){
					if(a1==-1) a1=i;//a1记录左边最高的‘/’的行数
				}
				if(mp[i][j]=='/' && j>9){
					if(a2==-1)	a2=i;//a2记录右边的
				}
				if(mp[i][j]>='A' && mp[i][j]<='Z' && j<8){
					sum1+=vale[mp[i][j]-'A'];
					s1[k1++]=mp[i][j];
				}
				if(mp[i][j]>='A' && mp[i][j]<='Z' && j>9){
					sum2+=vale[mp[i][j]-'A'];
					s2[k2++]=mp[i][j];
				}
			}
		}
		if(a1==a2 && sum1==sum2)//正确的情况
			printf("Case %d:\nThe figure is correct.\n",cas++);
		else if(a1<a2 && sum1<sum2)
			printf("Case %d:\nThe figure is correct.\n",cas++);
		else if(a1>a2 && sum1>sum2)
			printf("Case %d:\nThe figure is correct.\n",cas++);
		else if(a1>a2 && sum1<sum2){//不正确的情况
			printf("Case %d:\n",cas++);
			for(i=0,j=1;i<k1;++i,++j)
				str3[3][j]=s1[i];
			for(i=0,j=11;i<k2;++i,++j)
				str3[5][j]=s2[i];

			for(i=0;i<7;++i){
				printf("%s\n",str3[i]);
			}
		}else if(a1<a2 && sum1>sum2){
			printf("Case %d:\n",cas++);
			for(i=0,j=1;i<k1;++i,++j)
				str2[5][j]=s1[i];
			for(i=0,j=11;i<k2;++i,++j)
				str2[3][j]=s2[i];

			for(i=0;i<7;++i){
				printf("%s\n",str2[i]);
			}
		}else if( (a1>a2 || a1<a2) && (sum1==sum2)){
			printf("Case %d:\n",cas++);
			for(i=0,j=1;i<k1;++i,++j)
				str1[4][j]=s1[i];
			for(i=0,j=11;i<k2;++i,++j)
				str1[4][j]=s2[i];

			for(i=0;i<7;++i){
				printf("%s\n",str1[i]);
			}
		}else if(a1==a2 && sum1<sum2){
			printf("Case %d:\n",cas++);
			for(i=0,j=1;i<k1;++i,++j)
				str3[3][j]=s1[i];
			for(i=0,j=11;i<k2;++i,++j)
				str3[5][j]=s2[i];
			for(i=0;i<7;++i)
				printf("%s\n",str3[i]);
		}else if(a1==a2 && sum1>sum2){
			printf("Case %d:\n",cas++);
			for(i=0,j=1;i<k1;++i,++j)
				str2[5][j]=s1[i];
			for(i=0,j=11;i<k2;++i,++j)
				str2[3][j]=s2[i];
			for(i=0;i<7;++i)
				printf("%s\n",str2[i]);
		}
	}
	return 0;
} 
时间: 2024-10-14 18:07:31

UVA 4854 A Digital Satire of Digital Age(模拟)的相关文章

uva 101 The Blocks Problem (基本算法-模拟)

 The Blocks Problem  Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world in which a robot arm performed

uva 11384 Help is needed for Dexter(模拟)

uva 11384 Help is needed for Dexter Dexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for her is quite easy to play but not easy to win at least not for Dee Dee. But Dexter does not have time to spend on th

UVA - 10716 - Evil Straw Warts Live (简单模拟)

UVA - 10716 Evil Straw Warts Live Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Problem D: Evil Straw Warts Live A palindrome is a string of symbols that is equal to itself when reversed. Given an

UVA 1412 - Fund Management(用vector容器模拟状态的状压dp)

Frank is a portfolio manager of a closed-end fund for Advanced Commercial Markets (ACM ). Fund collects money (cash) from individual investors for a certain period of time and invests cash into various securities in accordance with fund's investment

UVA 11210 Chinese Mahjong(中国麻将 , 大模拟)

解题思路: 关键在于如何判断十四张牌能否和牌,这里采用dfs来判断,详情看代码. #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map>

UVA - 101 The Blocks Problem(STL,模拟)

The Blocks Problem Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an e

UVa 442 Matrix Chain Multiplication(矩阵链乘,模拟栈)

题意  计算给定矩阵链乘表达式需要计算的次数  当前一个矩阵的列数等于后一个矩阵的行数时  他们才可以相乘  不合法输出error 输入是严格合法的  即使只有两个相乘也会用括号括起来  而且括号里最多有两个 那么就很简单了 遇到字母直接入栈  遇到反括号计算后入栈  然后就得到结果了 #include<cstdio> #include<cctype> #include<cstring> using namespace std; const int N = 1000;

UVA 230 Borrowers(vector和map的应用,模拟)

1 //#include<bits/stdc++.h> 2 #include<cstdio> 3 #include<queue> 4 #include<algorithm> 5 #include<cstring> 6 #include<string> 7 #include<iostream> 8 using namespace std; 9 typedef long long ll; 10 /** 11 题意:SHELVE

UVa 12657 Boxes in a Line(数组模拟双链表)

题目链接 1 /* 2 问题 3 将一排盒子经过一系列的操作后,计算并输出奇数位置上的盒子标号之和 4 5 解题思路 6 由于数据范围很大,直接数组模拟会超时,所以采用数组模拟的链表,left[i]和right[i]分别表示i号盒子的左边是谁和右边 7 是谁.特别提醒,4这个操作可以采用其他的办法去标记,而不必真的去模拟交换,否则会超时. 8 */ 9 10 #include<cstdio> 11 #include<algorithm> 12 13 using namespace