上蓝了!

A. Consecutive Sum Riddle

题意

给一个nnn,你需要构造一个整数区间[L,R][L,R][L,R],其和等于nnn
分析

取[−n+1,n][-n+1,n][−n+1,n]即可。

B. Special Numbers

题意

给出一个 nnn , 另一个数 mmm 如果可以表示成 nnn 的不同幂次之和,则称 mmm 是 special 的。现在给出 nnn, 将所有 special 的数升序排序,问第 kkk 个数是多少。

分析

假如一个数是 n0+n1+n4n^0+n^1+n^4n0+n1+n4 , 我们不妨用二进制表示,转化为 10011(2)10011_{(2)}10011(2)​ ,也就是说现在给了一个二进制的数,但是其每个位的权值要乘以 nnn. 那么第 kkk 个数表示成二进制自然就是 k(2)k_{(2)}k(2)​ 本身了,模拟快速幂求即可。

代码

#include <bits/stdc++.h>
#define fors(i, a, b) for(int i = (a); i <= (b); ++i)
#define lson k<<1
#define rson k<<1|1
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mem(a) memset(a, 0, sizeof(a))
#define DDLC_ESCAPE_PLAN_FAILED ios::sync_with_stdio(false), cin.tie(0)
#define int long long
#define pii pair<int, int>
using namespace std;
const int mod = 1e9 + 7;
signed main() {DDLC_ESCAPE_PLAN_FAILED;int t;cin >> t;while(t--) {int n, k;cin >> n >> k;int ans = 0;int x = 1;while(k) {if(k & 1) {ans = (ans + x) % mod;}x = (x * n) % mod;k >>= 1;}cout << ans << endl;}return 0;
}

C. Make Them Equal

题意

给一串字符串,你要通过一些操作把它的所有字符全部变成 ccc:

选择一个数字 x,1≤x≤nx, 1\leq x\leq nx,1≤x≤n. 字符串中所有下标 iii 中 imodx≠0i\ mod\ x \neq 0i mod x​=0 的下标都将被替换为 ccc.

分析

首先贪心考虑,如果 xxx 取 nnn,那么 [1,n−1][1,n-1][1,n−1] 必定全部都可以替换,接下来再取个 n−1n-1n−1,把 nnn 替换即可。故不管怎样,答案最多为2.

所以只需要考虑答案为1的情况了。这里我们可以直接暴力统计所有不等于 ccc 的下标的因数,如果不同因数的个数小于 nnn ,说明一定可以找到一个 xxx 使得所有字符为 ccc.

代码

#include <bits/stdc++.h>
#define fors(i, a, b) for(int i = (a); i <= (b); ++i)
#define lson k<<1
#define rson k<<1|1
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mem(a) memset(a, 0, sizeof(a))
#define DDLC_ESCAPE_PLAN_FAILED ios::sync_with_stdio(false), cin.tie(0)
#define int long long
#define pii pair<int, int>
const int inf = 0x3f3f3f3f;
const double dinf = 1e100;
typedef long long ll;
//const ll linf = 9223372036854775807LL;
// const ll linf = 1e18;
using namespace std;
const int maxn = 3e5 + 10;
bool v[maxn];
signed main() {DDLC_ESCAPE_PLAN_FAILED;int t;cin >> t;while(t--) {int n;string s; char c;cin >> n;s += '#';string tmp;cin >> c;cin >> tmp;s += tmp;bool flag = 1;vector<int> pos;for (int i = 1; i <= n; ++i) v[i] = 0;for (int i = 1; i <= n; ++i) if(s[i] != c) {flag = 0; pos.pb(i);}if(flag) {cout << 0 << endl;continue;}int cnt = 0;for (auto &i : pos) {if(!v[i]) v[i] = 1, cnt++;for (int j = 1; j * j <= i; ++j) {if(i % j == 0 && !v[j]) v[j] = 1, cnt++;if(i % j == 0 && !v[i / j]) v[i / j] = 1, cnt++;}}if (cnt == n) {cout << 2 << endl;cout << n << ' ' << n - 1 << endl;}else {cout << 1 << endl;for (int i = 1; i <= n; ++i) if(!v[i]) {cout << i << endl;break;}}}return 0;
}

D. The Number of Imposters

题意

有一张 nnn 个节点的图,每条边都是单向边 (i,j,c)(i,j,c)(i,j,c) 表示第 iii 个人说第 jjj 个人是个说谎的人/说实话的人。且如果一个人是说谎的人,那他说的一定是假,否则一定是真。

问这张图最多有几个说实话的人。

分析

单向图其实可以直接转化为无向图,这是等价的。 aaa 说 bbb 是假的,其实和 bbb 说 aaa 假是一样的,可以列真值表证明。

