题面:

传送门

思路:

这是一道交互题

比赛的时候我看到了直接跳过了......

后来后面的题目卡住了就回来看这道题,发现其实比较水

实际上,从整个序列里面随机选1000个数出来询问,然后从里面找出比x小的最大的那个,再往后面搜1000个数(顺序),这样的方法,不成功率是1.7e-9......

所以随机化就可以了~

(要是这样还WA那真的是脸黑呢......)

Code:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
using namespace std;
int n,st,x;
int val[],next[];
int cnt;
struct node{
int v,p;
}s[];
bool cmp(node l,node r){
return l.v<r.v;
}
int main(){
int i,tmp,ttmp,t1,t2;
srand(time(NULL));
scanf("%d%d%d",&n,&st,&x);
printf("? %d",st);
scanf("%d%d",&t1,&t2);
if(x<t1){
printf("! -1");return ;
}
val[st]=t1;next[st]=t2;
for(i=;i<=min(,n);i++){
tmp=rand()*rand()%n+;
printf("? %d",tmp);
scanf("%d%d",&t1,&t2);
s[++cnt].v=t1;s[cnt].p=tmp;
val[tmp]=t1;next[tmp]=t2;
}
sort(s+,s+cnt+,cmp);
for(i=;i<cnt;i++){
if(s[i].v<x&&s[i+].v>=x) break;
}
tmp=s[i].p;
if(n<=){
printf("! %d",val[tmp]);return ;
}
for(i=;i<=;i++){
ttmp=next[tmp];
printf("? %d",ttmp);
scanf("%d%d",&val[ttmp],&next[ttmp]);
if(val[ttmp]>=x){
printf("! %d",val[tmp]);return ;
}
tmp=ttmp;
}
}

cf 843 B Interactive LowerBound [随机化]的更多相关文章

  1. Codeforces 844D Interactive LowerBound - 随机化

    This is an interactive problem. You are given a sorted in increasing order singly linked list. You s ...

  2. 【AIM Tech Round 4 (Div. 1) B】Interactive LowerBound

    [链接]http://codeforces.com/contest/843/problem/B [题意] 给你一个数组模拟的单链表,放在一个长度为n的数组里面,然后告诉你表头的位置在哪里; 你可以最多 ...

  3. cf 843 D Dynamic Shortest Path [最短路+bfs]

    题面: 传送门 思路: 真·动态最短路 但是因为每次只加1 所以可以每一次修改操作的时候使用距离分层的bfs,在O(n)的时间内解决修改 这里要用到一个小技巧: 把每条边(u,v)的边权表示为dis[ ...

  4. cf 843 A Sorting by Subsequences [建图]

    题面: 传送门 思路: 这道题乍一看有点难 但是实际上研究一番以后会发现,对于每一个位置只会有一个数要去那里,还有一个数要离开 那么只要把每个数和他将要去的那个位置连起来,构成了一个每个点只有一个入边 ...

  5. CF 843 A. Sorting by Subsequences

    A. Sorting by Subsequences You are given a sequence a1, a2, ..., an consisting of different integers ...

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

    ·题目:D. Interactive LowerBound ·英文题,述大意:       有一个长度为n(n<=50000)的单链表,里面的元素是递增的.链表存储在一个数组里面,给出长度n.表 ...

  7. AIM Tech Round 4 (Div. 2)ABCD

    A. Diversity time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  8. [LeetCode] 843. Guess the Word 猜单词

    This problem is an interactive problem new to the LeetCode platform. We are given a word list of uni ...

  9. ATC/TC/CF

    10.25 去打 CF,然后被 CF 打了. CF EDU 75 A. Broken Keyboard 精神恍惚,WA 了一发. B. Binary Palindromes 比赛中的憨憨做法,考虑一个 ...

随机推荐

  1. 手机上如何远程控制Linux服务器?

    这里介绍3个手机软件,分别是JuiceSSH.Termius和Termux,这3个软件都可以实现远程控制Linux服务器(相当于手机SSH客户端),而且使用起来都非常方便,下面我简单介绍一下这3个软件 ...

  2. CUDA高性能编程中文实战11章例子中多设备的例子编译提示问题

    提示的问题如下: error : argument of type "void *(*)(void *)" is incompatible with parameter of ty ...

  3. js当中mouseover和mouseout多次触发(非冒泡)

    JS当中,mouseover和mouseout多次触发事件,不光是冒泡会产生,就是不冒泡,在一定条件下 ,也会产生多次触发事件: 例如下面的结构的情况下,我在class="ceng_up f ...

  4. C# 常用函数和方法集汇总

    1.DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 1.1 取当前年月日时分秒 currentTime=System.D ...

  5. 更改yum网易、阿里云的yum源

    更改yum源为网易的. 首先备份/etc/yum.repos.d/CentOS-Base.repomv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos ...

  6. 回数是指从左向右读和从右向左读都是一样的数,例如 12321 , 909 。请利用 filter() 滤掉非回数

    不管在什么地方,什么时候,学习是快速提升自己的能力的一种体现!!!!!!!!!!! 最近一段时间学习了廖雪峰老师学的Python学习资料,给自己的帮助很大,同时也学到的了很多,今天做了一道练习题,对于 ...

  7. window.onload和$(docunment).ready的区别

    浏览器加载完DOM后,会通过javascript为DOM元素添加事件,在javascript中,通常使用window.onload()方法. 在jquery中,则使用$(document).ready ...

  8. 【CSS】css控制模块到顶层或底层

    举例子,分别有div1和div2现要把div1控制在div2的顶层,可以这样做: } div.div2{} 两个要点:一.设置div的position为absolute,即绝对定位.二.z-index ...

  9. JS如何判断是否为ie浏览器的方法(包括IE10、IE11在内)

    判断是否IE浏览器用的是window.navigator.userAgent,跟踪这个信息,发现在开发环境,识别为IE10,但访问服务器则识别为IE11,但IE11的userAgent里是没有MSIE ...

  10. [译]The Python Tutorial#2. Using the Python Interpreter

    [译]The Python Tutorial#Using the Python Interpreter 2.1 Invoking the Interpreter Python解释器通常安装在目标机器的 ...