조금 늦게 후기를 작성한다.

이 라운드는 한국인인 djm03718님이 주최하셔서 굉장히 기대가 되었다.

시간도 한국인에 맞게 1시간 이른 10시 35분이어서 좋았다.

그래도 한문제밖에 못풀었다.

바로 풀이로 들어가도록 하겠다.

 

A. Cancel the trains

Problem statement

Gildong's town has a train system that has 100 trains that travel from the bottom end to the top end and 100 trains that travel from the left end to the right end. The trains starting from each side are numbered from 11 to 100, respectively, and all trains have the same speed. Let's take a look at the picture below.

The train system can be represented as coordinates on a 2D plane. The i-th train starting at the bottom end is initially at (i,0) and will be at (i,T) after T minutes, and the i-th train starting at the left end is initially at (0,i) and will be at (T,i) after T minutes. All trains arrive at their destinations after 101 minutes.

However, Gildong found that some trains scheduled to depart at a specific time, simultaneously, are very dangerous. At this time, n trains are scheduled to depart from the bottom end and mm trains are scheduled to depart from the left end. If two trains are both at (x,y) at the same time for some x and y, they will crash into each other. Therefore, he is asking you to find the minimum number of trains that should be canceled to prevent all such crashes.

**문제에 오타가 있습니다. Bold로 표시한 'canceled'가 문제 지문에서는 'cancelled'로 표기되어 있습니다.**

 

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1≤t≤100).

Each test case contains three lines. The first line of each test case consists of two integers n and m (1≤n,m≤100) — the number of trains scheduled to depart from the bottom end, and the number of trains scheduled to depart from the left end, respectively.

The second line of each test case contains n integers. Each integer is a train number that is scheduled to start from the bottom end. The numbers are given in strictly increasing order, and are between 1 and 100, inclusive.

The third line of each test case contains mm integers. Each integer is a train number that is scheduled to start from the left end. The numbers are given in strictly increasing order, and are between 1 and 100, inclusive.

 

Output

For each test case, print a single integer: the minimum number of trains that should be canceled in order to prevent all crashes.

풀이

두개의 기차가 충돌하게 되는 조건은 같은 시간에 같은 위치에서 출발한 경우가 된다.

따라서 입력되는 2개의 배열에서 같은 숫자가 나오는 횟수를 출력하면 된다.

 

#include<stdio.h>
int main()
{
    int i,j,n,m,t,train[101],train2[101],cnt=0;
    scanf("%d\n",&t);
    while(t--)
    {
        scanf("%d %d\n",&n,&m);
        for(i=0;i<n;i++)
        {
            scanf("%d",&train[i]);
        }
        for(j=0;j<m;j++)
        {
            scanf("%d",&train2[j]);
        }
        cnt=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(train[i]==train2[j]) cnt++;
                else continue;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}

[00:09 Pretest Passed(3)/Accepted]

 

한 문제만 풀었다.

B번 업솔빙 예정..

'대회 후기 > Codeforces' 카테고리의 다른 글

SIT STAR Contest 2021 practice  (0) 2021.02.08
SIT Contest A, B, C, D Editorial  (0) 2021.02.08
Codeforces Round 690 (Div.3) 후기  (0) 2020.12.20
Codeforces Round #687 (Div. 2) 후기  (2) 2020.12.01
Codeforces Round #686 (Div.3) 후기  (0) 2020.11.25

+ Recent posts