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

Re:注意了用sort不一定能过

Posted by makuiyu at 2013-12-27 10:55:02 on Problem 3664
In Reply To:注意了用sort不一定能过 Posted by:1314199210 at 2013-07-31 16:44:06
> 用C++STL sort()排序不一定能过,我已经试了,原因不明,

水过啊

#include <algorithm>
#include <iostream>
#include <string>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>

#define N 50010

using namespace std;

struct cows
{
    int i, a, b;
} c[N];

bool cmp1(cows a, cows b)
{
    return a.a > b.a;
}

bool cmp2(cows a, cows b)
{
    return a.b > b.b;
}

int main()
{
    int n, k, a, b;
    int i;
    scanf("%d %d", &n, &k);
    for(i=0; i<n; ++i)
    {
        scanf("%d %d", &a, &b);
        c[i].i = i + 1;
        c[i].a = a;
        c[i].b = b;
    }
    sort(c, c+n, cmp1);
    sort(c, c+k, cmp2);
    printf("%d\n", c[0].i);
    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