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

随便暴力都能过

Posted by zhaohailin at 2017-04-18 20:30:48 on Problem 1456
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <cstdlib>
#include <algorithm>
#define max(a,b) (a>b?a:b)
using namespace std;
struct node {
    int x,y;
}k[10005];
int vis[10005];
int cmp(node x,node y){
    if(x.x==y.x)return x.y>y.y;
    return x.x>y.x;
}
int erfen(int u){
    int r=u-1;
    while(r>=0){
        if(vis[r])r--;
        else break;
    }
    return r;
}
int main(){
    int n;
    while(cin>>n){
        int sum=0;
        for(int i=0;i<n;i++){
            scanf("%d%d",&k[i].x,&k[i].y);
        }
        sort(k,k+n,cmp);
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++){
//            cout<<k[i].x<<" "<<k[i].y<<endl;
            int t=erfen(k[i].y);
            if(t!=-1){
//                cout<<k[i].x<<" "<<k[i].y<<" "<<t<<endl;
                sum+=k[i].x;
                vis[t]=1;
            }
        }
        printf("%d\n",sum);
    }
    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