hdu 5360 贪心

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <vector>

using namespace std;
#define INF 0x2fffffff
#define LL long long
#define MAX(a,b) ((a)>(b))?(a):(b)
#define MIN(a,b) ((a)<(b))?(a):(b)
struct node{
    int x,y,i;
    bool operator < (const node& a)const{
        return y > a.y;
    }
};
node a[100005];
vector<node> vec[100005];
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;

        for(int i = 0;i < n;i++){
            scanf("%d",&a[i].x);
        }
        for(int i = 0;i < n;i++){
            scanf("%d",&a[i].y);
            a[i].i = i+1;
            vec[i].clear();
        }
        for(int i = 0;i < n;i++){
            vec[a[i].x].push_back(a[i]);
        }
        int ans = 0;
        priority_queue<node,vector<node>,less<node> > que;
        queue<int> q;
        for(ans = 0;ans < n;ans++){
            int si = vec[ans].size();
            for(int j = 0;j < si;j++){
                que.push(vec[ans][j]);
            }
            if(que.empty()) break;
            node v = que.top();

            q.push(v.i);
            que.pop();
            while(!que.empty() && que.top().y <= (ans)){
                q.push(que.top().i);

                que.pop();
            }
        }
        int flag = 0;
        printf("%d\n",ans);
        while(!q.empty()){
            if(flag == 0){
                flag = 1;
            }
            else{
                printf(" ");
            }
            printf("%d",q.front());
            q.pop();
        }
        for(ans;ans<n;ans++){
            int si = vec[ans].size();
            for(int i = 0;i < si;i++){
                if(flag == 0){
                    flag = 1;
                }
                else{
                    printf(" ");
                }
                printf("%d",vec[ans][i].i);
            }
        }
        printf("\n");
    }
    return 0;
}

不会实现啊不会实现啊

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-13 09:23:13

hdu 5360 贪心的相关文章

hdu 5360 贪心+优先队列

贪心的思路还是比较好想的,每次选择cur(已经邀请成功的人数)所在的区间中右端点最小的(因为右端点大的在后面可以邀请成功的几率大),然后很自然的想到可以用一个优先队列来维护这些区间,只要每次把左端点小于等于cur的区间放到优先队列中即可. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <vector> 5 #include <queue> 6 u

HDU 5360(2015多校6)-Hiking(优先队列)

题目地址:HDU 5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须满足c>=l[i]&&c<=ri,问你邀请的顺序是什么才能使尽可能多的人去远足,若有多个最优解,输出任意的一个. 思路:先按照L从小到到排序,把当前符合的L放入优先队列中 ,然后对队列中的R从小到大排序,贪心的选择R小的,然后乱搞一番就可以了. #include <stdio.h> #include <math.h> #includ

hdu 4105 贪心思想

淋漓尽致的贪心思想 波谷一定是一位数,波峰一位数不够大的时候添加到两位数就一定够大了的. 当在寻找波谷碰到零了就自然当成波谷. 当在寻找波峰时碰到零时,将前面的波谷加到前一个波峰上,让当前的零做波谷,使得波谷的值尽量小,这就是本题最关键的贪心思想,一直想不到. 代码中:a表示前一个值,b表示当前考虑的值,tag为偶数时表示正在寻找波谷,奇数时在寻找波峰. #include<iostream> #include<cstdio> #include<cstring> #inc

HDU 4923 (贪心+证明)

Room and Moor Problem Description PM Room defines a sequence A = {A1, A2,..., AN}, each of which is either 0 or 1. In order to beat him, programmer Moor has to construct another sequence B = {B1, B2,... , BN} of the same length, which satisfies that:

hdu 2037 贪心

今年暑假不AC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 27361    Accepted Submission(s): 14439 Problem Description "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" &quo

HDU 4932 贪心

Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 191    Accepted Submission(s): 38 Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by

hdu 4292 贪心

http://acm.hdu.edu.cn/showproblem.php?pid=4296 Problem Description Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr. Wolowitz, Dr. Blue.Mary has accomplished many great projects, one of which is the Guanghua Building. T

hdu 4442 贪心

http://acm.hdu.edu.cn/showproblem.php?pid=4442 Problem Description WANGPENG is a freshman. He is requested to have a physical examination when entering the university. Now WANGPENG arrives at the hospital. Er-.. There are so many students, and the nu

hdu 1050(贪心算法)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19278    Accepted Submission(s): 6582 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a