Zoj 3465 The Hive (simulation)

Source: Internet
Author: User

Given a nest structure, let's simulate beebot production. N Bees produce 26 types of honey and specify to produce honey in a certain column. Once the honey is produced in a certain column, the honey runs from the top to the bottom. If the column is full, it will never be installed. If the following types of honey are the same, a candy is generated. How many candy can be produced at the end?

Solution: simply simulate a question. First, create a table for the honeycomb structure, and then use the stack to simulate each input, finally, the output is a honeycomb with honey.

Test data: 14
EA
EB
EC
ED
EE
EF
EG
EH
EI
EJ
EK
EK
EG
EL

11
EA
EA
EA
EA
EA
EA
EA
EA
EA
EA
EA

11
DA
DA
DA
DA
DA
DA
DA
DA
DA
DA
DA

11
IA
IA
IA
IA
IA
IA
IA
IA
IA
IA
IA


Code:
[Csharp]
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
 
Int st [40] [40];
Int top [40], n, m, ans;
Char candy [11000];
Char hive [40] [40];
Char ori [40] [40] = {
"",
"_",
"_/\\_",
"_/\\_/\\_",
"_/\\_/\\_/\\_",
"_/\\_/\\_/\\_/\\_",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"\\_/\\_/\\_/\\_/",
"\\_/\\_/\\_/",
"\\_/\\_/",
"\\_/",
};
 
 
Int main ()
{
Int I, j, k, tpcol, tp, colsum;



While (scanf ("% d", & n )! = EOF ){

Ans = 0;
Memcpy (hive, ori, sizeof (ori ));
Memset (top, 0, sizeof (top ));
For (I = 0; I <n; ++ I ){

Scanf ("% s", candy );
Tpcol = (candy [0]-'A' + 1) * 2-1;
Colsum = 11-abs (9-tpcol)/2;
Tp = candy [1]-'A ';

// Use stack operations to simulate the computing of candy count
If (top [tpcol] = 0 ){

Top [tpcol] ++;
St [tpcol] [top [tpcol] = tp;
}
Else if (top [tpcol] <colsum ){

If (st [tpcol] [top [tpcol] = tp)
Top [tpcol] --, ans ++;
Else st [tpcol] [++ top [tpcol] = tp;
}
}
 
 
Printf ("The number of candy is % d. \ n", ans );
// Change the content of the peak nest
For (I = 1; I <= 17; I + = 2) {// column

Int tpmin = 2 + abs (I-9)/2;
Int tpmax = 22-abs (I-9)/2;
For (k = 1, j = tpmax; k <= top [I]; j-= 2, ++ k)
Hive [j] [I] = st [I] [k] + 'a'; // printf ("% d \ n", j, I ),
}


For (I = 1; I <= 23; ++ I)
Printf ("% s \ n", hive [I]);
} Www.2cto.com
}


Author: woshi250hua

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.