而且,只要连通图中有一个人的真假确定了,其他人的真假一定也确定了。

所以,转化为无向图之后再记忆化搜索就可以了,对每个连通块进行 dfs ,dp[i][0]dp[i][0]dp[i][0] 表示第 iii 人说谎的情况下他和他的子节点中说实话的人有多少;dp[i][1]dp[i][1]dp[i][1] 表示 iii 说实话的情况下的答案。

注意矛盾的情况,搜索过程中每个节点要保存自己的当前真假情况,这样在子节点指回祖先节点时判断一下矛不矛盾就可以了。

所以对每个连通块搜索的根节点,假设其为实话或者谎话,分别 dfs 两次,取最大值即可。


其实也可以写的更简单的,但是昨天越写越奇怪,有点没稳住,思路太乱了。

不仅思路较为冗杂,代码也特别丑qwq

代码

#include <bits/stdc++.h>
#define fors(i, a, b) for(int i = (a); i <= (b); ++i)
#define lson k<<1
#define rson k<<1|1
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mem(a) memset(a, 0, sizeof(a))
#define DDLC_ESCAPE_PLAN_FAILED ios::sync_with_stdio(false), cin.tie(0)
// #define int long long
#define pii pair<int, int>
const int inf = 0x3f3f3f3f;
const double dinf = 1e100;
typedef long long ll;
//const ll linf = 9223372036854775807LL;
// const ll linf = 1e18;
using namespace std;
const int maxn = 2e5 + 10;
int n, m;
int dp[maxn][2]; // i号节点说谎/不说谎的答案
vector<pii> e[maxn];
bool v[maxn];
bool flag = 0;
int fa[maxn];
int st[maxn]; // 当前的status 1说谎,2不说谎
vector<int> tmp;
void dfs(int i, int l) { // l:0说谎,1不说谎tmp.pb(i);st[i] = l + 1;for (auto &x : e[i]) {if(st[x.first]) {if(l == 1 && x.second == 0 && st[x.first] == 2){flag = 1;}else if(l == 1 && x.second == 1 && st[x.first] == 1) {flag = 1;}else if(l == 0 && x.second == 1 && st[x.first] == 2) {flag = 1;}else if(l == 0 && x.second == 0 && st[x.first] == 1) {flag = 1;}continue;}if(l == 1 && x.second == 0) {dfs(x.first, 0);dp[i][1] += dp[x.first][0];}else if(l == 1 && x.second == 1) {dfs(x.first, 1);dp[i][1] += dp[x.first][1];}else if(l == 0 && x.second == 0) {dfs(x.first, 1);dp[i][0] += dp[x.first][1];}else {dfs(x.first, 0);dp[i][0] += dp[x.first][0];}}
}
signed main() {DDLC_ESCAPE_PLAN_FAILED;int t;cin >> t;while(t--) {cin >> n >> m;flag = 0;fors(i, 1, n) {dp[i][0] = 0, dp[i][1] = 1;fa[i] = i;v[i] = 0;st[i] = 0;}int l, r; string s;while(m--) {cin >> l >> r >> s;if(s[0] == 'i') {e[l].pb({r, 0});e[r].pb({l, 0});}else {e[l].pb({r, 1});e[r].pb({l, 1});}}int ans = 0;for (int i = 1; i <= n; ++i) {if(!st[i]) {tmp.clear();dfs(i, 0);for(auto &x : tmp) st[x] = 0;dfs(i, 1);ans += max(dp[i][0], dp[i][1]);if(flag) break;}}if(flag) cout << -1 << endl;else cout << ans << endl;fors(i, 1, n) e[i].clear();}return 0;
}

E1. Rubik’s Cube Coloring (easy version)

这种E1还是放Div. 3去吧,能当A做了,我不好说。

