Contest2073 - 湖南多校對抗賽(2015.04.06)

題目連接:http://acm.csu.edu.cn/OnlineJudge/contest.php?cid=2073php

Problem A: (More) Multiplication

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 86  Solved: 48
[Submit][Status][Web Board]

Description

Educators are always coming up with new ways to teach math to students. In 2011, an educational software company, All Computer Math (ACM), developed an application to display products in a traditional grade school math format. ACM is now working on an updated version of the software that will display results in a lattice format that some students find to be easier when multiplying larger numbers.

An example would be when multiplying 345 * 56 = 19320 as given below, using a lattice grid with 2 rows and 3 columns, which appears inside a surrounding frame:ios

+---------------+
|   3   4   5   |
| +---+---+---+ |
| |1 /|2 /|2 /| |
| | / | / | / |5|
|1|/ 5|/ 0|/ 5| |
| +---+---+---+ |
|/|1 /|2 /|3 /| |
| | / | / | / |6|
|9|/ 8|/ 4|/ 0| |
| +---+---+---+ |
|/ 3 / 2 / 0    |
+---------------+
The first operand, 345, is displayed above the top of the grid with each digit centered horizontally above its column of the grid, and the second operand, 56, is displayed along the righthand side with each digit centered vertically at the center of its row in the grid. A single cell of the grid, such as
+---+
|3 /|
| / |
|/ 0|
+---+
represents the product of the digit of the first operand that is above its column and the digit of the second operand that is to the right of its row. In our example, this cell represents the product 5 times 6 = 30 that results when multiplying the 5 in 345 and the 6 in 56. Note that the 10's digit of that product is placed in the upper left portion of this cell and the 1's digit in the lower right.

The overall product is then computed by summing along the diagonals in the lattice that represent the same place values in the result. For example, in our first problem the product 19320 was computed as:c++

 
1's digit = 0
10's digit = 5 + 3 + 4 = 12, thus 2 with a carry of 1
100's digit = (1 carry) + 2 + 0 + 2 + 8 = 13, thus 3 with a carry of 1
1000's digit = (1 carry) + 2 + 5 + 1 = 9
10000's digit = 1
The resulting product is placed with the one's digit below the grid at the far right and, depending on its length, with the most significant digits wrapped around the left side of the grid. Each digit of the final product appears perfectly aligned with the corresponding diagonal summands.
To provide an aesthetic view, we use a series of minus (-) characters for horizontal lines, pipe (|) characters for vertical lines, and slash (/) characters for diagonal lines. Furthermore, we use a plus (+) character wherever a horizontal and vertical line meet. Each multiplication lattice is subsequently "boxed" by an outer border. There is a row containing the first operand which is between the topmost border and the top line of the grid, and a row between the bottom of the grid and the bottom border, which contains some portion of the resulting product. There is one column between the leading | and the left edge of the inner grid, which may contain a portion of the resulting product, and one column after the right edge of the inner grid but before the rightmost | border, which contains the second operand. If the product is not long enough to wrap around the bottom-left corner, the column between the left border and the left edge of the grid will containing only spaces. (See the later example of 3 x 3.)

Leading zeros should be displayed within lattice grid cells, but leading zeros should never be displayed in the product, nor should there ever be a slash (/) character prior to the leading digit of the product. For example, consider the product of 12 * 27 = 324 below:git

+-----------+
|   1   2   |
| +---+---+ |
| |0 /|0 /| |
| | / | / |2|
| |/ 2|/ 4| |
| +---+---+ |
| |0 /|1 /| |
| | / | / |7|
|3|/ 7|/ 4| |
| +---+---+ |
|/ 2 / 4    |
+-----------+
 
Note that in the top-right grid of the lattice, the product 2 * 2 = 04 is displayed with the zero for the tens digit. However, there is no thousands digit displayed in the product 324, nor is there any slash displayed above the digit 3 in that product.

 

Input

 The input contains one or more tests. Each test contains two positive integers, A and B, such that 1 ≤ A ≤ 9999 and 1 ≤ B ≤ 9999. The last data set will be followed by a line containing 0 0.express

Output

 For each data set, produce the grid that illustrates how to multiply the two numbers using the lattice multiplication technique.api

 

Sample Input

345 56
12 27
1 68
9999 7
3 3
0 0

Sample Output

