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 ;
}

Yandex.Algorithm 2018, final round的更多相关文章

  1. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  2. 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 ...

  3. 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 ...

  4. 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)\), 现 ...

  5. Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记

    夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. DOM EventListener

    向元素添加事件句柄的语法:element.addEventListener(event, function, useCapture); 第一个参数是事件的类型,如click或者mousedown,注意 ...

  2. fjwc2019 D3T1 签到题 (贪心)

    #184. 「2019冬令营提高组」签到题 每次询问接近O(1).......考虑贪心 怎么贪心呢? 对于相邻的两个数,我们要保证异或x后单调不降 我们找到两个数二进制上最高的相异位 当左边的数相异位 ...

  3. fjwc2019 D2T2 定价 (栈+set+贪心)

    #182. 「2019冬令营提高组」定价 先瞄下数据范围 对于所有数据,1≤n≤1000,1≤m≤10^9,1≤q≤500000 .\textbf{2 操作的个数不超过 1000.} $10^9$位, ...

  4. 关于er模型中的identifying relationship or non-identifying relationship

    最近,主要负责项目管理和领域模型设计方面的工作,昨天在将UML类图转换为ER模型的时候,发现有identifying relationship or non-identifying relations ...

  5. redhat7.4+shell离线安装docker

    首先要准备离线安装包 1.docker官网下载 2.docker-compose gitbub官网下载 3.我的docker-compose install-docker.sh #!/bin/sh u ...

  6. 基于QProbe创建基本Android图像处理框架

    先来看一个GIF 这个GIF中有以下几个值得注意的地方 这个界面是基本的主要界面所应该在的地方.其右下角有一个“+”号,点击后,打开图像采集界面 在这个界面最上面的地方,显示的是当前图像处理的状态.( ...

  7. 守护进程,互斥锁,IPC,队列,生产者与消费者模型

    小知识点:在子进程中不能使用input输入! 一.守护进程 守护进程表示一个进程b 守护另一个进程a 当被守护的进程结束后,那么守护进程b也跟着结束了 应用场景:之所以开子进程,是为了帮助主进程完成某 ...

  8. 4819: [Sdoi2017]新生舞会 分数规划

    题目 https://www.lydsy.com/JudgeOnline/problem.php?id=4819 思路 分数规划的模板题?(好菜呀) 假如n=3吧(懒得写很长的式子) \(c=\fra ...

  9. 转载:Systemd 服务配置文件

    目录 一.开机启动 二.启动服务 三.停止服务 四.读懂配置文件 五. [Unit] 区块:启动顺序与依赖关系. 六.[Service] 区块:启动行为 6.1 启动命令 6.2 启动类型 6.3 重 ...

  10. switch反汇编(C语言)

    在分支较多的时候,switch的效率比if高,在反汇编中我们即可看到效率高的原因 0x01分支结构不超过3个 #include <stdio.h> void main() { int x ...