Yandex.Algorithm 2018, final round
Yandex.Algorithm 2018, final round
思路:如果n这个位置加1的话,不同的数的个数要么不变,要么加1,反之,如果不同的数的个数减少,肯定不是n这个位置加1
我们random_shuffle()50次,每次把不是n的位置标记一下,这样有很大的概率把所有的不是n的位置都标记了
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 1e3 + ;
int a[N];
bool vis[N];
int main() {
int n, tot = ;
scanf("%d", &n);
for (int i = ; i <= n; i++) a[i] = i;
int pre = n, now;
while(tot--) {
random_shuffle(a+, a++n);
for (int i = ; i <= n; i++) {
printf("0 %d\n", a[i]);
fflush(stdout);
scanf("%d", &now);
if(now < pre) {
vis[a[i]] = true;
}
pre = now;
}
}
for (int i = ; i <= n; i++) if(!vis[i]) return *printf("1 %d\n", i);
return ;
}
思路:FFT
求最小的m使得任意两个数之间的差值都不是这个m的倍数
用FFT求任意两个数之间的差值
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 8e6 + , M = 2e6 + ;
int R[N], a[M], b[M];
struct Complex {
double x, y;
Complex(double _x=, double _y=) : x(_x),y(_y) {};
Complex operator + (Complex &t) {return Complex(x+t.x, y+t.y);}
Complex operator - (Complex &t) {return Complex(x-t.x, y-t.y);}
Complex operator * (Complex &t) {return Complex(x*t.x - y*t.y, x*t.y + y*t.x);}
}A[N], B[N];
void fft(Complex *x, int n, int type) {
for (int i = ; i < n; i++) if(i < R[i]) swap(x[i], x[R[i]]);
for (int i = ; i < n; i<<=) {
Complex wn(cos(pi/i), type*sin(pi/i));
for (int j = ; j < n; j+=i<<) {
Complex w(, );
for (int k = ; k < i; k++, w=w*wn) {
Complex X = x[j+k];
Complex Y = w*x[j+k+i];
x[j+k] = X + Y;
x[j+k+i] = X - Y;
}
}
}
} int main() {
int n, m = ;
scanf("%d", &n);
for (int i = ; i <= n; i++) {
scanf("%d", &a[i]);
m = max(m, a[i]);
A[a[i]] = {, };
}
for (int i = ; i <= n; i++) {
B[m-a[i]] = {, };
} int l = , L = ;
for (l = ; l < *m+; l <<= ) L++;
for (int i = ; i < l; i++) {
R[i] = (R[i>>]>>)|((i&)<<L-);
} fft(A, l, );
fft(B, l, );
for (int i = ; i < l; i++) A[i] = A[i] * B[i];
fft(A, l, -);
for (int i = ; i <= m; i++) b[i] = (int)(A[i+m].x/l + 0.5);
for (int i = ; i <= m; i++) {
bool f = true;
for (int j = i; j <= m; j += i) {
if(b[j]) {
f = false;
break;
}
}
if(f) {
printf("%d\n", i);
exit();
}
}
return ;
}
Yandex.Algorithm 2018, final round的更多相关文章
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)B. World Cup
The last stage of Football World Cup is played using the play-off system. There are n teams left in ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)
A.B都是暴力搞一搞. A: #include<bits/stdc++.h> #define fi first #define se second #define mk make_pair ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)---ABC
A---The King's Race http://codeforces.com/contest/1075/problem/A 题意: 一个人在\((1,1)\), 一个人在\((n,n)\), 现 ...
- Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记
夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) B 1075B (思维)
B. Taxi drivers and Lyft time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)D. Peculiar apple-tree
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)C. Laboratory Work
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some v ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)A. Friends Meeting
Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the ...
随机推荐
- 如何用git将项目代码上传到github
注册账户以及创建仓库 要想使用github第一步当然是注册github账号了.之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,之 ...
- nginx动静态分离以及配置https(安全组强行切换以及导致的问题解决)
公司原来的网络采用http/https同时支持的方式,http并不会强制自动跳转到https,最近要求强制切换,导致了一系列问题.趁今天测试完成了,整理如下: 1.要求HTTP自动跳转到HTTPS: ...
- Zookeeper注册中心的搭建
一.Zookeeper的介绍 Zookeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用 ...
- nginx按日期分割日志
#!/bin/bash # Program:chenglee # Auto cut nginx log script. LOGS_PATH="/usr/local/nginx1.13/log ...
- python --- 20 约束 异常处理 MD5 日志
一.类的约束 1.抛出异常 NotImplementedError 2.抽象方法 含有抽象方法的类是抽象类 抽象类中的方法全是抽象方法的是接口 抽象类不能创建对象 二.异常处理 处理完后代码可继 ...
- django过滤器,日期格式化
过滤器相关: 一.形式:小写{{ name | lower }} 二.串联:先转义文本到HTML,再转换每行到 标签{{ my_text|escape|linebreaks }} 三.过滤器的参数显示 ...
- ODAC(V9.5.15) 学习笔记(二)控件列表
ODAC的控件有26个,简单介绍如下: TOraSession 管理Oracle的连接 TOraQuery 使用SQL进行数据获取,自动将更新提交数据库 TSmartQuery 在处理字 ...
- CSS的再深入2(更新中···)
在上一章中,我们又引出了一个知识点: margin的问题 margin:0 auto:(上下为0,左右自适应)会解决元素的居中问题(auto 自适应)前提是给这个元素设置width 同时,我们又要学习 ...
- 5. 多重背包问题 II 【用二进制优化】
多重背包问题 II 描述 有 NN 种物品和一个容量是 VV 的背包. 第 ii 种物品最多有 sisi 件,每件体积是 vivi,价值是 wiwi. 求解将哪些物品装入背包,可使物品体积总和不超过背 ...
- CF113D 高斯消元、dp
题目链接 https://codeforces.com/contest/113/problem/D 思路 \(k[i]=\frac{1-p[i]}{ru[i]}\) f[i][j]表示经过i和j的次数 ...