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. 使用python来建立http服务

    python建立http服务 首先我们的windos上要安装python解释器,然后进入我要想要传递的文件的目录下,从当前的目录下进入cmd 然后通过Python解释器输入 python -m htt ...

  2. JDBC 连接mysql获取中文时的乱码问题

    前段时间学习JDBC,要连接mysql获取数据.按照老师的样例数据,要存一些名字之类的信息,用的都是英文名,我当时就不太想用英文,就把我室友的名字存了进去,嘿嘿,结果,出问题了. 连接数据库语句: s ...

  3. September 13th 2017 Week 37th Wednesday

    Whenever people agree with me, I always feel I must be wrong. 每次人们赞同我时,我都觉得自己一定错了. We can draw lesso ...

  4. September 09th 2017 Week 36th Saturday

    Don't wait to be lonely, to recognize the value of a friend. 不要等到孤独了,才明白朋友的价值. Don't wait to be left ...

  5. 【原创】由于python的导入方式引起的深坑

    目录结构: test/ sacc/ __init__.py app.py logger.py /views __init__.py main.py 事情是这样的,logger里面是一个类LoggerF ...

  6. 为什么说Java中只有值传递----说服自己

    在开始深入讲解之前,有必要纠正一下大家以前的那些错误看法了.如果你有以下想法,那么你有必要好好阅读本文. 错误理解一:值传递和引用传递,区分的条件是传递的内容,如果是个值,就是值传递.如果是个引用,就 ...

  7. MySQL主从.md

    MySQL Replication 概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它 ...

  8. PostgreSQL学习----模式schema

    PostgreSQL学习---模式schema 小序 接触PostgreSQL也有好长时间了,知识不总结梳理,似乎总不是自己的,继续努力吧少年!以此记录我的软件工艺之路! 模式(Schema) 一个 ...

  9. yii 执行流程

    应用执行流程: 浏览器向服务器发送 Http Request | 控制器(protected/controllers) | |---> Action | 创建模型 (Model) | 检查$_P ...

  10. 【转】PHP面试题总结

    PHP面试总结 PHP基础 1:变量的传值与引用. 2:变量的类型转换和判断类型方法. 3:php运算符优先级,一般是写出运算符的运算结果. 4:PHP中函数传参,闭包,判断输出的echo,print ...