static void Main(string[] args)
        {
            int test_case = Int32 .Parse(System.Console.In.ReadLine());
            int x1, y1, x2, y2, cx, cy, r;
            int cn;
            double dis1, dis2;
            string pos_prince;
            string pos_planet;
           
            while (test_case > 0)
            {
                int count = 0;

                pos_prince = System. Console.In.ReadLine();
                string[] prince_arr = pos_prince.Split();
                x1 = Int32.Parse(prince_arr[0]);
                y1 = Int32.Parse(prince_arr[1]);
                x2 = Int32.Parse(prince_arr[2]);
                y2 = Int32.Parse(prince_arr[3]);

                cn = Int32.Parse(System.Console .In.ReadLine());

                while (cn > 0)
                {
                    pos_planet = System. Console.In.ReadLine();
                    string[] planet_arr = pos_planet.Split();
                    cx = Int32.Parse(planet_arr[0]);
                    cy = Int32.Parse(planet_arr[1]);
                    r = Int32.Parse(planet_arr[2]);

                    dis1 = Math.Sqrt(Math .Pow(x1 - cx, 2) + Math.Pow(y1 - cy, 2));
                    dis2 = Math.Sqrt(Math .Pow(x2 - cx, 2) + Math.Pow(y2 - cy, 2));

                    if (dis1 < r && dis2 > r)
                    {
                        count++;
                    }
                    else if (dis1 > r && dis2 < r)
                    {
                        count++;
                    }

                    cn--;
                }

                System. Console.Out.WriteLine(count);

                test_case--;
            }

        }



[문제]

https://www.acmicpc.net/problem/1004


[풀이]

문제를 간략화 시켜 보면 편하다. 예시의 경우를 보면 다음과 같은데,

어린 왕자가 진입/이탈하는 행성을 보면

1)어린 왕자가 속해있는 행성

2)별다방이 속해 있는 행성

이 두가지 경우 뿐이다. 다른 행성은 무시하면 된다.

문제 조건에서 행성이 겹치는 경우가 없다고 제시하였으므로 행성이 주어지면 이를 하나하나 검사하며

1)어린 왕자가 속해있으면서 별다방은 속해있지 않은지? => 이탈 횟수 1

2)어린 왕자가 속해있지 않으면서 별다방은 속해있는지? => 진입 횟수 1

3)어린 왕자와 별다방 모두 속해있는지? => 0

4)어린 왕자와 별다방 모두 속해있지 않은지? => 0

을 따지면 된다.


속해있는지 속해있지 않은지 검사하는 공식은 원의 중점 좌표와 어린왕자 또는 별다방의 좌표와의 거리를 구한 후 해당 원의 반지름보다 짧으면 속해있다고 확인할 수 있다.




Posted by Righ
,
  static int zero_case = 0;
        static int one_case = 0;
        static void Main(string[] args)
        {
            int test_case = Int32 .Parse(System.Console.In.ReadLine());
           
            while (test_case > 0)
            {
                int n = Int32 .Parse(System.Console.In.ReadLine());
                zero_case = 0;
                one_case = 0;
                fibonacci(n);
                System. Console.Out.WriteLine(zero_case + " " + one_case);

                test_case--;
               
            }

        }

        static int fibonacci(int n)
        {
            if (n == 0)
            {
                zero_case++;
                return 0;
            }
            else if (n == 1)
            {
                one_case++;
                return 1;
            }
            else
            {
                return fibonacci(n - 1) + fibonacci(n - 2);
            }

        }



[문제]

https://www.acmicpc.net/problem/1003


[풀이]

처음엔 클래스를 하나 생성해서 그 안에 set,get 함수 fibonacci 함수를 멤버 함수로 만들어서 제출했으나, 시간초과 에러가 떴다.

그 후엔 멤버 변수를 public으로 선언하여 바로 접근하게 했지만 그래도 시간 초과 에러가 뜬다.

