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. asp.net MVC4 框架揭秘 读书笔记系列3

    IIS/ASP.net管道 本节全部用图形表示便于理解和记忆 1.3.1 IIS5.x与asp.net 1.3.2 IIS 6.0与asp.net 1.3.3 IIS7.0与asp.net 基于IIS ...

  2. Swift-EasingAnimation

    Swift-EasingAnimation 效果 http://gizma.com/easing/ 源码 https://github.com/YouXianMing/UI-Component-Col ...

  3. Linux系统锁定关键文件

    锁定系统关键文件 1.密码.账号文件 chattr +i /etc/passwd /etc/group /etc/shadow /etc/gshadow /etc/inittab 加锁:chattr ...

  4. Nexus 3.X(Maven仓库私服)仓库迁移与备份

    Linux 仓库迁移 Nexus的构件仓库都保存在sonatype-work目录中,该目录的位置由nexus/conf/nexus.properties配置文件指定.仓库迁移需要两个过程:备份和还原 ...

  5. c++ 数组操作(转)

    转自 http://www.cnblogs.com/kykuaileren/archive/2011/09/04/2166646.html 一.数组定义和初始化 1: 一维数组初始化: 2: 标准方式 ...

  6. css实现梯形

    使用伪元素before和after分别在矩形元素前后加三角形或者直接设置border 使用3d旋转矩形,使之看起来像矩形 <html> <head> <meta char ...

  7. zabbix的日常监控-分布式监控(十)

    参考博文:http://blog.51cto.com/jinlong/2051966 zabbix proxy 可以代替 zabbix server 检索客户端的数据,然后把数据汇报给 zabbix ...

  8. kudu安装部署

    安装部署节点规划 节点 kudu-master kudu-tserver node01 是 是 node02 是 是 node03 是 是 配置本地Yum的Repository 下载kudu安装yum ...

  9. 【转】.NET Core基于. csproj 配置文件发布项目

    一.前言 .NET工具链在最新的Preview3版本中,引入了新的MSBuild项目系统,项目文件又回归了.csproj的XML文件来管理,项目文件.包引用.程序集引用..NET Core工具集.发布 ...

  10. RabbitMQ 6种应用场景

    http://www.rabbitmq.com/getstarted.html官网 最近业务需要使用Rabbitmq工作队列实现任务的负载分发 1.1.什么是RabbitMQ? RabbitMQ是实现 ...