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 897843079 at 2019-09-08 11:32:10 on Problem 3614
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=3000;
struct node{
    int l,r;
}e[maxn];
int n,q,vis[maxn];
bool cmp(node a,node b){
    if(a.r==b.r)
        return a.l<b.l;
    return a.r<b.r;
}
int main(){
    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>e[i].l>>e[i].r;
    }
    sort(e,e+n,cmp);
    memset(vis,0,sizeof(vis));
    int ans=0;
    while(q--){
        int l,r;
        cin>>l>>r;
        vis[l]+=r;
    }
    for(int i=0;i<n;i++){
        for(int j=e[i].l;j<=e[i].r;j++){
            if(vis[j]>=1){
                vis[j]--;
                ans++;
                break;
                }
            }
        }
    cout<<ans<<endl;
    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