cf 843 B Interactive LowerBound [随机化]
题面:
思路:
这是一道交互题
比赛的时候我看到了直接跳过了......
后来后面的题目卡住了就回来看这道题,发现其实比较水
实际上,从整个序列里面随机选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 [随机化]的更多相关文章
- Codeforces 844D Interactive LowerBound - 随机化
This is an interactive problem. You are given a sorted in increasing order singly linked list. You s ...
- 【AIM Tech Round 4 (Div. 1) B】Interactive LowerBound
[链接]http://codeforces.com/contest/843/problem/B [题意] 给你一个数组模拟的单链表,放在一个长度为n的数组里面,然后告诉你表头的位置在哪里; 你可以最多 ...
- cf 843 D Dynamic Shortest Path [最短路+bfs]
题面: 传送门 思路: 真·动态最短路 但是因为每次只加1 所以可以每一次修改操作的时候使用距离分层的bfs,在O(n)的时间内解决修改 这里要用到一个小技巧: 把每条边(u,v)的边权表示为dis[ ...
- cf 843 A Sorting by Subsequences [建图]
题面: 传送门 思路: 这道题乍一看有点难 但是实际上研究一番以后会发现,对于每一个位置只会有一个数要去那里,还有一个数要离开 那么只要把每个数和他将要去的那个位置连起来,构成了一个每个点只有一个入边 ...
- CF 843 A. Sorting by Subsequences
A. Sorting by Subsequences You are given a sequence a1, a2, ..., an consisting of different integers ...
- 【AIM Tech Round 4 (Div. 2) D Prob】
·题目:D. Interactive LowerBound ·英文题,述大意: 有一个长度为n(n<=50000)的单链表,里面的元素是递增的.链表存储在一个数组里面,给出长度n.表 ...
- 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 ...
- [LeetCode] 843. Guess the Word 猜单词
This problem is an interactive problem new to the LeetCode platform. We are given a word list of uni ...
- ATC/TC/CF
10.25 去打 CF,然后被 CF 打了. CF EDU 75 A. Broken Keyboard 精神恍惚,WA 了一发. B. Binary Palindromes 比赛中的憨憨做法,考虑一个 ...
随机推荐
- 用ComboBox控件制作浏览器网址输入框
实现效果: 知识运用: ComboBox控件的FindString public int FindString(string s) //查找数据项集合中指定数据项的索引 和Select方法 publi ...
- imfilter()用法
功能:对图像进行滤波. 用法: g = imfilter(f, w, filtering_mode, boundary_options, size_options) 其中,f:输入图像,w:滤波掩模, ...
- js实现指定日期增加指定月份
首先,大致思路为: 1. 先将字符串格式的时间类型转化为Date类型 2. 再将Date类型的时间增加指定月份 3. 最后将Date类型的时间在转化为字符串类型 1. 先将字符串格式的时间类型转化为 ...
- PAT (Basic Level) Practise (中文)- 1003. 我要通过!(20)
http://www.patest.cn/contests/pat-b-practise/1003 “答案正确”是自动判题系统给出的最令人欢喜的回复.本题属于PAT的“答案正确”大派送 —— 只要读入 ...
- CSS3和动画
定位: z-index叠层 数字越大越往上层 注意:要用z-index属性必须设position属性 溢出:overflow 属性值:visible 不剪切内容也不添加滚动条 Auto ...
- install cmake,install torch7
cmake http://blog.csdn.net/jesse__zhong/article/details/21290675 torch7 http://wanghaitao8118.blog.1 ...
- vue 服务代理 调用第三方api
项目中前期需要调用第三方API来获取汇率.因为直接调用会有跨域的问题,所以使用来服务代理. 在config配置代理可以这样写: 而调用接口就可以这样写: 坑:配置完成后一直报500,开始怀疑人生.最后 ...
- day 59 MySQL之锁、事务、优化、OLAP、OLTP
MySQL之锁.事务.优化.OLAP.OLTP 本节目录 一 锁的分类及特性 二 表级锁定(MyISAM举例) 三 行级锁定 四 查看死锁.解除锁 五 事务 六 慢日志.执行计划.sql优化 七 ...
- HashMap的实现原理和底层数据结构
看了下Java里面有HashMap.Hashtable.HashSet三种hash集合的实现源码,这里总结下,理解错误的地方还望指正 HashMap和Hashtable的区别 HashSet和Hash ...
- OpenCV学习笔记(十) 直方图操作
直方图计算 直方图可以统计的不仅仅是颜色灰度, 它可以统计任何图像特征 (如 梯度, 方向等等).直方图的一些具体细节: dims: 需要统计的特征的数目, 在上例中, dims = 1 因为我们仅仅 ...