그래서 모든 변수와 함수를 static으로 선언하여 ( Main함수가 static 함수 이므로 static 변수와 함수에만 접근 가능 ) 걸리는 시간을 단축하였다. 이것이 문제에서 원하는 해결 방안인지는 확신하지 못하겠다.


Posted by Righ
,
        static void Main(string[] args)
        {
            short x1, x2, y1, y2, r1, r2;
            short test_case = short .Parse(System.Console.In.ReadLine());

            while (test_case != 0)
            {
                string pos_input = System.Console .In.ReadLine();
                string[] pos_array = pos_input.Split();
                x1 = short.Parse(pos_array[0]);
                y1 = short.Parse(pos_array[1]);
                r1 = short.Parse(pos_array[2]);
                x2 = short.Parse(pos_array[3]);
                y2 = short.Parse(pos_array[4]);
                r2 = short.Parse(pos_array[5]);

                double distance = Math .Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));

                if (distance == 0 && r1 == r2)
                {
                    System. Console.Out.WriteLine(-1);
                }
                else if (distance < Math.Abs(r1 - r2))
                {
                    System. Console.Out.WriteLine(0);
                }
                else if (distance == Math.Abs(r1 - r2))
                {
                    System. Console.Out.WriteLine(1);
                }
                else if (distance < r1 + r2)
                {
                    System. Console.Out.WriteLine(2);
                }
                else if (distance == r1 + r2)
                {
                    System. Console.Out.WriteLine(1);
                }
                else if (distance > r1 + r2)
                {
                    System. Console.Out.WriteLine(0);
                }

                test_case--;
            }

        }


[문제]

https://www.acmicpc.net/problem/1002


[풀이]

중학교 때 풀던 수학문제를 생각 하면 된다


두 점이 주어지고 각 점에서의 거리 r이 각각 주어졌으므로, 두 점을 중심으로 하고 각각 r을 반지름으로 하는 두 원이 몇 개의 점에서 만나는지 찾으면 된다.

경우의 수는 총 6가지.


1.두 원이 일치하는 경우


d = 0 이고 r1 = r2 가 같다. 이 경우 무한한 경우의 수가 나오므로 -1 리턴




2.작은 원이 큰 원 안에 속해 있고, 테두리가 접하지 않는 경우


r1 - r2 의 절대값이 d 보다 크다. 즉, 

이 경우 두 원이 만나지 않으므로 경우의 수는 0이다.





3.작은 원이 큰 원 안에 속해 있고, 한 점에서 접해있는 경우

r1 - r2의 절대값이 d와 같다. 즉, 

이 경우 근의 수가 1이므로 경우의 수 역시 1이다.



4.두 원이 두 점에서 만나는 경우


r1 + r2 가 d 보다 큰 경우이다. 이 경우 원은 두 점에서 만난다. 즉, 

이 경우 근의 개수가 2이므로 경우의 수도 2.



5.두 원이 겹치지 않고, 한 점에서 만나는 경우


 한 점에서 만나므로 1 리턴.



6.두 원이 만나지 않는 경우



 근이 없으므로 0 리턴.



=> 수학적 능력 보다는 해당 문제를 보고 두 원의 관계에 대한 접근으로 다가갈 수 있느냐를 판단하는 문제 인듯.



Posted by Righ
,
            String input = System.Console .In.ReadLine();
            char[] test = {' ' };
            string[] input_char = input.Split(test);
            int first = Int32 .Parse(input_char[0]);
            int second = Int32 .Parse(input_char[1]);

            System. Console.Out.WriteLine(first-second);


[문제]

https://www.acmicpc.net/problem/1001

Posted by Righ
,
String input = System.Console .In.ReadLine();
char[] test = {' ' };
string[] input_char = input.Split(test);
int first = Int32 .Parse(input_char[0]);
int second = Int32 .Parse(input_char[1]);

System. Console.Out.WriteLine(first+second);


[문제]

https://www.acmicpc.net/problem/1000

Posted by Righ
,