+---------------+
|   3   4   5   |
| +---+---+---+ |
| |1 /|2 /|2 /| |
| | / | / | / |5|
|1|/ 5|/ 0|/ 5| |
| +---+---+---+ |
|/|1 /|2 /|3 /| |
| | / | / | / |6|
|9|/ 8|/ 4|/ 0| |
| +---+---+---+ |
|/ 3 / 2 / 0    |
+---------------+
+-----------+
|   1   2   |
| +---+---+ |
| |0 /|0 /| |
| | / | / |2|
| |/ 2|/ 4| |
| +---+---+ |
| |0 /|1 /| |
| | / | / |7|
|3|/ 7|/ 4| |
| +---+---+ |
|/ 2 / 4    |
+-----------+
+-------+
|   1   |
| +---+ |
| |0 /| |
| | / |6|
| |/ 6| |
| +---+ |
| |0 /| |
| | / |8|
|6|/ 8| |
| +---+ |
|/ 8    |
+-------+
+-------------------+
|   9   9   9   9   |
| +---+---+---+---+ |
| |6 /|6 /|6 /|6 /| |
| | / | / | / | / |7|
|6|/ 3|/ 3|/ 3|/ 3| |
| +---+---+---+---+ |
|/ 9 / 9 / 9 / 3    |
+-------------------+
+-------+
|   3   |
| +---+ |
| |0 /| |
| | / |3|
| |/ 9| |
| +---+ |
|  9    |
+-------+

HINT

 

 The tables must be formatted precisely as outlined by the rules and examples provided. Mistakes that involve solely errant whitespace will be categorized as Presentation Error; all other errors will be reported as Wrong Answer.app

 

題目大意:將第一個乘法按照圖形輸出,第二個乘數在上面橫放,乘數在最右邊豎放。詳解如圖。less

只要按照紅色圈圈這樣就ok了,一道很麻煩的模擬題~ide

 

