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:几个月前看过,但就是想不明白,今天一见,其实是很简单的题!

Posted by HG at 2009-07-12 23:54:40 on Problem 2726
In Reply To:几个月前看过,但就是想不明白,今天一见,其实是很简单的题! Posted by:alpc47 at 2008-09-30 16:14:31
无语开始我写成minPrice = 10001了
#include<iostream>
#include<algorithm>
using namespace std;
struct hotel
{
    int D;
    int C;
};
bool cmpFun(hotel a,hotel b);
hotel hs[10000];
int main()
{
    int n;
    while(cin>>n,n)
    {
        for(int i = 0 ; i  < n ; i ++)
            scanf("%d %d",&hs[i].D,&hs[i].C);
        sort(hs,hs + n,cmpFun);
        int count = 0,minPrice = 10001;
        for(int i = 0 ; i < n ; i ++)
            if(hs[i].C < minPrice)
                minPrice = hs[i].C , count ++;
        cout<<count<<endl;
    }
    return 0;
}
bool cmpFun(hotel a,hotel b)
{
    if(a.D < b.D)
        return true;
    else if(a.D == b.D)
        return a.C < b.C;
    else
        return false;
}

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