[KOI]전국본선 2014 중등부 세번째 문제





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
#include <stdio.h>
#include <algorithm>
#include <deque>
using namespace std;
 
const int MAX_SIZE = 500000;
 
struct BUS{
    int s, e, index;
};
 
bool comp(BUS a, BUS b) {
    return (a.s == b.s) ? (a.e > b.e) : (a.s < b.s);
}
 
bool comp1(BUS a, BUS b) {
    return (a.index < b.index);
}
 
BUS bus[MAX_SIZE];
 
int main()
{
    int N, M, end_point = 0;
    scanf("%d %d", &N, &M);
    for(int i = 0; i < M; ++i){
        scanf("%d %d", &bus[i].s, &bus[i].e);
        bus[i].index = i + 1;
 
        if (bus[i].s > bus[i].e) {
            end_point = max(end_point, bus[i].e);
            bus[i].e += N;
        }
    }
 
    sort(bus, bus + M, comp);
 
    deque<BUS> q;
    for (int i = 0; i < M; ++i) {
        if (q.empty() || q.back().e < bus[i].e) {
            q.push_back(bus[i]);
        }
    }
 
    while (!q.empty() && q.front().e <= end_point) {
        q.pop_front();
    }
 
    sort(q.begin(), q.end(), comp1);
 
    for (auto x : q) {
        printf("%d ", x.index);
    }
 
    return 0;
}


[KOI]전국본선 2014 중등부 두번째 문제




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
#include <stdio.h>
 
int seat[2000][2001];
 
int gcd(int a, int b) {
    return (b) ? gcd(b, a % b) : (a);
}
 
int main()
{
    int ret = 0;
    int from, to;
    scanf("%d %d", &from, &to);
    for (int i = from; i <= to; ++i) {
        for (int j = 0; j < i; ++j) {
            int g = gcd(i, j);
            int up = j / g;
            int down = i / g;
            if (seat[up][down] == 0) {
                seat[up][down] = 1;
                ++ret;
            }
        }
    }
    printf("%d\n", ret);
    return 0;
}


[KOI]전국본선 2013 중등부 두번째 문제




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
#include <stdio.h>
 
int main()
{
    int n;
    int after[30] = { 0, }, before[30] = { 0, };
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &after[i]);
    }
    int cur = 0, count = 0;
    while (count < n) {
        while (before[cur] != 0) {
            cur = (cur + 1) % n;
        }
        before[cur] = after[count++];
        cur = (before[cur] + cur) % n;
    }
 
    printf("%d\n", n);
    for (int i = 0; i < n; ++i) {
        printf("%d ", before[i]);
    }
 
    return 0;
}


[KOI]전국본선 2013 중등부 첫번째 문제





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
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
 
struct ANIMAL {
    int y, x;
};
 
vector<int> hunter;
vector<animal> animal;
 
bool comp(const ANIMAL& a, const ANIMAL& b) {
    return (a.x < b.x);
}
 
bool is_kill(const ANIMAL& a, const int h, const int len) {
    int dist = abs(a.x - h) + a.y;
    if (dist <= len)     return true;
    else                    return false;
}
 
int main()
{
    int M, N, L;
    scanf("%d %d %d", &M, &N, &L);
 
    hunter.resize(M);
    animal.resize(N);
 
    for (int i = 0; i < M; ++i) {
        scanf("%d", &hunter[i]);
    }
 
    for (int i = 0; i < N; ++i) {
        scanf("%d %d", &animal[i].x, &animal[i].y);
    }
 
    sort(hunter.begin(), hunter.end());
    sort(animal.begin(), animal.end(), comp);
 
    int ret = 0;
    for (auto ani : animal) {
        auto target = lower_bound(hunter.begin(), hunter.end(), ani.x) - hunter.begin();
        if (is_kill(ani, hunter[target], L)) {
            ++ret;
        }
        else {
            if (target > 0) {
                --target;
                if (is_kill(ani, hunter[target], L)) {
                    ++ret;
                }
            }
        }
    }
 
    printf("%d\n", ret);
     
    return 0;
}


[KOI]전국본선 2012 중등부 첫번째 문제



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
#include <stdio.h>
#include <algorithm>
using namespace std;
 
int n, money;
int city[10000];
 
bool valid(int mid) {
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        ret += min(mid, city[i]);
    }
    return (ret <= money);
}
 
int main()
{
    int left = 0, right = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &city[i]);
        right = max(right, city[i]);
    }
    scanf("%d", &money);
 
    while (left != right) {
        int mid = (left + right + 1) / 2;
        if (valid(mid)) {
            left = mid;
        }
        else {
            right = mid - 1;
        }
    }
 
    printf("%d\n", left);
 
    return 0;
}