詳見代碼。測試

  1 #include<iostream>
  2 #include<stdio.h>
  3 #include<string.h>
  4 #define N 10000
  5 using namespace std;
  6 char ch[100][100];
  7 int aaa[15],bbb[15],ccc[400];
  8 int mul[400];
  9 int main()
 10 {
 11     int n,m;
 12     while(~scanf("%d%d",&n,&m))
 13     {
 14         if(n==0&&m==0) break;
 15         bool flag=0;
 16         int a=1,b=1,cc=10,c=1,sum=n*m;
 17         memset(ccc,0,sizeof(ccc));
 18         while(sum)
 19         {
 20             ccc[c++]=sum%cc;
 21             sum/=cc;
 22             //cout<<ccc[c-1]<<endl;
 23         }
 24         c--;
 25         int kkk;
 26         while(n)
 27         {
 28             aaa[a++]=n%cc;
 29             n/=cc;
 30             //cout<<aaa[a-1]<<endl;
 31         }
 32         a--;
 33         while(m)
 34         {
 35             bbb[b++]=m%cc;
 36             m/=cc;
 37         }
 38         b--;
 39         kkk=a+b;
 40         //for(int i=kkk;i>0;i--)
 41         //cout<<ccc[i]<<endl;
 42         int flagg=1,flag1=0;
 43         int kk2=0;
 44         for(int i=b;i>=1;i--)
 45         for(int j=a;j>=1;j--)
 46         mul[++kk2]=aaa[j]*bbb[i];//cout<<" "<<aaa[j]<<" "<<bbb[i]<<" "<<mul[kk2]<<endl;
 47         int kk=a,kk3=1;
 48         kk2=1;
 49         int aa=b*4+5,bb=a*4+5;
 50         for(int i=0;i<aa;i++)
 51         {
 52             for(int j=0;j<bb;j++)
 53             {
 54                 if(i==0||i==aa-1)
 55                 {
 56                     if(j==0||j==bb-1)
 57                     printf("+");
 58                     else printf("-");
 59                 }
 60                 else if((i-2)%4==0&&i!=aa-2)
 61                 {
 62                     if(j==0||j==bb-1)
 63                     printf("|");
 64                     else if((j-2)%4==0)
 65                     printf("+");
 66                     else if(j==1||j==bb-2)
 67                     printf(" ");
 68                     else printf("-");
 69                 }
 70                 else if(i==1)
 71                 {
 72                     if(j==0||j==bb-1)
 73                     printf("|");
 74                     else if((j-4)%4==0)
 75                     printf("%d",aaa[kk--]);
 76                     else printf(" ");
 77                 }
 78                 else if((i-4)%4==0&&i!=aa-2)
 79                 {
 80                     if(j==0||j==bb-1)
 81                     printf("|");
 82                     else if(j==bb-2)
 83                     printf("%d",bbb[b-(i-4)/4]);
 84                     else if((j-2)%4==0)
 85                     printf("|");
 86                     else if((j-4)%4==0&&j!=bb-2&&j!=1)
 87                     printf("/");
 88                     else printf(" ");
 89                 }
 90                 else if((i-3)%4==0&&i!=aa-2)
 91                 {
 92                     if(j==0||j==bb-1)
 93                     printf("|");
 94                     else if((j-2)%4==0)
 95                     printf("|");
 96                     else if((j-3)%4==0&&j!=bb-2)
 97                     printf("%d",mul[kk2++]/10);
 98                     else if((j-5)%4==0&&j!=bb-2)
 99                     {
100                         if(j!=1||(j==1&&flag1==1))
101                         printf("/");
102                         else
103                         printf(" ");
104                     }
105                     else printf(" ");
106                 }
107                 else if((i-5)%4==0&&i!=aa-2)
108                 {
109                     //cout<<ccc[kkk]<<endl;
110                     if(j==0||j==bb-1)
111                     printf("|");
112                     else if((j-2)%4==0)
113                     printf("|");
114                     else if(ccc[kkk]>=0&&j==1)
115                     {
116                         if(ccc[kkk]==0&&flag1==0)
117                             kkk--,printf(" ");
118                         else
119                         printf("%d",ccc[kkk--]),flag1=1;//cout<<endl;
120                     }
121                     else if((j-5)%4==0&&j!=bb-2&&j!=1)
122                     printf("%d",mul[kk3]%10),kk3++;
123                     else if((j-3)%4==0&&j!=bb-2)
124                     printf("/");
125                     else printf(" ");
126                 }
127                 else if(i==aa-2)
128                 {
129                     if(j==0||j==bb-1)
130                     printf("|");
131                     else if(j==1&&flag==1)
132                     printf("/");
133                     else if((j-3)%4==0&&j!=bb-2&&ccc[kkk]>=0)
134                     {
135  
136                         if(ccc[kkk]==0&&flag1==0)
137                             kkk--,printf(" ");
138                         else
139                         printf("%d",ccc[kkk--]),flag1=1;
140                     }
141                     else if((j-5)%4==0&&j<bb-5&&flag1==1)
142                     printf("/");
143                     else printf(" ");
144                 }
145             }
146             printf("\n");
147         }
148     }
149     return 0;
150 }
151  
152 /**************************************************************
153     Problem: 1561
154     User: star_sky
155     Language: C++
156     Result: Accepted
157     Time:0 ms
158     Memory:1496 kb
159 ****************************************************************/

 

 

Problem B: Fun House

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 181  Solved: 66
[Submit][Status][Web Board]

Description

American Carnival Makers Inc. (ACM) has a long history of designing rides and attractions. One of their more popular attractions is a fun house that includes a room of mirrors. Their trademark is to set up the room so that when looking forward from the entry door, the exit door appears to be directly ahead. However, the room has double-sided mirrors placed throughout at 45 degree angles. So, the exit door can be on any of the walls of the room. The set designer always places the entry and mirrors, but can never seem to be bothered to place the exit door. One of your jobs as part of the construction crew is to determine the placement of the exit door for the room given an original design.

The final diagram for a sample room is given below. The asterisk (*) marks the entry way, lower case x's mark the walls, the mirrors are given by the forward and backward slash characters (/ and \), open spaces with no visual obstructions are marked by periods (.), and the desired placement of the exit is marked with an ampersand (&). In the input diagram, there is an 'x' in place of the '&', since the exit has not yet been located. You need to alter the input diagram by replacing the proper 'x' with an '&' to identify the exit. Note that entrances and exits can appear on any of the walls (although never a corner), and that it is physically impossible for the exit to be the same as the entrance. (You don't need to understand why this is so, although it may be fun to think about.)

xxxxxxxxxxx
x../..\...x
x..../....x
*../......x
x.........x
xxxxxx&xxxx

 

Input

Each room will be preceded by two integers, W and L, where 5 ≤ W ≤ 20 is the width of the room including the border walls and 5 ≤ L ≤ 20 is the length of the room including the border walls. Following the specification of W and L are L additional lines containing the room diagram, with each line having W characters from the alphabet: { * , x , . , / , \ }. The perimeter will always be comprised of walls, except for one asterisk (*) which marks the entrance; the exit is not (yet) marked. A line with two zeros indicates the end of input data.

 

