Hdu 5493 合肥网络赛 1010 Queue

在线求第k大,第一次用二分+树状数组写。。。比赛的时候分治啊,splay啊,主席树啊换来换去,然而以前为什么不知道可以这么写。。。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <cmath>
 6 #include <vector>
 7 #include <set>
 8 #define inf 1000000007
 9 #define maxn 100002
10
11 using namespace std;
12
13 int n;
14 int seq[maxn];
15
16 struct peo
17 {
18     int h,x;
19     friend bool operator <(peo a, peo b)
20     {
21         return a.h<b.h;
22     }
23 }a[maxn];
24
25 struct bit
26 {
27     int b[maxn];
28     int num;
29     void add(int x,int z)
30     {
31         for (int i=x;i<=num;i+=(i&-i)) b[i]+=z;
32     }
33     int ask(int x)
34     {
35         int tmp=0;
36         for (int i=x;i;i-=(i&-i)) tmp+=b[i];
37         return tmp;
38     }
39     void init(int n)
40     {
41         num=n;
42         memset(b,0,sizeof(b));
43     }
44 }s;
45
46 int main()
47 {
48     int Case;
49     scanf("%d",&Case);
50     for (int o=1;o<=Case;o++)
51     {
52         int flag=1;
53         scanf("%d",&n);
54         for (int i=1;i<=n;i++)
55             scanf("%d%d",&a[i].h,&a[i].x);
56         sort(a+1,a+n+1);
57         s.init(n);
58         for (int i=1;i<=n;i++) s.add(i,1);
59
60         for (int i=1;i<=n;i++)
61         {
62             int tmp=inf, k=a[i].x;
63             if (1<=k+1 && k+1<=n-i+1) tmp=min(tmp,k+1);
64             if (1<=n-i-k+1 && n-i-k+1<=n-i+1) tmp=min(tmp,n-i-k+1);
65             if (tmp==inf)
66             {
67                 flag=0;
68                 break;
69             }
70             int l=1,r=n, now;
71             while (l<=r)
72             {
73                 int mid=(l+r)>>1;
74                 if (s.ask(mid)>=tmp)
75                 {
76                     now=mid;
77                     r=mid-1;
78                 }
79                 else
80                     l=mid+1;
81             }
82             seq[now]=a[i].h;
83             s.add(now,-1);
84         }
85         printf("Case #%d: ",o);
86         if (!flag) printf("impossible\n");
87         else
88             for (int i=1;i<=n;i++)
89                 if (i<n) printf("%d ",seq[i]);
90                 else printf("%d\n",seq[i]);
91     }
92     return 0;
93 }

queue

时间: 2024-08-05 06:44:55

Hdu 5493 合肥网络赛 1010 Queue的相关文章

Hdu 5489 合肥网络赛 1009 Removed Interval

跳跃式LIS(nlogn),在普通的转移基础上增加一种可以跨越一段距离的转移,用一颗新的树状数组维护,同时,我们还要维护跨越完一次后面的转移,所以我用了3颗树状数组.. 比赛的时候一句话位置写错了,然后就...雪崩 呆马: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <vector> 6 #include

HDU 5008西安网络赛B题:后缀数组求第k小子串

思路:尼玛,这题搞了一天了,比赛的时候用了n^2的方法绝对T了,然后今天看别人代码看了一天才知道.后面感觉也挺容易的,就是没想到,之前做过SPOJ 694 705求过不同子串了,知道怎么求不同子串个数了,但是比赛的时候这个技巧竟然抛在脑后了,然后就不会了. 但是今天自己用了自己的两个后缀数组的模板(倍增和DC3)的都WA了,搞得自己真想跳楼去了!! 到现在都不知道到底是哪里错了,处理的方法和标准做法都一样,但是就是WA,然后用了别人的模板,再用自己的处理方法就过了,怀疑自己的两个模板是不是哪里错

2015合肥网络赛 HDU 5492 Find a path 动归

1 #include <iostream> 2 #include <cstdio> 3 #include <fstream> 4 #include <algorithm> 5 #include <cmath> 6 #include <deque> 7 #include <vector> 8 #include <queue> 9 #include <string> 10 #include <cs

2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 1010

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

hdu 6194 沈阳网络赛--string string string(后缀数组)

题目链接 Problem Description Uncle Mao is a wonderful ACMER. One day he met an easy problem, but Uncle Mao was so lazy that he left the problem to you. I hope you can give him a solution.Given a string s, we define a substring that happens exactly k time

hdu 6444 网络赛 Neko&#39;s loop(单调队列 + 裴蜀定理)题解

题意:有编号为0~n-1的n个游戏,每个活动都有一个价值(可为负),给你m,s和k,你可以从任意一个编号开始玩,但是下一个游戏必须是编号为(i + k)%n的游戏,你最多能玩m次游戏,问你如果最后你手里要有s的价值,那么你至少一开始要有多少价值. 思路:由裴蜀定理可以知道,如果有n个值首尾相连,间隔为k地走,那么最后会有一个循环节,这样的循环节一共有gcd(n, k)个,每个循环节长度n / gcd(n, k)个.所以我们只要找出所有循环节,并且把每个循环节的最大价值算出来就行了.对于每个循环节

HDU 5024 Wang Xifeng&#39;s Little Plot(2014广州网络赛1003)

写了1h的DFS,简直被自己的代码吓哭了..不过起码还是思路清晰,QUQ~ 说一下题意吧: 题意是求一条最长路,最多能经过一次转弯,并且其角度只能为90度. 拿第一个样例来说:(0,1)->(1,2)->[转弯](2,1) ,所以答案是3. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5024 代码如下: #include<iostream> #include<cstdio> #include<cstring>

hdu 5023 A Corrupt Mayor&#39;s Performance Art(广州网络赛)

A Corrupt Mayor's Performance Art                                                                  Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others) Total Submission(s): 341    Accepted Submission(s): 150 Problem D

HDU - 4734 F(x) (2013成都网络赛,数位DP)

题意:求0-B的满足<=F[A]的所有可能 思路:数位DP,记忆化搜索 #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; int A, B; int dp[20][200000]; int bit[20]; int dfs(int cur, int num, int flag) { if (cur == -