Leaving Auction

Leaving Auction

题目链接:http://codeforces.com/contest/749/problem/D

二分

本来以为是哪种神奇的数据结构,没想到sort+lower_bonud就解决了,妙。

这道题的精髓在于将每个人出价的最大值记录下来,最后竞拍到的一定为没有leave的人中出价最高的那个人(因为It's guaranteed that the sum of k over all question won't exceed 200 000. 所以这个操作的总复杂度不会超过200 000)。而这个人的最低出价,只需要比第二个人的最高出价高即可,此操作可以用二分。//最后不得不说scanf和cin在没有关同步之前,差别真的很大...

代码如下:

 1 #include <cstdio>
 2 #include <vector>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <set>
 6 #define pb(x) push_back(x)
 7 #define N 200005
 8 using namespace std;
 9 int n,q,k,t,biggest[N],person[N];
10 vector<int>man[N];
11 bool cmp(int a,int b){
12     return biggest[a]<biggest[b];
13 }
14 int main(void){
15     scanf("%d",&n);
16     for(int i=1;i<=n;++i){
17         int a,b;
18         scanf("%d%d",&a,&b);
19         man[a].pb(b);
20         biggest[a]=b;
21         person[i]=i;
22     }
23     sort(person+1,person+1+n,cmp);
24     scanf("%d",&q);
25     while(q--){
26         set<int>leave;
27         scanf("%d",&k);
28         for(int i=0;i<k;++i){
29             scanf("%d",&t);
30             leave.insert(t);
31         }
32         int temp[2],num=0;
33         temp[0]=temp[1]=0;
34         for(int i=n;i>=1;--i){
35             if(leave.count(person[i]))continue;
36             temp[num++]=person[i];
37             if(num==2)break;
38         }
39         if(man[temp[0]].size()==0){
40             printf("0 0\n");
41             continue;
42         }
43         if(num==2){
44             int it=*lower_bound(man[temp[0]].begin(),man[temp[0]].end(),biggest[temp[1]]);
45             printf("%d %d\n",temp[0],it);
46         }else if(num==1){
47             printf("%d %d\n",temp[0],man[temp[0]][0]);
48         }
49     }
50 }

 

转载于:https://www.cnblogs.com/barrier/p/6206190.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值