Yandex.Algorithm 2018, final round

Smart Vending

LIS vs. LDS

Eat And Walk

Search Engine

Guess Me If You Can

思路:如果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 ;
}

Lazy Hash Table

思路: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 ;
}

最新文章

  1. String,StringBuffer与StringBuilder的区别??
  2. 如何让ConfigurationManager打开任意的配置文件
  3. 前端开发week3
  4. C# Winfrom 页面传值
  5. listview 设置数组为空
  6. Python socket编程之四:模拟分时图
  7. map each 工具函数
  8. 【转】 ubuntu下fastboot找不到devices
  9. C# httpclient获取cookies实现模拟web登录
  10. Linux学习历程——Centos 7 chmod命令
  11. Mysql 根据一个表数据更新另外一个表
  12. docker 15 dockerfile案例-CMD、ENTRYPOINT案例
  13. php通过CURL模拟post提交请求
  14. Linux内核分析第八周总结
  15. wpf 加阴影效果导致内容模糊的问题解决
  16. Xilinx AXI总线学习(1)
  17. cxGrid 的 Sorting和Filtering的总开关
  18. %08lx
  19. kendoui仪表盘和柱状图 示例
  20. 洛谷P3933 Chtholly Nota Seniorious 【二分 + 贪心 + 矩阵旋转】

热门文章

  1. Apache2.4反向代理设置
  2. maven-shade-plugin插件
  3. python,pycharm安装
  4. svg动态添加小人
  5. centos 7 安装使用 redis
  6. Codeforces 15E Triangles - 组合数学
  7. Class DesiredCapabilities
  8. openwrt中在软件包中定义PKG_INSTALL将会发生什么?
  9. ZOJ 3593 One Person Game(ExGcd + 最优解)题解
  10. R: Coercing LHS to a list