Output

For each test case, the first line will contain the word, HOUSE, followed by a space and then an integer that identifies the given fun house sequentially. Following that should be a room diagram which includes the proper placement of the exit door, as marked by an ampersand (&).

 

Sample Input

11 6
xxxxxxxxxxx
x../..\...x
x..../....x
*../......x
x.........x
xxxxxxxxxxx
5 5
xxxxx
*...x
x...x
x...x
xxxxx
5 5
xxxxx
x./\x
*./.x
x..\x
xxxxx
6 6
xxx*xx
x/...x
x....x
x/./.x
x\./.x
xxxxxx
10 10
xxxxxxxxxx
x.../\...x
x........x
x........x
x.../\..\x
*...\/../x
x........x
x........x
x...\/...x
xxxxxxxxxx
0 0

Sample Output

HOUSE 1
xxxxxxxxxxx
x../..\...x
x..../....x
*../......x
x.........x
xxxxxx&xxxx
HOUSE 2
xxxxx
*...&
x...x
x...x
xxxxx
HOUSE 3
xxxxx
x./\x
*./.x
x..\&
xxxxx
HOUSE 4
xxx*xx
x/...x
x....x
x/./.&
x\./.x
xxxxxx
HOUSE 5
xxxxxxxxxx
x.../\...x
x........x
x........x
&.../\..\x
*...\/../x
x........x
x........x
x...\/...x
xxxxxxxxxx

HINT

 

In both Java and C++ the backslash character (\) has special meaning as an escape character within character and string literals. You must use the combination \\ to express a single backslash within a character or string literal within source code.

 

題目大意:主要理解"/"還有"\"這兩個的表達的含義,簡單的說就是初中物理學的反射,仍是看圖~~從這個圖片就很明顯的能夠看出反射以後的狀況了,另外一邊的大同小異。*表示起點,題目是想要咱們找到一個能從起點直接看到的終點(這個終點就是咱們要找的),找到後將X變成&!一路看過去遇到/還有\就能夠反射,轉到其餘的方向上面去~

詳見代碼。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4  
 5 using namespace std;
 6  
 7 int dir[4][2]={-1,0,1,0,0,-1,0,1};
 8 int n,m,ei,ej;
 9 char Map[25][25],flag1;
10  
11 void Dfs(int i,int j,int ans)
12 {
13     if(flag1==1)
14         return ;
15     if(Map[i][j]=='x')
16     {
17         Map[i][j]='&';
18         flag1=1;
19         return ;
20     }
21     if(Map[i][j]=='/')
22     {
23         if(ans==0)
24             Dfs(i+dir[3][0],j+dir[3][1],3);
25         else if(ans==1)
26             Dfs(i+dir[2][0],j+dir[2][1],2);
27         else if(ans==2)
28             Dfs(i+dir[1][0],j+dir[1][1],1);
29         else if(ans==3)
30             Dfs(i+dir[0][0],j+dir[0][1],0);
31     }
32     else if(Map[i][j]=='\\')
33     {
34         if(ans==0)
35             Dfs(i+dir[2][0],j+dir[2][1],2);
36         else if(ans==1)
37             Dfs(i+dir[3][0],j+dir[3][1],3);
38         else if(ans==2)
39             Dfs(i+dir[0][0],j+dir[0][1],0);
40         else if(ans==3)
41             Dfs(i+dir[1][0],j+dir[1][1],1);
42     }
43     else
44         Dfs(i+dir[ans][0],j+dir[ans][1],ans);
45 }
46  
47 int main()
48 {
49     int si,sj,flag=1;
50     while(scanf("%d%d",&n,&m),n||m)
51     {
52         for(int i=0;i<m;i++)
53         {
54             scanf("%s",Map[i]);
55             for(int j=0;j<n;j++)
56                 if(Map[i][j]=='*')
57                     si=i,sj=j;
58         }
59         int ans;
60         flag1=0;
61         if(si==0) ans=1;
62         else if(si==m-1) ans=0;
63         else if(sj==0) ans=3;
64         else if(sj==n-1) ans=2;
65         //cout<<ans<<" "<<dir<<endl;
66         Dfs(si,sj,ans);
67         printf("HOUSE %d\n",flag++);
68         for(int i=0;i<m;i++)
69             printf("%s\n",Map[i]);
70     }
71     return 0;
72 }
73  
74 /**************************************************************
75     Problem: 1562
76     User: star_sky
77     Language: C++
78     Result: Accepted
79     Time:0 ms
80     Memory:1484 kb
81 ****************************************************************/

 

