본문 바로가기
Computer Science

프양연 롤러코스터 / 퀵소트 유저 메인 구현

by OKOK 2018. 12. 21.

1. 유저 메인에 대한 혼동되는 것 정리 가능

2. 퀵 소트 끝

3. 어떻게 소팅할 것인지 파악 후 정리 끝

4. 오케이 집중 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<stdio.h>
//#define Max 200001
#define Max 5
 
#define Mod 1000000007
 
typedef struct {
    int a;
    int b;
    double c; // (a-1)/b why double?
}vector;
 
vector array[Max];
 
void quickSort(int first, int last)
{
    int pivot;
    int i;
    int j;
    vector temp;
 
    if (first < last)
    {
        pivot = first;
        i = first;
        j = last;
 
        while (i < j)
        {
            while (array[i].c <= array[pivot].c && i < last)
            {
                i++;
            }
            while (array[j].c > array[pivot].c)
            {
                j--;
            }
            if (i < j)
            {
                temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
        }
 
        temp = array[pivot];
        array[pivot] = array[j];
        array[j] = temp;
 
        quickSort(first, j - 1);
        quickSort(j + 1, last);
    }
}
 
 
int main(void)
{
    freopen("input.txt""r", stdin);
    setbuf(stdout, NULL);
 
    int T, N;
    scanf("%d"&T);
 
    for (int test_case = 1; test_case <= T; test_case++)
    {
        scanf("%d"&N);
 
        for (int i = 0; i < N; i++)
        {
            scanf("%d %d"&array[i].a, &array[i].b);
            array[i].c = (double)(array[i].a - 1/ (double)array[i].b;
        }
 
        quickSort(0, N - 1);
 
        long long unsigned sum = 1;
 
        for (int i = N - 1; i >= 0; i--)
        {
            sum = (array[i].a*sum % Mod + array[i].b) % Mod;
        }
        printf("#%d %d\n", test_case, sum);
    }
 
    return 0;
}
 
cs


댓글