843B - Interactive LowerBound

Posted yijiull

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了843B - Interactive LowerBound相关的知识,希望对你有一定的参考价值。

843B - Interactive LowerBound

 

 

有点懵比~~

没看懂题解说的随机数概率什么的=_=

 

先贴上dalao代码

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 inline pair <int, int> ask(int id) {
 6   printf("? %d\\n", id);
 7   fflush(stdout);
 8   pair <int, int> p;
 9   scanf("%d %d", &p.first, &p.second);
10   return p;
11 }
12 
13 inline void finish(int value) {
14   printf("! %d\\n", value);
15   fflush(stdout);
16   exit(0);
17 }
18 
19 inline int RAND(int n) {
20   return abs((rand() << 15) + rand()) % n;
21 }
22 
23 const int MAGIC = 1000;
24 
25 int main() {
26   int n, start, x;
27   scanf("%d %d %d", &n, &start, &x);
28   srand(time(0));
29   set <int> all;
30   all.insert(start);
31   while ((int) all.size() < min(n, MAGIC)) {
32     all.insert(RAND(n) + 1);
33   }
34   vector < pair <int, int> > v;
35   for (int i : all) {
36     pair <int, int> z = ask(i);
37     v.emplace_back(z.first, i);
38   }
39   sort(v.begin(), v.end());
40   int ptr = start;
41   for (int i = 0; i < (int) v.size(); i++) {
42     if (v[i].first < x) {
43       ptr = v[i].second;
44     }
45   }
46   while (ptr != -1) {
47     pair <int, int> z = ask(ptr);
48     if (z.first >= x) {
49       finish(z.first);
50       return 0;
51     }
52     ptr = z.second;
53   }
54   finish(-1);
55   return 0;
56 }
tourist

 

以上是关于843B - Interactive LowerBound的主要内容,如果未能解决你的问题,请参考以下文章

Firebase 部署功能 --non-interactive

login shell与non-login shell,interactive shell与non-interactive shell

[Python Cookbook] IPython: An Interactive Computing Environment

text Terraform Interactive提示变量

python Interactive Broker示例

css Pine Interactive Components CSS