属于是送经验了(

#include <bits/stdc++.h>
#define fors(i, a, b) for(int i = (a); i <= (b); ++i)
#define lson k<<1
#define rson k<<1|1
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mem(a) memset(a, 0, sizeof(a))
#define DDLC_ESCAPE_PLAN_FAILED ios::sync_with_stdio(false), cin.tie(0)
#define int long long
#define pii pair<int, int>
const int inf = 0x3f3f3f3f;
const double dinf = 1e100;
typedef long long ll;
//const ll linf = 9223372036854775807LL;
// const ll linf = 1e18;
using namespace std;
const int mod = 1e9 + 7;
int fpow(int x, int y) {int ans = 1;while(y) {if(y & 1) {ans = (ans * x) % mod;}x = (x * x) % mod;y >>= 1;}return ans;
}
signed main() {DDLC_ESCAPE_PLAN_FAILED;int t;t = 1;while(t--) {int k;cin >> k;int p = (1LL << k) - 1LL;cout << (fpow(4, p - 1LL) * 6LL) % mod << endl;}return 0;
}

Codeforces Round #747 (Div. 2) 个人题解相关推荐

  1. Codeforces Round #747 (Div. 2)题解

    Codeforces Round #747 (Div. 2)题解 (本博客将持续更新以后每场CF div2的题解,喜欢ACM.OI的小伙伴记得点个关注哟) 昨天夜晚刷网络流刷入迷了,渐渐就忘记了我还要 ...

  2. Codeforces Round #686 (Div. 3) A-F题解

    Codeforces Round #686 (Div. 3) A-F题解 A. Special Permutation 题意 给定 nnn ,输出一个长度为 nnn 的全排列,每个位置 iii 上的数 ...

  3. Codeforces Round #693 (Div. 3)部分题解

    Codeforces Round #693 (Div. 3) 部分题解 D. Even-Odd Game 思路: 贪心:田忌赛马 (1)先将数组从大到小排序,取数时从大到小取,用一个ans变量记录取数 ...

  4. Codeforces Round #702 (Div. 3)A-G题解

    Codeforces Round #702 (Div. 3)A-G题解 比赛链接:https://codeforces.ml/contest/1490 这场F读错题意白给一发,G二分的if(dp[mi ...

  5. codeforces Round #645 (Div. 2)D题解

    Codeforces Round #645 (Div. 2)--D题解 作为一名菜鸡,理所当然得没有A出来,这道题数据放小就一水题了,可惜数据这块卡的死死的. 本题最重要的一点就是你要推出来一个结论: ...

  6. Codeforces Round #670 (Div. 2)A-D题解

    Codeforces Round #670 (Div. 2)A-D题解 //写于rating值1987/2184 //补档 比赛链接:https://codeforces.ml/contest/140 ...

  7. Codeforces Round #674 (Div. 3)A-F题解

    Codeforces Round #674 (Div. 3)A-F题解 比赛链接:https://codeforces.com/contest/1426 A题 水题不写题解 #include<b ...

  8. Codeforces Round #807 (Div. 2) A-C题解

    Codeforces Round #807 (Div. 2) A.B.C题题解 A - Mark the Photographer 题意:马克要给2n个人照相,分两排,一排站n人,给出每个人的身高,要 ...

  9. Codeforces Round #723 (Div. 2) 个人题解

    上1400辣! 传送门:https://codeforces.com/contest/1526 A. Mean Inequality 题意 给一个长度为偶数的数组,你需要重排这个数组,使得任意一个数不 ...

最新文章

  1. ajax请求数据渲染个人中心页面
  2. android 读取其他应用程序,android – 在另一个应用程序中请求我自己的ContentProvider的读取权限...
  3. JS循环绑定对象或变量
  4. sonarqube中,分析maven聚合工程时,不必分析parent工程,只需分析下面的module子工程即可
  5. android Animator详解
  6. debian下安装python虚拟环境
  7. 错失双节福利?这12本新书投送了解一下
  8. pb预览状态下的pagecount_QuickLook高效文件预览神器,方便到令你意想不到
  9. select count(*) ,count() , select *
  10. idea2020 个性化设置
  11. 反欺骗:从黑客时代的神话说起
  12. 恶意程序新趋势-钻粪坑+数签
  13. 『码上行动-编程擂台』学员作品展(附源码)
  14. 有道无术,术可求;有术无道,止于术
  15. 从零和到竞合 亚马逊为何联姻国美?
  16. hazelcast_使用Hazelcast发布和订阅
  17. 同一个电脑安装多个jdk版本
  18. 如何快速清洗空调扇(水冷式电风扇)(图文教程)
  19. ews java 新建邮箱_通过EWS JAVA API订阅邮箱更新
  20. 谷歌 地图 android studio,Android Studio百度地图开发(一)

热门文章

  1. Xubuntu22.04之番茄时钟gnome-pomodoro(一百六十七)
  2. C语言习题——字符串旋转结果
  3. python13 之线性回归(WLS加权最小二乘法)
  4. 洛谷 P1957 【口算练习题】
  5. 华为你学不会思维脑图
  6. 搜索引擎下拉食云速捷详细_「seo推广技术」seo关键词软件首要云速捷安全
  7. 【毕业设计】大数据北京二手房数据分析与可视化 - python 数据挖掘
  8. 小程序用canvas合并两张图片
  9. Matlab GUI/APP 浅谈(附计算器源码)
  10. Android 拍照和相册选择