E. Arithmetic Progression

链接

题意:

  交互题。

  有一个等差序列,现已打乱顺序,最多询问60次来确定首项和公差。每次可以询问是否有严格大于x的数,和查看一个位置的数。

分析:

  首先可以二分找到序列的最大值,然后考虑如何求公差。

  随机选30个数,然后对任意两个求一遍gcd即可。

  正确性证明

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline int query(int ty,LL x) {
int y;
if (ty == ) printf("> %I64d\n", x);
else printf("? %I64d\n", x);
fflush(stdout);
cin >> y;
if (y == -) exit();
return y;
} vector<LL> vec;
int Rand() { return (rand() << ) | rand(); }
int id[]; int main() {
srand();
int n; cin >> n;
LL l = -1e9, r = 1e9, ans = , cnt = , tot = n;
while (l <= r) {
LL mid = (l + r) >> ;
cnt --;
if (query(, mid) == ) ans = mid, r = mid - ;
else l = mid + ;
}
for (int i = ; i <= tot; ++i) id[i] = i;
while (cnt > && tot > ) {
int x = Rand() % tot + ;
vec.push_back(query(, id[x]));
swap(id[x], id[tot]);
tot --; cnt --;
}
sort(vec.begin(), vec.end());
if (vec.back() != ans) vec.push_back(ans);
LL d = vec[] - vec[];
for (int i = ; i < (int)vec.size() - ; ++i) d = __gcd(d, vec[i + ] - vec[i]);
printf("! %I64d %I64d\n", ans - (n - ) * d, d);
return ;
}

CF 1114 E. Arithmetic Progression的更多相关文章

  1. POJ3495 Bitwise XOR of Arithmetic Progression

    Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 772   Accepted: 175 Description Write ...

  2. cf C. Arithmetic Progression

    http://codeforces.com/contest/382/problem/C 题意:给你n个数,然后让你添加一个数使得n+1个数能形成这样的规律,a[1]-a[0]=a[2]-a[1]=a[ ...

  3. CF刷题-Codeforces Round #481-D. Almost Arithmetic Progression

    题目链接:https://codeforces.com/contest/978/problem/D 题解: 题目的大意就是:这组序列能否组成等差数列?一旦构成等差数列,等差数列的公差必定确定,而且,对 ...

  4. CF# 334 Moodular Arithmetic

    B. Moodular Arithmetic time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Dirichlet's Theorem on Arithmetic Progression

    poj3006 Dirichlet's Theorem on Arithmetic Progressions 很显然这是一题有关于素数的题目. 注意数据的范围,爆搜超时无误. 这里要用到筛选法求素数. ...

  6. CF1114E Arithmetic Progression(交互题,二分,随机算法)

    既然是在CF上AC的第一道交互题,而且正是这场比赛让我升紫了,所以十分值得纪念. 题目链接:CF原网 题目大意:交互题. 有一个长度为 $n$ 的序列 $a$,保证它从小到大排序后是个等差数列.你不知 ...

  7. Codeforces 1114E - Arithmetic Progression - [二分+随机数]

    题目链接:http://codeforces.com/problemset/problem/1114/E 题意: 交互题,有一个 $n$ 个整数的打乱顺序后的等差数列 $a[1 \sim n]$,保证 ...

  8. Find Missing Term in Arithmetic Progression 等差数列缺失项

    查找等差数列中的缺失项. e.g.Input: arr[] = {2, 4, 8, 10, 12, 14} Output: 6 Input: arr[] = {1, 6, 11, 16, 21, 31 ...

  9. BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数 ...

随机推荐

  1. Linux partprobe命令详解

    partprobe命令 partprobe: 通知系统分区表的变化 常用的命令展示: 查看帮助 [root@localhost omc]# partprobe --help Usage: partpr ...

  2. Linux 系统常见命令功能大全_【all】

    Linux常见快捷键(6个) ctrl + u:剪贴光标前面 ctrl + k:剪贴光标后面 ctrl + y:粘贴 ctrl + r:查找命令 ctrl + insert:复制 shift+ ins ...

  3. Linux学习之路-2017/12/25

    三章  命令通配符 .PATH变量 支持多种文本的通配符 通配符                   含义 * 匹配零个或多个字符    ?   匹配任意单个字符 [0-9]   匹配范围内的数字 [ ...

  4. 安装Stunnel来实现正向代理邮件

    文:铁乐与猫 2017年8月 一开始我是使用yum install来安装stunnel的 感觉版本低点也无所谓,毕竟只是拿来加密代理一下邮件收发. 可是后来发现之前下载的最新官网版本的tar包里有很多 ...

  5. session过期,拦截ajax请求并跳转登录页面

    1.方法一 :1.1使用filter 和ajaxsetup 对ajax进行拦截并跳转登录页面 public void doFilter(ServletRequest request, ServletR ...

  6. 团队作业1——团队展示&教辅宝

    1.队名:PHILOSOPHER 2.队员学号: [组长]金盛昌(201421122043).刘文钊(20142112255).陈笑林(201421122042). 张俊逸(201421122044) ...

  7. 怎么在移动端模拟pc端进行web开发调试日志

    由于移动端开发,许多地方需要进行手势交互开发,而在pc模拟手机浏览器中不能进行模拟手势,所以无法查看日志,于是网上找了一个,腾讯vConsole,感觉还可以,分享给大家安装也方便 我的项目是基于vue ...

  8. JAVA构造MAP并初始化MAP

    第一种方法:static块初始化 public class Demo{ private static final Map<String, String> myMap; static { m ...

  9. CSS属性之word-break:break-all强制性换行

       一般情况下,元素拥有默认的white-space:normal(自动换行,PS:不换行是white-space:nowrap),当录入的文字超过定义的宽度后会自动换行,但当录入的数据是一堆没有空 ...

  10. [NOIp2009] $Hankson$の趣味题

    \(23333\)这是最近第二份在时间上吊打\(yjk\)的代码--啊哈哈哈哈哈哈哈 嗯,其实遇到这种单纯的\(gcd \ \ or \ \ lcm\)的题,我们都可以用一种比较简单的方法分析:唯一分 ...