题面:

传送门

思路:

这是一道交互题

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

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

实际上,从整个序列里面随机选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. 2013年6月 最新Godaddy(持续更新)

    关于Godaddy Godaddy 是世界上最大的域名注册商,Godaddy管理的域名超过5000万.同时,Godaddy也是最大的主机服务商,据多家监测机构显示,放置在Godaddy上的网站数量已经 ...

  2. java 学习集锦

    java学习系列 http://www.cnblogs.com/skywang12345/category/455711.html

  3. Bootstrap历练实例:响应式导航

    <!DOCTYPE html><html lang="zh-cn"><head><meta http-equiv="Conten ...

  4. 使用Vue CLI 3快速创建项目

    首先 vue create ant-design-vue-pro 执行命令会显示两个选项,1默认,2自定义 我么选择自定义 选择好自定义的插件回车就等待下安装成功然后进入项目文件夹 cd ant-de ...

  5. 爬虫学习(八)——带cookie的网页进行爬取

    # 前提:# # 通常,很多网站需要登录才能进行浏览,所以在爬取这些网站时,也需要进行登录,并拿取登录时的cookie# # 登录网页,服务器会给客户端一个牌子cookie# # 访问登录页面时,带着 ...

  6. TP5数据库操作方法总结

    一.TP5数据库操作方法 1.name()方法        作用 : 指定默认的数据表名(不含前缀)        示例 : Db::name('weiba_post');        返回 : ...

  7. 自动发现项目中的URL,django1版本和django2版本

    一.django 1 版本 routers.py import re from collections import OrderedDict from django.conf import setti ...

  8. 动态规划:POJ2576-Tug of War(二维费用的背包问题)

    Tug of War Time Limit: 3000MS Memory Limit: 65536K Description A tug of war is to be arranged at the ...

  9. 7、python中的字典

    字典是python内置的一种无序.可变的数据结构. 字典也叫哈希表.什么是哈希表?哈希表就是会对表中的键(key)执行哈希计算,并根据计算结果在内存中分配一个区域来储存该键所对应的值(value).这 ...

  10. vs code 快捷键总结

    返回上个光标:alt + ←列编辑模式:shift + alt + 鼠标左键