A

构造题,分两种情况考虑

  • 上下都行,左右选一个
  • 左右都行,上下选一个
void solve() {
int n;
cin >> n;
vector<pair<int, int> > a(n);
for(auto &t : a) cin >> t.x >> t.y;
sort(a.begin(), a.end());
bool okx = a[0].x * a.back().x >= 0;
for(auto &t : a) swap(t.x, t.y);
sort(a.begin(), a.end());
bool oky = a[0].x * a.back().x >= 0;
cout << (okx | oky ? "YES\n" : "NO\n");
}

B

也是构造,这里介绍两种方法

法一 : 二进制拆分

考虑只去模 \(2^k\)

把每个数二进制拆分,模 \(2^k\) 的结果即为这个数的 $[0, k - 1] $位

一直往上枚举 \(k\),直到所有数的 $[0, k - 2] $位相同,第 \(k - 1\) 位不同

void solve() {
int n;
cin>> n;
vector<ll> a(n);
for(ll &x : a) cin >> x;
auto check = [&](ll p) -> bool {
set<ll> se;
for(int i = 0; i < n; ++ i) se.insert(a[i] % p);
return se.size() == 2;
};
for(int i = 1; ; ++ i) {
if(check(1ll << i)) {
cout << (1ll << i) <<'\n';
return;
}
}
}

法二 : 数学

\[x = gcd\{a[1] - a[0], a[2] - a[1], a[3]- a[2], ... , a[n - 1] - a[n - 2]\}
\]

此时

\[ans = 2x
\]

考虑去如何证明

不难得到

\[\forall i \in [1, n),\hspace{0.3cm} x \mid a[i] - a[i - 1]
\]

换句话说,此时所有数模\(x\)结果相同

不妨设

\[a[i] = p_ix + q
\]
  • 若\(p_i\)为偶数,则\(a[i] \bmod 2x = q\)
  • 若\(p_i\)为奇数,则\(a[i] \bmod 2x = x + q\)

由于 \(q < x\),所以 \(x + q < 2x\)

又\(x \neq 0\),所以 \(q \neq x + q\)

情况一: \(p\) 中既有奇数又有偶数,显然成立

情况二: \(p\) 全为奇数或全为偶数,则此时 \(gcd\{a[i] - a[i - 1]\}\) 一定是 \(2x\)的倍数, 与最大为 \(x\) 矛盾

void solve() {
int n;
cin >> n;
ll ans = 0;
vector<ll> a(n);
for(int i = 0; i < n; ++ i) {
cin >> a[i];
if(i) ans = gcd(ans, abs(a[i] - a[i - 1]));
}
cout << ans * 2 << '\n';
}

D. Split Plus K

void solve() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for(auto &x : a) cin >> x;
sort(a.begin(), a.end());
if(a[0] == a[n - 1]) cout << "0\n";
else if(a[0] <= k && a[n - 1] >= k) cout << "-1\n";
else {
ll t = 0, ans = 0;
for(auto x : a) t = __gcd(t, x - k);
for(auto x : a) ans += (x - k) / t - 1;
cout << ans << '\n';
}
}

E. Multiple Lamps

vector<int> ans[20];

void init() {
for(int n = 1; n < 20; ++ n) {
vector<int> f(n + 1, 0);
for(int i = 1; i <= n; ++ i) {
for(int j = i; j <= n; j += i) f[i] |= 1 << j;
}
for(int i = 1; i < 1 << n; ++ i) {
int t = 0;
for(int j = 1; j <= n; ++ j) if((i << 1) >> j & 1) t ^= f[j];
if(__builtin_popcount(t) <= n / 5) ans[n].push_back(i << 1);
}
} } void solve() {
int n, m;
cin >> n >> m;
vector<pair<int, int> > a(m);
for(auto &[x, y] : a) cin >> x >> y;
if(n >= 20) {
cout << n << '\n';
for(int i = 1; i <= n; ++ i) cout << i << ' ';
cout << '\n';
}
else {
for(auto sta : ans[n]) {
bool ok = 1;
for(auto &[x, y] : a) if((sta >> x & 1) && !(sta >> y & 1)) ok = 0;
if(ok) {
cout << __builtin_popcount(sta) << '\n';
for(int i = 1; i <= n; ++ i) if(sta >> i & 1) cout << i << ' ';
cout << '\n';
return;
}
}
cout << "-1\n";
}
}

F1. Small Permutation Problem (Easy Version)

