[editorial] 10월 11일 대회 소스코드 입니다.

  • astein
    astein

    소스코드 저장을 안해두니까 제가 다 짜서 올려야 하는군요 -_-;;;
    A번 소스 코드.
    [spoiler="더 보기..."]

    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <iostream>
    using namespace std;
    int card[4][13];
    int sum[4];
    int dsum[14];
    string suit[4] = {"Spades", "Hearts", "Diamonds", "Clubs"};
    string no = "23456789TJQKA";
    string go() {
        int hcp = 0;
        for (int i = 9; i < 13; i++) 
            for (int j = 0; j < 4; j++) 
                hcp += card[j][i] * (i - 8);
        // rule 1
        if (hcp >= 10) 
            for (int i = 0; i < 4; i++) 
                if (sum[i] >= 8) return "4 " + suit[i];
        // rule 2
        if (hcp >= 10 && hcp <= 13) 
            for (int i = 0; i < 4; i++) 
                if (sum[i] == 7) return "3 " + suit[i];
        // rule 3
        if (hcp >= 8 && hcp <= 9)
            for (int i = 0; i < 2; i++) // Spades or Hearts
                if (sum[i] >= 7) return "2 " + suit[i];
        // rule 4
        if (hcp >= 8 && hcp <= 11)
            for (int i = 0; i < 2; i++) // Spades or Hearts
                if (sum[i] == 6) return "2 " + suit[i];
        // rule 5
        if (hcp >= 11 && hcp <= 15) {
            if ((dsum[4] == 3 && dsum[1] == 1) || // 4-4-4-1
                (dsum[5] == 1 && dsum[4] == 2)) { // 5-4-4-0
                if (sum[0] >= 4) return "2 Diamonds";
            }
        }
        // rule 6
        if (hcp >= 15 && hcp <= 17) {
            if ((dsum[4] == 1 && dsum[3] == 3) || // 4-3-3-3
                (dsum[4] == 2 && dsum[3] == 1) || // 4-4-3-2
                (dsum[5] == 1 && dsum[3] == 2)) { // 5-3-3-2
                int stopped = 0;
                for (int i = 0; i < 4; i++) {
                    if ((card[i][12] == 1) ||
                        (card[i][11] == 1 && sum[i] >= 2) ||
                        (card[i][10] == 1 && sum[i] >= 3) ||
                        (card[i][9] == 1 && sum[i] >= 4)) stopped++;
                }
                if (stopped >= 3) return "1 No Trump";
            }
        }
        // rule 7
        if (hcp >= 20 && hcp <= 22) {
            if ((dsum[4] == 1 && dsum[3] == 3) || // 4-3-3-3
                (dsum[4] == 2 && dsum[3] == 1) || // 4-4-3-2
                (dsum[5] == 1 && dsum[3] == 2)) { // 5-3-3-2
                return "2 No Trump";
            }
        }
        // rule 8
        if (hcp >= 22) return "2 Clubs";
        // rule 9
        if (hcp >= 13 && hcp <= 16) {
            if (sum[0] >= 5 || sum[1] >= 5) {
                if (sum[0] >= sum[1]) return "1 Spades";
                return "1 Hearts";
            }
            if (sum[2] >= sum[3]) return "1 Diamonds";
            return "1 Clubs";
        }
        // reverse-rule
        if (hcp >= 17) {
            for (int i = 13; i >= 0; i--) 
                if (dsum[i] != 0) 
                    for (int j = 3; j >= 0; j--) 
                        if (sum[j] == i) return "1 " + suit[j];
        }
        return "Pass";
    }
    int main() {
        int Q = 0;
        while (true) {
            memset(card, 0, sizeof(card));
            memset(sum, 0, sizeof(sum));
            memset(dsum, 0, sizeof(dsum));
            for (int i = 0; i < 13; i++) {
                string s;
                if (!(cin >> s)) return 0;
                int a, b;
                for (int j = 0; j < 4; j++)
                    if (suit[j][0] == s[0]) a = j;
                for (int j = 0; j < 13; j++)
                    if (no[j] == s[1]) b = j;
                card[a][b]++; sum[a]++;
            }
            for (int i = 0; i < 4; i++) 
                dsum[sum[i]]++;
            printf("Hand #%d: %s\n", ++Q, go().c_str());
        }
    }
    

    [/spoiler]
    B번 소스 코드.
    [spoiler="더 보기.."]

    #include <cstdio>
    using namespace std;
    int main() {
        int N, w, d, m;
        while (scanf("%d %d %d %d", &N, &w, &d, &m) == 4) {
            int t = (N * (N - 1) / 2) * w;
            printf("%d\n", (t == m) ? (N) : ((t - m) / d));
        }
    }
    

    [/spoiler]
    C번 소스 코드.
    [spoiler="더 보기..."]

    #include <algorithm>
    #include <cstdio>
    using namespace std;
    pair<int, int> a[5001];
    pair<int, int> b[5001];
    void go(int f, int s) {
        if (f == 0) {
            if (a[s].second == 1) {
                for (int i = 0; i < s; i++) printf("|");
            } else {
                go(0, a[s].second);
                printf("x");
                go(0, s / a[s].second);
            }
        } else {
            if (b[s].second == 0) {
                go(0, s);
            } else {
                go(1, s - b[s].second);
                printf("+");
                go(1, b[s].second);
            }
        }
    }
    int main() {
        for (int i = 1; i <= 5000; i++) {
            a[i] = make_pair(i, 1);
            for (int j = 2; j * j <= i; j++) {
                if ((i % j) != 0) continue;
                if (a[j].first + a[i / j].first + 2 < a[i].first) {
                    a[i].first = a[j].first + a[i / j].first + 2;
                    a[i].second = j;
                }
            }
        }
        for (int i = 1; i <= 5000; i++) {
            b[i] = make_pair(a[i].first, 0);
            for (int j = 1; 2 * j <= i; j++) {
                if (b[j].first + b[i - j].first + 2 < b[i].first) {
                    b[i].first = b[j].first + b[i - j].first + 2;
                    b[i].second = j;
                }
            }
        }
        int N;
        while (scanf("%d", &N) == 1) {
            printf("%d toothpicks: ", b[N].first);
            go(1, N);
            printf("=%d\n", N);
        }
    }
    

    [/spoiler]
    D번 소스 코드.
    [spoiler="더 보기..."]

    #include <cstdio>
    #include <vector>
    #include <algorithm>
    using namespace std;
    vector <pair<int, int> > g;
    vector <int> a, c;
    int go(vector<int> a) {
        vector <int> r;
        for (int i = 0; i < a.size(); i++) {
            int pos = lower_bound(r.begin(), r.end(), a[i]) - r.begin();
            if (pos == r.size()) 
                r.push_back(a[i]);
            else
                r[pos] = a[i];
        }
        return a.size() - r.size();
    }
    int main() {
        int n;
        while (scanf("%d", &n) == 1) {
            if (n == 0) break;
            g.resize(n);
            for (int i = 0; i < n; i++) {
                scanf(" %d %d", &g[i].first, &g[i].second);
                g[i].first--;
                g[i].second--;
            }
            a.clear();
            c.assign(n, 0);
            int now = 0;
            while (true) {
                if (c[now] == 1) break;
                a.push_back(now);
                c[now] = 1;
                now = ((c[g[now].first] == 0) ? g[now].first : g[now].second);
            }
            if (a.size() == n) {
                printf("Knot solvable.\n");
                int ret = n;
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) 
                        c[(a[j] + i) % n] = j;
                    ret <?= go(c); 
                    reverse(c.begin(), c.end());
                    ret <?= go(c);
                }
                printf("%d\n", ret);
            } else {
                printf("Not solvable.\n");
            }
        }
    }
    

    [/spoiler]
    E번 소스 코드.
    [spoiler="더 보기..."]
    [code]
    #include
    #include
    using namespace std;
    int main() {
    int n;
    while (scanf("%d", &n) == 1) {
    if (n == 0) break;
    vector a(n, 0);
    for (int i = 0; i < n; i++) {
    int v;
    scanf("%d", &v);
    for (int j = 0; j < n; j++) {
    if (a[j] == 0) {
    if (v == 0) {
    a[j] = i + 1;
    break;
    }
    v--;
    }
    }
    }
    for (int i = 0; i < n - 1; i++)
    printf("%d,", a[i]);
    printf("%d\n", a[n - 1]);
    }
    }
    [/code]
    [/spoiler]
    F번 소스 코드.
    [spoiler="더 보기..."]

    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <cstring>
    using namespace std;
    struct triplet {
        int a, b, c;
        triplet(int ia = 0, int ib = 0, int ic = 0) : a(ia), b(ib), c(ic) {}
    };
    int a[61][61][61];
    int b[61][61][61];
    int c[61][61][61];
    int main() {
        memset(a, -1, sizeof(a));
        queue<triplet> Q;
        for (int i = 0; i <= 20; i++) {
            Q.push(triplet(i, i, i));
            a[i][i][i] = i;
            b[i][i][i] = i;
            c[i][i][i] = i;
        }
        while (!Q.empty()) {
            triplet now = Q.front(), next; Q.pop();
            for (int i = 0; i < 3; i++) {
                int half;
                if (i==0) half=now.a; else if (i==1) half=now.b; else half=now.c;
                if (half % 2 == 1) continue; else half /= 2;
                for (int j = 0; j < 3; j++) {
                    if (i == j) continue;
                    next = now;
                    if (i==0) next.a-=half; else if (i==1) next.b-=half; else next.c-=half;
                    if (next.a < 0 || next.b < 0 || next.c < 0) continue;
                    if (j==0) next.a+=half; else if (j==1) next.b+=half; else next.c+=half;
                    if (a[next.a][next.b][next.c] == -1) {
                        a[next.a][next.b][next.c] = now.a;
                        b[next.a][next.b][next.c] = now.b;
                        c[next.a][next.b][next.c] = now.c;
                        Q.push(next);
                    }
                }
            }
        }
        int x, y, z, nx, ny, nz;
        while (scanf("%d %d %d", &x, &y, &z) == 3) {
            while (x != -1) {
                printf("%4d%4d%4d\n", x, y, z);
                nx = a[x][y][z]; ny = b[x][y][z]; nz = c[x][y][z];
                if (x == nx && y == ny && z == nz) break;
                x = nx, y = ny, z = nz;
            }
            printf("============\n");
        }
    }
    

    [/spoiler]
    G번 소스 코드.
    [spoiler="더 보기..."]

    #include <cstdio>
    #include <vector>
    #include <algorithm>
    using namespace std;
    #define EPS 1e-9
    #define abs(x) (((x) > 0) ? (x) : -(x))
    struct Point {
        double x, y;
        Point(double a = 0.0, double b = 0.0) : x(a), y(b) {}
        bool operator == (const Point &a) const {
            return (abs(x - a.x) < EPS) && (abs(y - a.y) < EPS);
        }
    };
    bool lowerLeft(const Point& a, const Point& b)
    {
       if (a.y < b.y) return true;
       if (a.y > b.y) return false;
       if (a.x < b.x) return true;
       if (a.x > b.x) return false;
       return false;
    }
    inline double isLeft(const Point& p0, const Point& p1, const Point& p2)
    {
       return ( (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y) );
    }
    double dist(const Point& a, const Point& b)
    {
       return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
    }
    Point o;
    bool angleComp(const Point& a, const Point& b)
    {
       double v = isLeft(o, a, b);
       if (v > 0) return true;
       if (v < 0) return false;
       return dist(o, a) < dist(o, b);
    }
    vector<Point> convex(vector<Point> a)
    {
        if (a.size() < 3) return a;
        vector<Point> r;
        r.clear();
        int n = a.size();
        sort(a.begin(), a.end(), lowerLeft);
        a.erase(unique(a.begin(), a.end()), a.end());
        o = a[0];
        sort(a.begin() + 1, a.end(), angleComp);
        a.push_back(a[0]);
        int top = 2;
        r.push_back(a[0]);
        r.push_back(a[1]);
        for (int i = 2; i <= n; i++) {
            while(top > 1 && isLeft(r[top - 2], r[top - 1], a[i]) <= 0) {
                r.pop_back();
                top--;
            }
            r.push_back(a[i]);
            top++;
        }
        r.pop_back();
        top--;
        return r;
    }
    vector <Point> a, b;
    bool check() {
        int c[3], d[3];
        for (int i = 0; i < a.size(); i++) {
            for (int j = 0; j < b.size(); j++) {
                double p;
                c[0] = c[1] = c[2] = d[0] = d[1] = d[2] = 0;
                for (int k = 0; k < a.size(); k++) {
                    p = isLeft(a[i], b[j], a[k]);
                    if (p < -EPS) c[0] = 1; else if (p > EPS) c[2] = 1; else c[1] = 1;
                }
                if (c[0] + c[2] == 2) continue;
                for (int k = 0; k < b.size(); k++) {
                    p = isLeft(a[i], b[j], b[k]);
                    if (p < -EPS) d[0] = 1; else if (p > EPS) d[2] = 1; else d[1] = 1;
                }
                if (d[0] + d[2] == 2) continue;
                if (c[0] + d[0] == 2 || d[2] + d[2] == 2) continue;
                return true;
            }
        }
        return false;
    }
    int main() {
        int n, m, Q = 0;
        while (scanf("%d %d", &n, &m) == 2) {
            if (n == 0 && m == 0) break;
            a.clear(), b.clear();
            int sx, sy, ex, ey;
            for (int i = 0; i < n; i++) {
                scanf("%d %d %d %d", &sx, &sy, &ex, &ey);
                a.push_back(Point(sx, sy));
                a.push_back(Point(sx, ey));
                a.push_back(Point(ex, sy));
                a.push_back(Point(ex, ey));
            }
            for (int i = 0; i < m; i++) {
                scanf("%d %d %d %d", &sx, &sy, &ex, &ey);
                b.push_back(Point(sx, sy));
                b.push_back(Point(sx, ey));
                b.push_back(Point(ex, sy));
                b.push_back(Point(ex, ey));
            }
            a = convex(a);
            b = convex(b);
            if (Q) printf("\n");
            printf("Case %d: ", ++Q);
            if (check()) {
                printf("It is possible to separate the two groups of vendors.\n");
            } else {
                printf("It is not possible to separate the two groups of vendors.\n");
            }
        }
    }
    

    [/spoiler]
    H번 소스 코드.
    [spoiler="더 보기..."]

    #include <cstdio>
    using namespace std;
    double a[101];
    int main() {
        int n;
        a[2] = 1.0;
        for (int i = 4; i <= 100; i += 2) 
            a[i] = a[i - 2] * (i - 2) / (i - 1);
        while (scanf("%d", &n) == 1) {
            printf("%.5lf\n", a[n]);
        }
    }
    

    [/spoiler]
    I번 소스 코드.
    [spoiler="더 보기..."]

    #include <cstdio>
    #include <string>
    #include <vector>
    #include <algorithm>
    using namespace std;
    #define REP(i, n) for(int i = 0; i < (n); ++i)
    #define sz(x) ((x).size())
    char tmp[13];
    struct Matrix {
        vector<long long> left;
        vector<long long> right;
        bool check() {
            REP(i, sz(left))
                if (left[i] != 0) return false;
            return true;
        }
    };
    int main() {
        int n;
        while (scanf("%d", &n) == 1 && n) {
            vector <string> a(n);
            vector <Matrix> T(n);
            string S = "";
            for (int i = 0; i < n; i++) {
                scanf("%s", &tmp);
                a[i] = tmp;
                S += a[i];
            }
            sort(S.begin(), S.end());
            S.erase(unique(S.begin(), S.end()), S.end());
            REP(i, n) {
                T[i].left.assign(sz(S), 0);
                T[i].right.assign(n, 0);
                REP(j, sz(a[i]))
                    T[i].left[S.find(a[i][j])]++;
                T[i].right[i] = 1;
            }
            int last = 0;
            REP(i, sz(S)) {
                bool sw = false;
                for (int j = i; j < n; j++) {
                    if (T[j].left[i] != 0) {
                        swap(T[last], T[j]);
                        sw = true;
                        break;
                    }
                }
                if (!sw) continue;
                for (int j = last + 1; j < n; j++) {
                    if (T[j].left[i] != 0) {
                        long long g = __gcd(T[last].left[i], T[j].left[i]);
                        long long l = T[last].left[i] * T[j].left[i] / g;
                        long long v1 = l / T[last].left[i];
                        long long v2 = l / T[j].left[i];
                        REP(k, sz(S)) 
                            T[j].left[k] = v1 * T[last].left[k] - v2 * T[j].left[k];
                        REP(k, n) 
                            T[j].right[k] = v1 * T[last].right[k] - v2 * T[j].right[k];
                    }
                }
                last++;
                if (last == n) break;
            }
            bool sw = false;
            REP(i, n) {
                if (T[i].check()) {
                    sw = true;
                    printf("yes\n");
                    REP(j, n) {
                        printf("%s", a[j].c_str());
                        long long v = T[i].right[j];
                        if (v < 0) printf(" L %lld\n", -v);
                        if (v > 0) printf(" R %lld\n", v);
                        if (v == 0) printf(" N 0\n");
                    }
                    break;
                }
            }
            if (!sw) printf("no\n");
        }
    }
    

    [/spoiler]

    [이 글은 과거 홈페이지에서 이전된 글입니다. 원문보기]

    17년 전
0개의 댓글이 있습니다.
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.