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. Oracle 章节编号排序

    测试代码 CREATE TABLE TEST (CH_CODE VARCHAR2(10)); INSERT INTO TEST (CH_CODE) VALUES ('1.1'); INSERT INT ...

  2. QT数据库学习笔记

    简介 QT通过模块化管理,对于某种模块需要添加对应的模块实现.QT SQL也是需要增加对应的模块来实现.QT数据库的层次关系为: 驱动层:数据库到SQL语言之间的桥梁 SQL API层: SQL语句的 ...

  3. KingbaseES V8R6集群运维案例---数据块故障自动修复(auto_bmr)

    案例说明: 在Oracle11.2版本之后,DataGuard 若搭建实时应用日志的物理备库,那么在主库数据文件少 量坏块的情况下,可以利用ABCR技术快速修复坏块. Starting in Orac ...

  4. Luna likes Love 题解

    Problem Link 简要题意 题目很清楚. 分析 定理 两个人中左边的人一直向右运动,和两人向中间走所用的 步数相同 证明 假设有两组人为 \(a_l , a_r , b_l , b_r (a_ ...

  5. #轮廓线dp#洛谷 1879 [USACO06NOV]Corn Fields G

    题目 分析 考虑状压dp在\(n\leq 21\)的情况下会TLE, 设\(dp[n][m][S]\)表示当前正在处理\((n,m)\)这个格子 并且轮廓线状态为\(S\)的方案数, 考虑可行状态最多 ...

  6. c++_shared库引入的问题

    项目组提供了一个AAR文件供下游业务团队集成. 某天,下游团队反馈了一个紧急的问题,最终客户的开发者使用Android Studio打包时,构建工具提示构建失败,原因是存在重复的c++_shared库 ...

  7. 深入理解HashMap和LinkedHashMap的区别

    目录 简介 LinkedHashMap详解 插入 访问 removeEldestEntry 总结 深入理解HashMap和LinkedHashMap的区别 简介 我们知道HashMap的变量顺序是不可 ...

  8. OpenHarmony社区运营报告(2023年3月)

      本月快讯 • <OpenHarmony 2022年度运营报告>于3月正式发布,2022年OpenAtom OpenHarmony(以下简称"OpenHarmony" ...

  9. OpenHarmony 官网文档有哪些上新?下篇:设备开发文档上新

    为了方便社区开发者更易获取 OpenAtom OpenHarmony(以下简称"OpenHarmony")相关文档,暨上篇应用开发文档上新内容,SIG Docs  小组同步准备了设 ...

  10. Avalonia中的布局

    Avalonia是一个跨平台的.NET UI框架,它允许开发者使用C#和XAML来创建丰富的桌面应用程序.在Avalonia中,Alignment.Margin和Padding是非常重要的布局属性,它 ...