#个人赛第七场解题总结 # (Fzu 18,813 angle Problem &&fzu 1884-row train simulation)

Source: Internet
Author: User

Link: Click here~~, Password: nyist

C- triangle problem

Description

To give you a triangle of infinite nodes (for example), your task is simple-give you two positive integers x and y to determine if they are adjacent (coincident is not adjacent).

Input

The first line T, which represents the T-group test data, is followed by only two 32-bit positive integers x and Y.

Output

For each set of test data, the first output is "Case K:", where K represents the first group. Then if x and Y are adjacent, the output is "Yes", otherwise the output "No".

Sample Input

31 11 21 11

Sample Output

Case 1:nocase 2:yescase 3:no "Solving ideas":

Simulation judge, the specific look at the code, the brain a little tired, and the hand is a bit lazy, lazy write too many useless things.

Code:

#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm>using namespace    Std;__int64 A[100005];int Main () {__int64 n,m,i,j;    int t,tot=1;    A[0]=1;    for (I=1; i<100000; i++) {a[i]=i+a[i-1];    } scanf ("%d", &t);                while (t--) {scanf ("%i64d%i64d", &n,&m);                if (n>m) {swap (n,m);}        printf ("Case%d:", tot++);            if (n==m) {printf ("no\n");        Continue            } for (i=0; i<100000; i++) {if (N<a[i]) {break; }} if (N==a[i]-1) {if (m==n+i| |            m==n+i+1) {printf ("yes\n");        } else printf ("no\n"); } else {if (n==m-1| | n+1+i==m| |            n+i==m) {printf ("yes\n");        } else printf ("no\n"); }} return 0;}
D-Train line

Description

One day, Apple asked Gaga, "has the poker row train ever played?", "No-_-". Apple was so amazed that he decided to teach Gaga to play the game right away. With no poker on hand, Apple cut a few cards, then wrote the numbers on the cards, and said to Gaga, "Simply put, you have a bunch of cards, I have a bunch of cards, we take turns, each time the cards are stacked at the bottom of the previous card, if you find that the current card and the previous cards are duplicated, Then the cards are yours. In the end, whoever has no cards will lose. "Oh, that's it." Gaga doesn't think this is the case.

So they started to play the train line ...

Now suppose Apple and Gaga each have n cards, and Apple cards first. Please give the number of cards that Apple and Gaga have won in a round.

Input

The first line T, which represents the T group test data, is followed by the T section.

Each part starts with an integer n (1 <= n <= 50000) that represents the number of cards for Apple and Gaga. Next there are 2 lines that give the Apple and Gaga cards a case. Apple's cards are given first, there are n integers, and the first I integer XI (1 <= XI <= 100000) represents Apple's first card. Next gives Gaga's cards, similar in format.

Output

For each set of test data, the first output is "Case K:", where K represents the first group. Then output the number of cards that Apple and Gaga have won this round.

Sample Input

331 2 31 2 341 4 6 82 5 9 1035 5 56 6 6

Sample Output

Case 1:apple:0 Gaga:6case 2:apple:0 Gaga:0case 3:apple:3 Gaga:3

Hint

Input is huge, C + + please use scanf input to avoid timeouts.
"Problem-solving ideas": This problem is a bit risky ah, the last minute to hand in, in fact, the problem is not difficult to understand, that is, we used to play the pile of trains, the situation online Ah, now think quite nostalgic ~ ~
After the game to see the report, is a stack simulation, their own simulation, is generally found that if the same elements appear before and after the same, immediately mark, and then the number of statistics, and then loop to the last.
Code:
#include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <stack > #include <algorithm>using namespace std;const int N=100005;const double Pi=acos ( -1.0); #define LL __int64int a[    N],b[n],c[n];int Flag[n];int Main () {int t,i,j,n,m,tot=1;    scanf ("%d", &t);        while (t--) {memset (a,0,sizeof (a));        Memset (b,0,sizeof (b));        memset (flag,0,sizeof (flag));        scanf ("%d", &n);        for (I=1; i<=n; i++) scanf ("%d", &a[i]);        for (I=1; i<=n; i++) scanf ("%d", &b[i]);        int S1=0,s2=0,ss=1;                for (int i=1; i<=n; i++) {if (flag[a[i]]!=0) {s1++;                int Temp=flag[a[i]];                    for (int k=flag[a[i]]; k<ss; k++) {flag[c[k]]=0;                s1++;            } ss=temp;                } else{Flag[a[i]]=ss;            C[ss++]=a[i]; } if (flag[b[i]]!=0) {s2++;                int Temp=flag[b[i]];                    for (int k=flag[b[i]]; k<ss; k++) {flag[c[k]]=0;                s2++;            } ss=temp;                } else{Flag[b[i]]=ss;            C[ss++]=b[i];    }} printf ("Case%d:apple:%d gaga:%d\n", TOT++,S1,S2); } return 0;}

#个人赛第七场解题总结 # (Fzu 18,813 angle Problem &&fzu 1884-row train simulation)

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.