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

时间: 2024-09-28 07:32:02

843B - Interactive LowerBound的相关文章

cf 843 B Interactive LowerBound [随机化]

题面: 传送门 思路: 这是一道交互题 比赛的时候我看到了直接跳过了...... 后来后面的题目卡住了就回来看这道题,发现其实比较水 实际上,从整个序列里面随机选1000个数出来询问,然后从里面找出比x小的最大的那个,再往后面搜1000个数(顺序),这样的方法,不成功率是1.7e-9...... 所以随机化就可以了~ (要是这样还WA那真的是脸黑呢......) Code: 1 #include<iostream> 2 #include<cstdio> 3 #include<

【AIM Tech Round 4 (Div. 2) D Prob】

·题目:D. Interactive LowerBound ·英文题,述大意:       有一个长度为n(n<=50000)的单链表,里面的元素是递增的.链表存储在一个数组里面,给出长度n.表头在数组的下标和一个值w.题目要求求出链表中大于等于w值的元素中的最小元素.注意,这道题是一道interactive.由于链表是未知的,最多可以进行1999个询问,询问形式:?i.表示询问数组下标为i,询问后,会得到一个答案组(val,Next),表示询问的元素是val,链表下一位所在的数组下标是Next

lowerBound与upperBound

//4.以某一特定位置来截取字符串 var string = " https://www.baidu.com" let range = string.range(of: "baidu") let lowerStr = string.substring(to: (range?.lowerBound)!) //结果为: https://www. print("to lower string: \(lowerStr)") let upperStr =

Maven在[INFO] Generating project in Interactive mode卡住的问题解决

我的环境: Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00) Maven home: /usr/local/maven3 Java version: 1.8.0_111, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Ho

Senergy.Interactive.Petrophysics.v4.2.2013.275 1CD(交互式测井分析工具)

Senergy.Interactive.Petrophysics.v4.2.2013.275 1CD(交互式测井分析工具)Interactive Petrophysics软件的基本模块包括数据库的管理.数据的导入导出.数据接口.曲线编辑与预处理工具.环境校正.基本解释功能.多井功能.二次开发功能等. 数据接口包括与Openworks.Openspirit(Geoframe).Geolog.Powerlog.Logic.Petrel.ODM.Recall软件的数据接口,这使IP能够直接和这些软件的

Maven: Generating project in Interactive mode

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=org.conan.myhadoop.mr -DartifactId=myHadoop -DpackageName=org.conan.myhadoop.mr -Dversion=1.0-SNAPSHOT -DinteractiveMode cmd输出卡死在Generating project in Interactive mode不动了

iOS 7 自定义Back按钮 与 Pop interactive gesture

1.自定义Back按钮 iOS中很多时候我们都会自定义返回按钮,也是一件easy的事,类似如下: // 返回按钮 1 - (void)showNavBackButton 2 { 3 UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; 4 [backButton addTarget:self action:@selector(backButtonAction:) 5 forControlEvents:UICont

[CSS3] Interactive Pseudo-Classes :link :visited :hover :active

The interactive pseudo-classes for links (and buttons) allow us to make sure the user knows what elements on the page are interactive and that they can use them to navigate the website. Order is important: order -- link, then visited, then hover, the

Interactive Learning Document Format Reference

Interactive Learning Document Format Reference An interactive learning document is a kind of playground that lets the reader interact with code mixed with rich HTML content. Its file format is a package that contains Swift source code, HTML content,