Yandex.Algorithm 2018, final round

时间:2021-09-06 01:20:11

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 &lpar;Open Div&period; 2&rpar; &lpar;前三题题解)

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

  2. Codeforces Round &num;468 &lpar;Div&period; 2&comma; based on Technocup 2018 Final Round&rpar;B&period; 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 &num;468 &lpar;Div&period; 2&comma; based on Technocup 2018 Final Round&rpar;

    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 &lpar;Open Div&period; 2&rpar;---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&period; 1没翻车记

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

  6. Lyft Level 5 Challenge 2018 - Final Round &lpar;Open Div&period; 2&rpar; B 1075B (思维)

    B. Taxi drivers and Lyft time limit per test 1 second memory limit per test 256 megabytes input stan ...

  7. Codeforces Round &num;468 &lpar;Div&period; 2&comma; based on Technocup 2018 Final Round&rpar;D&period; Peculiar apple-tree

    In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity ...

  8. Codeforces Round &num;468 &lpar;Div&period; 2&comma; based on Technocup 2018 Final Round&rpar;C&period; 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 &num;468 &lpar;Div&period; 2&comma; based on Technocup 2018 Final Round&rpar;A&period; Friends Meeting

    Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the ...

随机推荐

  1. mac下限速

    sudo ipfw pipe 1 config bw 15KByte/s #设置带宽 sudo ipfw add 1 pipe 1 src-port 80 sudo ipfw add 1 pipe 1 ...

  2. Linux系统的介绍

    一.linux的特点: Linux是一个开源(源代码公开),免费的操作系统,其稳定性,安全性(也会有病毒,但因为linux是开源的,所以一旦有病毒就会有人去搞定它),处理多并发(月,NEC(日本电气股 ...

  3. 关联规则挖掘之apriori算法

    前言: 众所周知,关联规则挖掘是数据挖掘中重要的一部分,如著名的啤酒和尿布的问题.今天要学习的是经典的关联规则挖掘算法--Apriori算法 一.算法的基本原理 由k项频繁集去导出k+1项频繁集. 二 ...

  4. Ant执行一个含有main方法的class文件

    目前需要使用ant来执行一个含有main方法的class文件,并且需要通过命令来行传两个参数(start和end)到main方法. <target name="gsp" de ...

  5. UVa232&period;Crossword Answers

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. 最新发布树莓派2代Wi-Fi自动连接实战&lpar;适合初学者&rpar;

    话说天地会珠海分舵在上几天才刚给大家分享了个海外资讯说树莓派2已经发布且Windows10加盟之类的资讯,具体请查看<海外优秀资讯抢先看8 - Windows 10 for Raspberry ...

  7. Windows Subsystem for Linux (WSL)挂载移动硬盘U盘

    WSL想通过移动硬盘处理一些数据,结果进去了无法发现移动硬盘,于是搜了好久也没有一个正确的解决办法,终于找到一个,现在贡献出来与大家共享. WSL比起linux挂载硬盘简单一些.而且windows本身 ...

  8. PHP 正则表达式资料

    正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串.将匹配的子串做替换或者从某个串中取出符合某个条件的子串等. 举例来说,正则表达式的一个 ...

  9. react创建项目报错unexpected end of json while parsing near xxx

    报这个错,执行下面的命令,然后重新创建项目就可以. npm cache clean --force

  10. 页面livereload width grunt

    step-1.   安装node 环境 step-2.  npm  install grunt-cli  \ grunt http://www.gruntjs.net/docs/getting-sta ...