Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

帖代码,搞了半天的贪心,最后终于A了,可是好像做错题了。

Posted by cyb19950118 at 2014-08-22 17:04:59 on Problem 1089
#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
#include <algorithm>

using namespace std;

const int EM = 50003;
const int INF = 1e9+7;

struct node {
    int u, v;
};
node edge[EM];

bool cmp(node a, node b) {
    if (a.u == b.u)
        return a.v > b.v;
    return a.u < b.u;
}

int main() {
    int n;
    int cnt = 0;

    scanf("%d", &n);
    while (n--) {
        scanf("%d %d", &edge[cnt].u, &edge[cnt].v);
        cnt++;
    }
    sort(edge, edge + cnt, cmp);
    printf("%d ", edge[0].u);
    int end = edge[0].v;
    for (int i = 1; i < cnt; i++) {
        if (edge[i].u > end) {
            printf("%d\n", end);
            printf("%d ", edge[i].u);
            end = edge[i].v;
        }
        else if (edge[i].v > end)
            end = edge[i].v;
    }
    printf("%d\n", end);
    return 0;
}




Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator