题目链接:

题意:

  给你一个严格升序的单链表,但是是用数组来存放的。对于每一个位置来说,你可以知道这个位置的值和下一个的位置。你每一个可以询问一个位置,机器会告诉你这个位置的值,和下一个位置的指针。要你确认大于等于x的值。(询问次数不能超过2000).

题解:

  由于给你的可能有5e4个数,除了随机算法,没有一种可以在2000步以内找到小于等于x。

  对与随机算法:我们先随机找500个点,找到小于x的点0值中最大的一个。然后暴力询问。小于2000的直接暴力找了。  

  证明:

    我们假设x的位置在Y, 那么在[Y-1500, Y] 将会有一个点被随机到。如果没有一个被随机到,这个概率是:1-1500/5e4 = 0.97。有97%的机率选不到。但是500次随机之后 (0.97)500 = 2.4e- 7。

    也就是1e7次的期望值才2。

  

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = +;
const int mod = 1e9+;
bool vis[maxn];
int maxval, pos;
int main() {
#ifdef LOCAL
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // IOS
srand(time());
int n, start, x, val, next;
scanf("%d%d%d", &n, &start, &x);
if(n<=){
int hh = start;
while(){
printf("? %d\n", hh);fflush(stdout);
scanf("%d%d", &val, &hh);
if(val>=x){
printf("! %d\n", val);
return ;
}
if(hh==-){
printf("! -1\n");
return ;
}
}
}
printf("? %d\n", start);fflush(stdout);
scanf("%d%d", &maxval, &next);
pos = start;
for(int i = ;i<;i++){
int hh = random(, n);
while(vis[hh]) hh = random(, n);
vis[hh] = ;
printf("? %d\n", hh);fflush(stdout);
scanf("%d%d", &val, &next);
if(val==x){
printf("! %d\n", x);
return ;
}
if(val<x){
if(val>maxval){
maxval = val;
pos = hh;
}
}
}
int hh = pos;
for(int i = ;i<;i++){
printf("? %d\n", hh);fflush(stdout);
scanf("%d%d", &val, &hh);
if(val>=x){
printf("! %d\n", val);
return ;
}
if(hh==-){
printf("! -1\n");
return ;
}
}
return ;
}

Codeforces Aim Tech Round4 (Div2) D的更多相关文章

  1. Codeforces AIM Tech Round (Div. 2)

    这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...

  2. Codeforces AIM Tech Round3

    打得最烂一场Codeforces,多次都错题,无限WA... A题: 题意:给定n个橘子的大小,大小超过b的丢掉,不足d的补充进来,同时超过d的部分去掉,问要去掉几次 分析:直接模拟即可 #inclu ...

  3. 【Codeforces AIM Tech Round 4 (Div. 2) C】

    ·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意:       输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...

  4. AIM Tech R3 div2 E Centroid

    思路很明显了,假设是点x,则看它的子树中是否有大于n/2的,如果有,则在该子树中剪去它可以剪的且小于n/2的,接到点x上. 则统计出在以x点为根的子树中,它的各子树可以剪去的且小于n/2的最大子子树. ...

  5. codeforces AIM Tech Round 4 div 2

    A:开个桶统计一下,但是不要忘记k和0比较大小 #include<bits/stdc++.h> using namespace std; ]; ]; int main() { int k; ...

  6. Codeforces AIM Tech Round 5 (rated, Div. 1 + Div. 2)

    A. Find Square time limit per test: 1 second memory limit per test: 256 megabytes input: standard in ...

  7. AIM Tech Round 5 1028cf(A-E)

    AIM Tech Round 5 (codeforces上题目编号是1028)(A-E) ---完全被这次比赛打击,自己真的很渣--- 战况 依旧3题选手 被构造题坑得好惨 稍稍涨了rating,希望 ...

  8. codeforce AIM tech Round 4 div 2 B rectangles

    2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...

  9. AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)

    rating又掉下去了.好不容易蓝了.... A..没读懂题,wa了好几次,明天问队友补上... B. Checkpoints 题意:一条直线上n个点x1,x2...xn,现在在位置a,求要经过任意n ...

随机推荐

  1. PHP 数组辅助函数

    /** * 取多维数据中某字段的值 * @param array $array 数据源数组 * @param string|array $field 要获取的字段 * @return array 结果 ...

  2. Dynamic Compilation and Loading of .NET Objects

      This is another approach to dynamic compilation of objects and their usage via Interfaces. Introdu ...

  3. 解决 find: 路径必须在表达式之前:

    通配符前面加\ 转义 或者 换个目录操作

  4. 为Xcode配置Git和Github

    Xcode.Git和Github是三个伟大的编程工具.本文记录一下如何在Xcode中使用Git作为源代码控制工具,以及如何将本地的Git仓库和远程Github上的仓库集成起来. 1. 如何为新建的Xc ...

  5. bcdedit删除uefi多余项

    1.检查是否有多余的启动项:用管理员权限的cmd运行Bcdedit /enum firmware 2.保存现在的所有引导项Bcdedit /export savebcdsavebcd是导出的文件名 3 ...

  6. AIX 逻辑卷简介

    1.基本概念 LVM的组成:物理卷PV.卷组VG.逻辑卷LV.物理分区PP.逻辑分区LP.文件系统等   物理卷:物理卷表示AIX可以识别的物理磁盘(hdisk*),一个物理卷指一块硬盘.可以是内部的 ...

  7. 解决Kloxo出现Could not open database connection问题

    当我们在使用或者运行kloxo面板的时候,可能会出现类似"Could not open database connection"错误提示,对于新手朋友来说肯定本身安装面板管理VPS ...

  8. 【ZOJ3627】Treasure Hunt II

    题目大意:给定一个长度为 N 的序列,现有两个人从 P 点出发,每个单位时间每个人最多可以移动一个单位,两人之间的最大距离不能超过 M,一共有 T 单位的时间,求在合法情况下,两人可以获得的序列点权和 ...

  9. 【UOJ#450】[集训队作业2018] 复读机

    题目链接 题目描述 群里有\(k\)个不同的复读机.为了庆祝平安夜的到来,在接下来的\(n\)秒内,它们每秒钟都会选出一位优秀的复读机进行复读.非常滑稽的是,一个复读机只有总共复读了\(d\)的倍数次 ...

  10. wordpress设置本地化语言

    wordpress语言本地化 在wordpress上很多插件不支持本地化语言如:中文,需要本地化,则需要制作本地化语言的po(用于编辑)和mo(用于机器识别)文件.可以没有*.po文件,但是不能没有* ...