hdu5360 Hiking(水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

Hiking

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 724    Accepted Submission(s): 384
Special Judge

Problem Description

There are n soda conveniently labeled by 1,2,…,n. beta, their best friends, wants to invite some soda to go hiking. The i-th soda will go hiking if the total number of soda that go hiking except him is no less than li and no larger than ri. beta will follow the rules below to invite soda one by one:
1. he selects a soda not invited before;
2. he tells soda the number of soda who agree to go hiking by now;
3. soda will agree or disagree according to the number he hears.

Note: beta will always tell the truth and soda will agree if and only if the number he hears is no less than li and no larger than ri, otherwise he will disagree. Once soda agrees to go hiking he will not regret even if the final total number fails to meet some soda‘s will.

Help beta design an invitation order that the number of soda who agree to go hiking is maximum.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first contains an integer n (1≤n≤105), the number of soda. The second line constains n integers l1,l2,…,ln. The third line constains n integers r1,r2,…,rn. (0≤li≤ri≤n)
It is guaranteed that the total number of soda in the input doesn‘t exceed 1000000. The number of test cases in the input doesn‘t exceed 600.

Output

For each test case, output the maximum number of soda. Then in the second line output a permutation of 1,2,…,n denoting the invitation order. If there are multiple solutions, print any of them.

Sample Input

4

8

4 1 3 2 2 1 0 3

5 3 6 4 2 1 7 6

8

3 3 2 0 5 0 3 6

4 5 2 7 7 6 7 6

8

2 2 3 3 3 0 0 2

7 4 3 6 3 2 2 5

8

5 6 5 3 3 1 2 4

6 7 7 6 5 4 3 5

Sample Output

7

1 7 6 5 2 4 3 8

8

4 6 3 1 2 5 8 7

7

3 6 7 1 5 2 8 4

0

1 2 3 4 5 6 7 8

水题,先按li排序,然后不断地塞进优先队列

  1 /**
  2  * code generated by JHelper
  3  * More info: https://github.com/AlexeyDmitriev/JHelper
  4  * @author xyiyy @https://github.com/xyiyy
  5  */
  6
  7 #include <iostream>
  8 #include <fstream>
  9
 10 //#####################
 11 //Author:fraud
 12 //Blog: http://www.cnblogs.com/fraud/
 13 //#####################
 14 //#pragma comment(linker, "/STACK:102400000,102400000")
 15 #include <iostream>
 16 #include <sstream>
 17 #include <ios>
 18 #include <iomanip>
 19 #include <functional>
 20 #include <algorithm>
 21 #include <vector>
 22 #include <string>
 23 #include <list>
 24 #include <queue>
 25 #include <deque>
 26 #include <stack>
 27 #include <set>
 28 #include <map>
 29 #include <cstdio>
 30 #include <cstdlib>
 31 #include <cmath>
 32 #include <cstring>
 33 #include <climits>
 34 #include <cctype>
 35
 36 using namespace std;
 37 #define mp(X, Y) make_pair(X,Y)
 38 #define pb(X) push_back(X)
 39 #define rep(X, N) for(int X=0;X<N;X++)
 40 #define rep2(X, L, R) for(int X=L;X<=R;X++)
 41 typedef pair<int, int> PII;
 42
 43 typedef pair<PII, int> PIII;
 44 priority_queue<PIII, vector<PIII>, greater<PIII> > q;
 45 int f[100010];
 46 int l[100010];
 47 int r[100010];
 48 vector<int> v[100010];
 49
 50 class hdu5360 {
 51 public:
 52     void solve(std::istream &in, std::ostream &out) {
 53         int n;
 54         in >> n;
 55         for (int i = 1; i <= n; i++)in >> l[i];
 56         for (int i = 1; i <= n; i++) {
 57             in >> r[i];
 58             if (l[i])v[l[i]].pb(i);
 59             else q.push(mp(mp(r[i], l[i]), i));
 60         }
 61         int num = n;
 62         int ans = 0;
 63         int sz = 0;
 64         while (n) {
 65             if (q.empty()) {
 66                 rep2(i, ans + 1, n) {
 67                     rep(j, v[i].size()) {
 68                         f[sz++] = v[i][j];
 69                     }
 70                     v[i].clear();
 71                 }
 72                 break;
 73             }
 74             PIII p = q.top();
 75             q.pop();
 76             int y = p.first.first;
 77             int x = p.first.second;
 78             int z = p.second;
 79             f[sz++] = z;
 80             if (x <= ans && y >= ans) {
 81                 ans++;
 82                 rep(i, v[ans].size()) {
 83                     int j = v[ans][i];
 84                     q.push(mp(mp(r[j], l[j]), j));
 85                 }
 86                 v[ans].clear();
 87             }
 88         }
 89         out << ans << endl;
 90         rep(i, sz) {
 91             if (i)out << " ";
 92             out << f[i];
 93         }
 94         out << endl;
 95     }
 96 };
 97
 98 int main() {
 99     std::ios::sync_with_stdio(false);
100     std::cin.tie(0);
101     hdu5360 solver;
102     std::istream &in(std::cin);
103     std::ostream &out(std::cout);
104     int n;
105     in >> n;
106     for (int i = 0; i < n; ++i) {
107         solver.solve(in, out);
108     }
109
110     return 0;
111 }
时间: 2024-09-30 14:44:15

hdu5360 Hiking(水题)的相关文章

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b

sdut 2841 Bit Problem (水题)

题目 贴这个题是因为看题解有更简单的方法, 我做的时候是直接算的, 也很简单. 贴一下题解吧: 如果一个整数不等于 0,那么该整数的二进制表示中至少有一位是 1. 这个题结果可以直接输出 x - (x&(x-1)); 因为x-1 之后二进制下,就是最右边的1变成了0, 最右边的1的 右边所有的0变成了1, 不影响最左边. 我的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4

sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst

杭电(hdu)2053 Switch Game 水题

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13113    Accepted Submission(s): 7970 Problem Description There are many lamps in a line. All of them are off at first. A series of o

4.7-4.9补题+水题+高维前缀和

题目链接:51nod 1718 Cos的多项式  [数学] 题解: 2cosx=2cosx 2cos2x=(2cosx)^2-2 2cos3x=(2cosx)^3-3*(2cosx) 数归证明2cos(nx)能表示成关于2cosx的多项式,设为f(n) f(1)=x,f(2)=x^2-2(其中的x就是2cosx) 假设n=1~k时均成立(k>=3) 当n=k+1时 由cos((k+1)x)=cos(kx)cos(x)-sin(kx)sin(x) cos((k-1)x)=cos(kx)cos(x)

历年NOIP水题泛做

快noip了就乱做一下历年的noip题目咯.. noip2014 飞扬的小鸟 其实这道题并不是很难,但是就有点难搞 听说男神错了一个小时.. 就是$f_{i,j}$表示在第$i$个位置高度为$j$的时候最小点击次数 递推的话对于上升的情况只做一次,后面几次在后面再做.. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace st

[ZPG TEST 114] 阿狸的英文名【水题】

1.      阿狸的英文名 阿狸最近想起一个英文名,于是他在网上查了很多个名字.他发现一些名字可以由两个不同的名字各取一部分得来,例如John(约翰)的前缀 "John"和Robinson(鲁滨逊)的后缀 "son" 连在一起就是Johnson. 现在他找到了两个喜欢的名字(名字可看作字符串),用A和B表示,他想知道取A的一个非空前缀和B的一个非空后缀,连接在一起能组成多少不同的字符串. 输入格式 输入两行,分别表示字符串A和B:字符串只包含小写英文字母. 输出格

G - Brain Network (easy)(并查集水题)

G - Brain Network (easy) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u CodeForces 690C1 Description One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know

UVaLive 6591 &amp;&amp; Gym 100299L Bus (水题)

题意:略. 析:不解释,水题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set>