void solve() {
int n, ok = 1;
cin >> n;
vector<int> a(n + 1, 0);
for(int i = 1; i <= n; ++ i) {
cin >> a[i];
ok &= a[i] <= i && a[i] >= a[i - 1] && a[i] <= a[i - 1] + 2;
}
if(!ok || a[n] != n) cout << "0\n";
else {
ll ans = 1;
for(int i = 1; i <= n; ++ i) {
int delta = a[i] - a[i - 1];
if(delta == 1) ans = ans * (2 * (i - a[i - 1]) - 1) % P;
if(delta == 2) ans = ans * (i - a[i - 1] - 1) % P * (i - a[i - 1] - 1) % P;
}
cout << ans << '\n';
}
}

F2. Small Permutation Problem (Hard Version)

ll calc(int a, int b, int k) {
return C(a, k) * C(b, k) % P * fac[k] % P;
} void solve() {
int n;
cin >> n;
vector<int> a(n + 1, 0);
for(int i = 1; i <= n; ++ i) cin >> a[i];
if(a[n] != n && a[n] != -1) return cout << "0\n", void(); ll ans = 1;
auto work = [&](int i, int j) {
ll cur = 0;
int delta = a[i] - a[j];
for(int k = 0; k <= delta; ++ k) {
cur = (cur + calc(i - j, i - a[j] - k, delta - k) * calc( i - j, j - a[j], k)) % P;
}
ans = ans * cur % P;
}; int i = 1, j = 0;
for(; i <= n; ++ i) {
if(~ a[i]) {
if(a[i] < a[j]) return cout << "0\n", void();
work(i, j);
j = i;
}
} work(a[n] = n, j);
cout << ans << '\n';
}

Pinely Round 3 (Div. 1 + Div. 2)的更多相关文章

  1. CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

    1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort    暴力枚举,水 1.题意:n*m的数组, ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  4. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  5. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  8. Codeforces Beta Round #27 (Codeforces format, Div. 2)

    Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...

  9. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  10. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

随机推荐

  1. DNS劫持怎么预防?

    DNS劫持,也称为域名劫持,是一种网络攻击手段,攻击者通过拦截域名解析的请求,将用户重定向到恶意站点,以达到获取用户信息或谋取非法利益的目的.DNS劫持可以分为以下几种基本类型: 1.路由器DNS劫持 ...

  2. JSON格式化 动态生成表格 表格转置 行列转换 Excel导出

    先看效果 初始化: JSON格式化 : 生成表格-方式1 : 生成表格-方式2 : Excel导出 需要行求和.列求和功能的查看 JSON格式化 动态生成表格 表格转置 行列转换 Excel导出 行求 ...

  3. GWD:基于高斯Wasserstein距离的旋转目标检测 | ICML 2021

      论文详细描述了当前旋转目标检测的主要问题,提出将旋转回归目标定义为高斯分布,使用Wasserstein距离度量高斯分布间的距离用于训练.目前,常规目标检测也有很多将回归转化为概率分布函数的做法,本 ...

  4. CSS浮动---float

    一.标准文档流的特性 1.空白折叠 无论多少个空格.换行.tab,都会折叠为一个空格. 2.高矮不齐,底边对齐 3.自动换行,一行放不下就换行写 二.行内元素和块级元素的注意点 1.行内元素不能设置宽 ...

  5. GeminiDB Cassandra接口新特性FLASHBACK发布:任意时间点秒级闪回

    本文分享自华为云社区<GeminiDB Cassandra接口新特性FLASHBACK发布:任意时间点秒级闪回>,作者: GaussDB 数据库. 技术背景 数据库作为现代信息系统的核心组 ...

  6. CTFshow pwn49 wp

    PWN49 用ida打开我们发现是静态编译的,所以先要通过libc库来打是不可能的了,程序里面有一个栈溢出点,找一下有没有system函数,发现并没有 那么我们找一下有没有mprotect函数如果有这 ...

  7. #dp#NOIP2020.9.26模拟jerry

    题目 Jerry 写下了一个只由非负整数和加减号组成的算式. 它想给这个算式添加合法的括号,使得算式的结果最大. 分析 考场\(O(n^3)\)伪部分分成功爆零, 设\(dp[i][j]\)表示前\( ...

  8. #子序列自动机,vector#洛谷 3500 [POI2010]TES-Intelligence Test

    题目 多组询问查询某个串是否为模式串的子序列 分析 考虑用子序列自动机做,匹配的时候显然选择靠前的,用个vector查询最近的就行了 代码 #include <cstdio> #inclu ...

  9. 一文读懂java中的Reference和引用类型

    目录 简介 强引用Strong Reference 软引用Soft Reference 弱引用weak Reference 虚引用PhantomReference Reference和Referenc ...

  10. Qt 桌面服务 QDesktopServices

    使用浏览器打开网址 #include <QDesktopServices> #include <QUrl> QUrl url(QString("https://cn. ...