Qualification round problem A. Bot trust-Simulation

Source: Internet
Author: User

This is a simulation. This Goole code jam has two simulations, and Problem B is also

I don't know if I don't know. I only know that the simulation is so annoying when I do it. There are still a lot of details to consider. This question can be quite time-consuming.

The second is even more sad ~~~~ How can I make a mistake? Although the question is not very clear, let's say it back.

I learned this question. Do not easily write the code when you are not clear about your ideas.

There was a problem with how to adjust it. It was like this at the beginning, and then it was overwritten. ^-^

Code:

# Include <iostream> <br/> # include <cmath> </P> <p> using namespace STD; </P> <p> struct ELEM {<br/> char C; <br/> int Bot; <br/> bool CLI; <br/> }; </P> <p> int main () <br/>{< br/> int tcase; <br/> int N, PI; <br/> char ch; <br/> int BT, ot; <br/> int o_pos, B _pos; <br/> int temp, temp1; <br/> ELEM ob [0, 105], bb [105]; <br/> ELEM * (p [105]); <br/> int top1, top2; <br/> int nexto, nextb; <br/> int I; <br/> int walk = 0; <br/> file * In, * o Ut; <br/> In = freopen ("A-large.in", "r", stdin); <br/> out = freopen ("A-large.txt", "W", stdout ); <br/> CIN> tcase; <br/> while (tcase --) {<br/> CIN> N; <br/> top1 = top2 = 0; <br/> ob [0]. BOT = 1; ob [0]. CLI = true; <br/> BB [0]. BOT = 1; bb [0]. CLI = true; <br/> for (I = 0; I <n; I ++) {<br/> CIN> CH> PI; <br/> If (CH = 'O') {<br/> P [I] = & ob [top1]; <br/> ob [top1]. C = CH; <br/> ob [top1]. CLI = true; <br/> ob [top1 ++ ]. BOT = PI; <br/>}< br/> If (CH = 'B') {<br/> P [I] = & BB [top2]; <br/> BB [top2]. C = CH; <br/> BB [top2]. CLI = true; <br/> BB [top2 ++]. BOT = PI; <br/>}< br/> bt = ot = 0; <br/> B _pos = o_pos = 1; <br/> nexto = nextb = 0; <br/> temp1 = 0; <br/> for (I = 0; I <n; I ++) {<br/> If (P [I]-> C = 'O') {<br/> temp = ABS (P [I]-> bot-o_pos ); <br/> ot + = temp + 1; <br/> o_pos = P [I]-> Bot; <br/> nexto ++; <br/> P [I]-> CLI = false; <B R/> If (BB [nextb-1]. CLI & B _pos = BB [nextb]. BOT) | nextb = top2) {<br/> Bt + = temp + 1; <br/>}< br/> else {<br/> If (temp + 1 <(temp1 = ABS (BB [nextb]. bot-b_pos) {<br/> B _pos = B _pos + (BB [nextb]. BOT> B _pos? (Temp + 1) :(-temp-1); <br/> Bt + = temp + 1; <br/>}< br/> else {<br/> B _pos = BB [nextb]. bot; <br/> Bt + = temp + 1; <br/> // nextb ++; <br/>}< br/> If (P [I]-> C = 'B ') {<br/> temp = ABS (P [I]-> bot-b_pos); <br/> Bt + = temp + 1; <br/> B _pos = P [I]-> Bot; <br/> nextb ++; <br/> P [I]-> CLI = false; & lt; br/& gt; If (OB [nexto-1]. CLI & o_pos = ob [nexto]. BOT) | nexto = top1) {<br/> ot + = temp + 1; <br/>}< br/> else {<br/> If (Te MP + 1 <(temp1 = ABS (OB [nexto]. bot-o_pos) {<br/> o_pos = o_pos + (OB [nexto]. Bot> o_pos? (Temp + 1) :(-temp-1); <br/> ot + = temp + 1; <br/>}< br/> else {<br/> o_pos = ob [nexto]. bot; <br/> ot + = temp + 1; <br/> // nexto ++; <br/>}< br/>}// cout <"o_pos:" <o_pos <''<ot <" B _pos: "<B _pos <'' <BT <Endl; <br/>}< br/> If (P [n-1]-> C = 'O ') <br/> cout <"case #" <++ walk <":" <ot <Endl; <br/> else cout <"case #" <++ walk <":" <BT <Endl; <br/>}< br/> fclose (in); <br/> fclose (out); <br /> Return 0; <br/>}# include <iostream> <br/> # include <cmath> </P> <p> using namespace STD; </P> <p> struct ELEM {<br/> char C; <br/> int Bot; <br/> bool CLI; <br/> }; </P> <p> int main () <br/>{< br/> int tcase; <br/> int N, PI; <br/> char ch; <br/> int BT, ot; <br/> int o_pos, B _pos; <br/> int temp, temp1; <br/> ELEM ob [0, 105], bb [105]; <br/> ELEM * (p [105]); <br/> int top1, top2; <br/> int nexto, nextb; <br/> int I; <br/> int walk = 0; <br/> file * In, * out; <br/> In = freopen ("A-large.in", "r", stdin ); <br/> out = freopen ("A-large.txt", "W", stdout); <br/> CIN> tcase; <br/> while (tcase --) {<br/> CIN> N; <br/> top1 = top2 = 0; <br/> ob [0]. BOT = 1; ob [0]. CLI = true; <br/> BB [0]. BOT = 1; bb [0]. CLI = true; <br/> for (I = 0; I <n; I ++) {<br/> CIN> CH> PI; <br/> If (CH = 'O') {<br/> P [I] = & ob [top1]; <br/> ob [top1]. C = CH; <br/> ob [top1]. CLI = T Rue; <br/> ob [top1 ++]. BOT = PI; <br/>}< br/> If (CH = 'B') {<br/> P [I] = & BB [top2]; <br/> BB [top2]. C = CH; <br/> BB [top2]. CLI = true; <br/> BB [top2 ++]. BOT = PI; <br/>}< br/> bt = ot = 0; <br/> B _pos = o_pos = 1; <br/> nexto = nextb = 0; <br/> temp1 = 0; <br/> for (I = 0; I <n; I ++) {<br/> If (P [I]-> C = 'O') {<br/> temp = ABS (P [I]-> bot-o_pos ); <br/> ot + = temp + 1; <br/> o_pos = P [I]-> Bot; <br/> nexto ++; <br/> P [I]-> CLI = false; <br/> If (BB [nextb-1]. CLI & B _pos = BB [nextb]. BOT) | nextb = top2) {<br/> Bt + = temp + 1; <br/>}< br/> else {<br/> If (temp + 1 <(temp1 = ABS (BB [nextb]. bot-b_pos) {<br/> B _pos = B _pos + (BB [nextb]. BOT> B _pos? (Temp + 1) :(-temp-1); <br/> Bt + = temp + 1; <br/>}< br/> else {<br/> B _pos = BB [nextb]. bot; <br/> Bt + = temp + 1; <br/> // nextb ++; <br/>}< br/> If (P [I]-> C = 'B ') {<br/> temp = ABS (P [I]-> bot-b_pos); <br/> Bt + = temp + 1; <br/> B _pos = P [I]-> Bot; <br/> nextb ++; <br/> P [I]-> CLI = false; & lt; br/& gt; If (OB [nexto-1]. CLI & o_pos = ob [nexto]. BOT) | nexto = top1) {<br/> ot + = temp + 1; <br/>}< br/> else {<br/> If (Te MP + 1 <(temp1 = ABS (OB [nexto]. bot-o_pos) {<br/> o_pos = o_pos + (OB [nexto]. Bot> o_pos? (Temp + 1) :(-temp-1); <br/> ot + = temp + 1; <br/>}< br/> else {<br/> o_pos = ob [nexto]. bot; <br/> ot + = temp + 1; <br/> // nexto ++; <br/>}< br/>}// cout <"o_pos:" <o_pos <''<ot <" B _pos: "<B _pos <'' <BT <Endl; <br/>}< br/> If (P [n-1]-> C = 'O ') <br/> cout <"case #" <++ walk <":" <ot <Endl; <br/> else cout <"case #" <++ walk <":" <BT <Endl; <br/>}< br/> fclose (in); <br/> fclose (out); <br/> return 0; <br/>}

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.