题面:

传送门

思路:

这是一道交互题

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

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

实际上,从整个序列里面随机选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. cloudera manager的卸载以及重新安装

    1 卸载cloudera 参照 http://www.cnblogs.com/chenfool/p/3738540.html Cloudera 的官方介绍: http://www.cloudera.c ...

  2. [vijos1066]弱弱的战壕

    描述 永恒和mx正在玩一个即时战略游戏,名字嘛~~~~~~恕本人记性不好,忘了-_-b. mx在他的基地附近建立了n个战壕,每个战壕都是一个独立的作战单位,射程可以达到无限(“mx不赢定了?!?”永恒 ...

  3. (转)CocoaPods

    本文转自http://nshipster.cn/cocoapods/ 文明是建立在道路,桥梁,运河,下水道,管线,电线和光纤这些基础设施之上的.只要设计和施工得当,它们可以帮助社会成倍的发展. 唯一的 ...

  4. Java中创建(实例化)对象的五种方式

    Java中创建(实例化)对象的五种方式1.用new语句创建对象,这是最常见的创建对象的方法. 2.通过工厂方法返回对象,如:String str = String.valueOf(23); 3.运用反 ...

  5. Labyrinth POJ - 1383

    Labyrinth POJ - 1383 The northern part of the Pyramid contains a very large and complicated labyrint ...

  6. python——用递归的方法求x的y次幂

    def function(x,y): : : )*x ): number = int(input('请输入x的值:')) y = int(input('请输入y的值:')) print('x的y次幂的 ...

  7. Reachability from the Capital

    题目描述 There are nn cities and mm roads in Berland. Each road connects a pair of cities. The roads in ...

  8. LightOJ 1141 Number Transformation

    Number Transformation In this problem, you are given an integer number s. You can transform any inte ...

  9. UVA11825 Hacker's Crackdown 二进制集合+关于子集的动态规划

    题意:有N台服务器,全部服务器都直接运行着完全相同的N个任务.对于每台电脑,你都可以进行“一次”操作,使得某(自己选定)一种任务停止,且同时会使得其他和这台服务器直接相连的电脑上面相同的服务完全终止. ...

  10. Storm: 遇到问题总结

    1.没有ack : kafkaspout id 重复导致每次读最新没有数据. 2.由于storm提供的读取kafka的enternal工具存在bug,导致重复读取数据,致使数据不准确.storm bu ...