Problem E: Word Cloud

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 73  Solved: 37
[Submit][Status][Web Board]

Description

A word cloud (or tag cloud) is a visual representation of textual data based on a weighted metric. In the above cloud (which is based on this year's list of Mid-Central teams), the font size of each word is based on its number of occurrences in the data set. Tagg Johnson is a man obsessed with counting words that appear in online documents. On his computer, he keeps a spreadsheet of all the sites he visits, along with a list of words that appear on each site and the number of times such word appears. Tagg would like to generate word clouds based on the data he has collected.
Before describing the algorithm Tagg uses for generating clouds, we digress for a quick lesson in typography. The basic unit of measure is known as a point (typically abbreviated as pt). A font's size is described based on the vertical number of points from one line to the next, including any interline spacing. For example, with a 12pt font, the vertical space from the top of one character to the top of a character below it is 12 points. We assume that a character's height is precisely equal to the font's point size (regardless of whether the character is upper or lower case).

For this problem, we focus on a fixed-width font, such as Courier, in which each character of the alphabet is also given the same amount of width. The character width for such a font depends on the font size and the aspect ratio. For Courier, a word with t characters rendered in a font of size P has a total width of  when measured in points. Note well the use of the ceiling operator, which converts any noninteger to the next highest integer. For example, a 5-letter word in a 20pt font would be rendered with a height of 20 points and a width equal to points.

Now we can describe Tagg's algorithm for creating a word cloud. He pre-sorts his word list into alphabetical order and removes words that do not occur at least five times. For each word w, he computes a point size based on the formula , where cw is the number of occurrences of the word, and cmax is the number of occurrences of the most frequent word in the data set. Note that by this formula, every word will be rendered with anywhere from a 9pt font to a 48pt font. He then places the words in rows, with a 10pt horizontal space between adjacent words, placing as many words as fit in the row, subject to a maximum width W for his entire cloud. The height of a given row is equal to the maximum font size of any word rendered in that row.

As a tangible example, consider the following data set and word cloud.

Word         Count

apple          10
banana          5
grape          20
kiwi           18
orange         12
strawberry     10

 

In this example, apple is rendered with 23pt font using width 65pt, banana is rendered with 11pt font using width 38pt, and grape is rendered with 48pt font and width 135pt. If the overall word cloud is constrained to have width at most 260, those three words fit in a row and the overall height of that row is 48pt (due to grape). On the second row kiwi is rendered with height 43pt and width 97pt, and orange is rendered with height 28pt and width 95pt. A third row has strawberry with height 23pt and width 130pt. The overall height of this word cloud is 114pt.

 

Input

 Each data set begins with a line containing two integers: W and N. The value W denotes the maximum width of the cloud; W ≤ 5000 will be at least as wide as any word at its desired font size. The value 1 ≤ N ≤ 100 denotes the number of words that appear in the cloud. Following the first line are N additional lines, each having a string S that is the word (with no whitespace), and an integer C that is a count of the number of occurrences of that word in the original data set, with 5 ≤ C ≤ 1000. Words will be given in the same order that they are to be displayed within the cloud.

Output

 For each data set, output the word CLOUD followed by a space, a serial number indicating the data set, a colon, another space, and the integer height of the cloud, measured in font points.

Sample Input

260 6
apple 10
banana 5
grape 20
kiwi 18
orange 12
strawberry 10
250 6
apple 10
banana 5
grape 20
kiwi 18
orange 12
strawberry 10
610 6
apple 10
banana 5
grape 20
kiwi 18
orange 12
strawberry 10
0 0

Sample Output

CLOUD 1: 114
CLOUD 2: 99
CLOUD 3: 48

題目大意:把題目輸入的每個都當作一個小盒子,最外層的是一個大盒子。按照所給的順序存放在一個盒子中,開始輸入的兩個w和n分別表示盒子的最大的寬度,以及有多少個盒子。而後輸入每一個小盒子和分別出現的次數。

說下這兩個公式,第一個這個是求p(高度),cw表示的是每一個小盒子的出現次數,cmax表示出現最多的次數。

第二個這個是求寬度的,t表示的是apple的字節長度,p就是上面求得那個。

經過這兩個公式就能夠求的每一個小盒子的高度和寬度。

特別注意:一、要按照所給的順序放,放到這一行不能放了在換行。

     二、with a 10pt horizontal space between adjacent words.特別注意這句話,很久才發現的,這個是說每一個小盒子間要空10,因此不要忘記加這個10,可是第一個千萬不要加哦~

 

詳見代碼。

 

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5  
 6 using namespace std;
 7  
 8 char ch[11000];
 9  
10 int main ()
11 {
12     int w,n,t[210],p[210],num[210],time[210],flag=1;
13     while (scanf("%d%d",&w,&n),w||n)
14     {
15         int Max=0;
16         for (int i=0; i<n; i++)
17         {
18             scanf("%s%d",ch,&time[i]);
19             //memset(vis,0,sizeof(vis));
20             t[i]=strlen(ch);
21             if (Max<time[i])
22                 Max=time[i];
23         }
24         for (int i=0; i<n; i++)
25         {
26             p[i]=8+ceil(40*((time[i]-4)*(1.0))/(Max-4));
27             num[i]=ceil(((9*1.0)/16)*p[i]*t[i]);
28             //cout<<num[i]<<" "<<p[i]<<" "<<(time[i]-4)*(1.0)/(Max-4)<<endl;
29         }
30         int i=0,sum=0;
31         while(i<n)
32         {
33             int s=0;
34             int maxx=0;
35             while(s<=w)
36             {
37                 //cout<<s<<endl;
38                 if(s+num[i]>w||i==n)
39                     break;
40                 s+=num[i]+10;
41                 maxx=max(maxx,p[i]);
42                 i++;
43             }
44             sum+=maxx;
45         }
46         printf("CLOUD %d: %d\n",flag++,sum);
47     }
48     return 0;
49 }
50  
51 /**************************************************************
52     Problem: 1565
53     User: star_sky
54     Language: C++
55     Result: Accepted
56     Time:0 ms
57     Memory:1496 kb
58 ****************************************************************/

 

 

Problem G: Reverse Rot

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 150  Solved: 82
[Submit][Status][Web Board]

Description

A very simplistic scheme, which was used at one time to encode information, is to rotate the characters within an alphabet and rewrite them. ROT13 is the variant in which the characters A-Z are rotated 13 places, and it was a commonly used insecure scheme that attempted to "hide" data in many applications from the late 1990's and into the early 2000's.

It has been decided by Insecure Inc. to develop a product that "improves" upon this scheme by first reversing the entire string and then rotating it. As an example, if we apply this scheme to string ABCD with a reversal and rotation of 1, after the reversal we would have DCBA and then after rotating that by 1 position we have the result EDCB.

Your task is to implement this encoding scheme for strings that contain only capital letters, underscores, and periods. Rotations are to be performed using the alphabet order:

ABCDEFGHIJKLMNOPQRSTUVWXYZ_.
Note that underscore follows Z, and the period follows the underscore. Thus a forward rotation of 1 means 'A' is shifted to 'B', that is, 'A'→'B', 'B'→'C', ..., 'Z'→'_', '_'→'.', and '.'→'A'. Likewise a rotation of 3 means 'A'→'D', 'B'→'E', ..., '.'→'C'.

 

Input

Each input line will consist of an integer N, followed by a string. N is the amount of forward rotation, such that 1 ≤ N ≤ 27. The string is the message to be encrypted, and will consist of 1 to 40 characters, using only capital letters, underscores, and periods. The end of the input will be denoted by a final line with only the number 0.

 

Output

For each test case, display the "encrypted" message that results after being reversed and then shifted.

 

Sample Input

1 ABCD
3 YO_THERE.
1 .DOT
14 ROAD
9 SHIFTING_AND_ROTATING_IS_NOT_ENCRYPTING
2 STRING_TO_BE_CONVERTED
1 SNQZDRQDUDQ
0

Sample Output

EDCB
CHUHKWBR.
UPEA
ROAD
PWRAYF_LWNHAXWH.RHPWRAJAX_HMWJHPWRAORQ.
FGVTGXPQEAGDAQVAIPKTVU
REVERSE_ROT

題目大意:直接說下輸入吧,輸入的第一個數就是表示一次移動幾格,第二個就是加了密的密碼。要按照ABCDEFGHIJKLMNOPQRSTUVWXYZ_.進行譯碼,可是注意要從加密的密碼尾部開始譯碼。最後輸出就ok了,哇哈哈~注意一種特殊狀況。

給一組測試數據

2   WFDFG..__..__  這個就是考慮,數字和字符之間會不會有多個空格,解決這個問題就沒大問題了

 

詳見代碼。

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<string.h>
 4 #define N 10000
 5 using namespace std;
 6 int main()
 7 {
 8     char ch[50]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ_.\0"};
 9     int n;
10     char a[100];
11     while(~scanf("%d%s",&n,a))
12     {
13         if(n==0) break;
14         //cout<<a<<endl;
15         int i=strlen(a),k;
16         for(int j=0;j<i;j++)
17         {
18             if(a[j]=='_')
19             {
20                 k=26;
21                 //cout<<ch[k]<<endl;
22             }
23             else if(a[j]=='.')
24             {
25                 k=27;
26                 //cout<<ch[k]<<endl;
27             }
28             else
29             {
30                 k=a[j]-'A';
31             }
32             k+=n;
33             k%=28;
34             a[j]=ch[k];
35         }
36         for(int j=i-1;j>=0;j--)
37         printf("%c",a[j]);
38         printf("\n");
39     }
40     return 0;
41 }
42  
43 /**************************************************************
44     Problem: 1567
45     User: star_sky
46     Language: C++
47     Result: Accepted
48     Time:0 ms
49     Memory:1484 kb
50 ****************************************************************/

 

Problem I: Wet Tiles

Time Limit: 60 Sec  Memory Limit: 512 MB
Submit: 73  Solved: 34
[Submit][Status][Web Board]

Description

Alice owns a construction company in the town of Norainia, famous for its unusually dry weather. In fact, it only rains a few days per year there. Because of this phenomenon, many residents of Norainia neglect to do roof repairs until leaks occur and ruin their floors. Every year, Alice receives a deluge of calls from residents who need the leaks fixed and floor tiles replaced. While exquisite in appearance, Norainia floor tiles are not very water resistant; once a tile becomes wet, it is ruined and must be replaced. This year, Alice plans to handle the rainy days more efficiently than in past years. She will hire extra contractors to dispatch as soon as the calls come in, so hopefully all leaks can be repaired as soon as possible. For each house call, Alice needs a program to help her determine how many replacement tiles a contractor team will need to bring to complete the job.

For a given house, square floor tiles are arranged in a rectangular grid. Leaks originate from one or more known source locations above specific floor tiles. After the first minute, the tiles immediately below the leaks are ruined. After the second minute, water will have spread to any tile that shares an edge with a previously wet tile. This pattern of spreading water continues for each additional minute. However, the walls of a house restrict the water; if a damaged area hits a wall, the water does not penetrate the wall. We assume there are always four outer walls surrounding the entire house. A house may also have a number of additional "inner" walls; each inner wall is comprised of a connected linear sequence of locations (which may or may not be connected to the outer walls or to each other).

As an example, Figure 1 shows water damage (in gray) that would result from three initial leaks (each marked with a white letter 'L') after each of the first five minutes of time. Tiles labeled '2' become wet during the second minute, tiles labeled '3' become wet during the third minute, and so forth. The black areas designate inner walls that restrict the flow of water. Note that after 5 minutes, a total of 75 tiles have been damaged and will need to be replaced. Figures 2 through 4 show other houses that correspond to the example inputs for this problem.

75 wet tiles

17 wet tiles

4 wet tiles

94 wet tiles

 

 

 

Input

 Each house is described beginning with a line having five integral parameters: X Y T L W. Parameters X and Y designate the dimensions of the rectangular grid, with 1 ≤ X ≤ 1000 and 1 ≤ Y ≤ 1000. The coordinate system is one-indexed, as shown in the earlier figures. Parameter T designates the number of minutes that pass before a team of contractors arrives at a house and stops the leaks, with 1 ≤ T ≤ 200000. The parameter L designates the number of leaks, with 1 ≤ L ≤ 100. Parameter W designates the number of inner walls in the house, 0 ≤ W ≤ 100.

The following 2L integers in the data set, on one or more lines, are distinct (x y) pairs that designate the locations of the L distinct leaks, such that 1 ≤ x ≤ X and 1 ≤ y ≤ Y.

If W > 0, there will be 4W additional integers, on one or more lines, that describe the locations of the walls. For each such wall the four parameters (x1,y1), (x2,y2) describe the locations of two ends of the wall. Each wall replaces a linear sequence of adjoining tiles and is either axis-aligned or intersects both axes at a 45 degree angle. Diagonal walls are modeled as a sequence of cells that would just be touching corner to corner. If the two endpoints of a wall are the same, the wall just occupies the single cell at that location. Walls may intersect with each other, but no leak is over a wall.

There will be one or more houses in the data file and a line with a single integer -1 designates the end of the data set.

Output

 For each house, display the total number of tiles that are wet after T minutes.

Sample Input

12 12 5 3 5
2 11 3 3 9 5
1 9 6 9 1 7 4 4 7 1 7 4
10 9 10 12 11 4 12 4
9 7 8 1 3
4 3
2 2 6 6 6 2 2 6 8 2 8 2
6 7 50 1 3
3 4
2 2 2 6 3 6 5 4 5 4 3 2
12 12 5 3 0
2 11 3 3 9 5
-1

Sample Output

75
17
4
94

最後一題,在還有半個小時的時候纔看的,題目太長猜了一下,結果理解了題意0.0

題目大意:給一個x*y的矩陣,給出幾個漏水的地點,還會給出牆的起始座標。漏水點水會蔓延,到牆的位置過不去,求有多少瓷磚被淹。用廣搜就能夠,起點已經給了、

 

詳見代碼。

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<queue>
  5 using namespace std;
  6 struct ssss
  7 {
  8     int x,y,t;
  9 } s,ss;
 10 bool Map[1010][1010];
 11 int xy[4][2]= {0,1,0,-1,1,0,-1,0};
 12 int main()
 13 {
 14     int n,m,t,l,w;
 15     while(~scanf("%d",&n))
 16     {
 17         if(n==-1) break;
 18         scanf("%d%d%d%d",&m,&t,&l,&w);
 19         queue<ssss>q;
 20         memset(Map,0,sizeof(Map));
 21         int sum=l;
 22         while(l--)
 23         {
 24             scanf("%d%d",&s.x,&s.y);
 25             s.y=m-s.y+1;
 26             s.t=1;
 27             Map[s.x][s.y]=1;
 28             q.push(s);
 29         }
 30         while(w--)
 31         {
 32             //cout<<w<<endl;
 33             int a,b,c,d;
 34             scanf("%d%d%d%d",&a,&b,&c,&d);
 35             b=m-b+1;
 36             d=m-d+1;
 37             int x=d-b,y=c-a;
 38             if(y==0)
 39             {
 40                 if(x>0)
 41                 {
 42                     while(b<=d)
 43                     {
 44                         Map[a][b]=1,b++;
 45                     }
 46                 }
 47                 else
 48                     while(b>=d)
 49                     {
 50                         Map[a][b]=1,b--;
 51                     }
 52             }
 53             else if(y<0)
 54             {
 55                 if(x>0)
 56                     while(a>=c)
 57                     {
 58                         Map[a][b]=1,b++,a--;
 59                     }
 60                 else if(x<0)
 61                     while(a>=c)Map[a][b]=1,b--,a--;
 62                 else while(a>=c)Map[a][b]=1,a--;
 63             }
 64             else
 65             {
 66                 if(x>0)
 67                     while(a<=c)
 68                         Map[a][b]=1,b++,a++;
 69                 else if(x<0)
 70                 {
 71                     while(a<=c) Map[a][b]=1,b--,a++;
 72                 }
 73                 else while(a<=c)Map[a][b]=1,a++;
 74  
 75             }
 76         }
 77         while(q.size())
 78         {
 79             s=q.front();
 80             q.pop();
 81             for(int i=0; i<4; i++)
 82             {
 83                 ss.x=s.x+xy[i][0];
 84                 ss.y=s.y+xy[i][1];
 85                 ss.t=s.t+1;
 86                 if(ss.x>=1&&ss.x<=n&&ss.y>=1&&ss.y<=m&&ss.t<=t&&Map[ss.x][ss.y]==0)
 87                 {
 88                     sum++;
 89                     Map[ss.x][ss.y]=1;
 90                     q.push(ss);
 91                 }
 92             }
 93         }
 94         printf("%d\n",sum);
 95     }
 96 }
 97  
 98 /**************************************************************
 99     Problem: 1569
100     User: star_sky
101     Language: C++
102     Result: Accepted
103     Time:944 ms
104     Memory:2488 kb
105 ****************************************************************/
相關文章
相關標籤/搜索