CF 1114 E. Arithmetic Progression
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的更多相关文章
- POJ3495 Bitwise XOR of Arithmetic Progression
Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 772 Accepted: 175 Description Write ...
- cf C. Arithmetic Progression
http://codeforces.com/contest/382/problem/C 题意:给你n个数,然后让你添加一个数使得n+1个数能形成这样的规律,a[1]-a[0]=a[2]-a[1]=a[ ...
- CF刷题-Codeforces Round #481-D. Almost Arithmetic Progression
题目链接:https://codeforces.com/contest/978/problem/D 题解: 题目的大意就是:这组序列能否组成等差数列?一旦构成等差数列,等差数列的公差必定确定,而且,对 ...
- CF# 334 Moodular Arithmetic
B. Moodular Arithmetic time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Dirichlet's Theorem on Arithmetic Progression
poj3006 Dirichlet's Theorem on Arithmetic Progressions 很显然这是一题有关于素数的题目. 注意数据的范围,爆搜超时无误. 这里要用到筛选法求素数. ...
- CF1114E Arithmetic Progression(交互题,二分,随机算法)
既然是在CF上AC的第一道交互题,而且正是这场比赛让我升紫了,所以十分值得纪念. 题目链接:CF原网 题目大意:交互题. 有一个长度为 $n$ 的序列 $a$,保证它从小到大排序后是个等差数列.你不知 ...
- Codeforces 1114E - Arithmetic Progression - [二分+随机数]
题目链接:http://codeforces.com/problemset/problem/1114/E 题意: 交互题,有一个 $n$ 个整数的打乱顺序后的等差数列 $a[1 \sim n]$,保证 ...
- 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 ...
- 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,问是否在每个数 ...
随机推荐
- 模板(template)包含与继承
Django 模板查找机制: Django 查找模板的过程是在每个 app 的 templates 文件夹中找(而不只是当前 app 中的代码只在当前的 app 的 templates 文件夹中找). ...
- Loadrunner11代理录制&各个常见功能介绍
1.代理录制: Lr代理工具:C:\Program Files (x86)\HP\LoadRunner\bin\wplus_init_wsock.exe 1) 设置代理 配置代理信息: 2)设置浏览器 ...
- Linux uname命令详解
uname常见命令参数 -a, --all print all information, in the following order, except omit -p and -i if unknow ...
- virtual memory exhausted: Cannot allocate memory 解决方法
在阿里云买了个云服务器,内存1G.编译kudu时出现下面的错误: virtual memory exhausted: Cannot allocate memory 问题原因:由于物理内存本身很小,且阿 ...
- jQuery Ajax url使用方式
jQuery Ajax的使用场景: 页面需要通过后台逻辑,但只需要局部刷新以显示新的内容. jQuery Ajax url使用方式1.servlet方式: 需要在struts.xml中写一个actio ...
- Web通信协议:OSI、TCP、UDP、Socket、HTTP、HTTPS、TLS、SSL、WebSocket、Stomp
1 各层的位置 1.1 OSI七层模型全景图 OSI是Open System Interconnect的缩写,意为开放式系统互联. 1.2 五层网络协议 在七层的基础上, ...
- October 04th 2017 Week 40th Wednesday
We teach people how to remember, we never teach them how to grow. 我们教会人们如何记忆,却从来不教他们如何成长. Without pr ...
- 基于UML的毕业设计管理系统的分析与设计
基于UML的毕业设计管理系统的分析与设计 <本段与标题无关,自行略过 最近各种忙,天气不错,导师心情不错:“我们要写一个关于UML的专著”,一句话:“一个完整的系统贯穿整个UML的知识”:我:“ ...
- JAVA 泛型通配符 ? EXTENDS SUPER 的用法
1. <? extends Hero> ArrayList heroList<? extends Hero> 表示这是一个Hero泛型或者其子类泛型heroList 的泛型可能 ...
- 4-4 R语言函数 tapply
#对向量的子集进行操作 #tapply(参数):tapply(向量,因子/因子列表,函数/函数名) > x <- c(rnorm(5),runif(5),rnorm(5,1)) > ...