标签:
/* 大意:n个人参加一个活动的条件有人数限制,l和r,问你最多有多少个人能一起去,把不能参加的人随便输出 用优先队列维护满足的情况 把块从0分到n,贪心地把r最小的并且满足大于等于l的值取出,注意判断如果这一次没有了,下一次也肯定没有这种情况 */ /************************************************ Author :powatr Created Time :2015-8-6 14:45:47 File Name :b.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int MAX = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; struct edge{ int l, r, id; }a[MAX]; struct edge1{ int x, y; }; edge1 P; struct cmp1 { bool operator () (edge1 x, edge1 y) { return x.x > y.x; } }; int b[MAX]; int vis[MAX]; int n; vector<edge1>G[MAX]; int main(){ int T; priority_queue < edge1 , vector<edge1> , cmp1 > q; scanf("%d", &T); while(T--){ memset(vis, 0, sizeof(vis)); scanf("%d", &n); memset(a, 0, sizeof(a)); for(int i = 1; i <= n; i++){ scanf("%d",&a[i].l); } for(int i = 0 ; i <= 100000; i++) G[i].clear(); for(int i = 1; i <= n; i++) scanf("%d",&a[i].r); for(int i = 1; i <= n; i++) a[i].id = i; // sort(a + 1, a + n + 1); while(!q.empty()) q.pop(); for(int i = 1; i <= n; i++) G[a[i].l].push_back((edge1){a[i].r, a[i].id}); for(int i = 0 ; i < G[0].size(); i++) q.push((edge1){G[0][i].x,G[0][i].y}); int ans = 1; edge1 m; if(!q.empty()){ m = q.top(); if(m.x >= 0){ b[ans++] = m.y; q.pop(); } } for(int i = 1; i <= n; i++){ for(int j = 0; j < G[i].size(); j++) q.push((edge1){G[i][j].x, G[i][j].y}); // if(ans < i + 2) break; while(!q.empty()){ m = q.top(); if(ans < i + 1) break; if(ans == i + 2) break; if(m.x >= i){ q.pop(); b[ans++] = m.y; } else q.pop(); } } printf("%d\n", ans - 1); for(int i = 1; i < ans ; i++){ printf("%d ", b[i]); vis[b[i]] = 1; } for(int i = 1 ; i <= n; i++) if(!vis[i]) printf("%d ", i); puts(""); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4708839.html