黄绿题选刷

news/2024/10/23 8:08:56/文章来源:https://www.cnblogs.com/fanrunze/p/18494276
  • [ABC376D] Cycle

找到包含节点 1 的环,直接从节点一出发,BFS,如果第二次遍历到了节点1,直接输出时间即可。

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
#define DEBUG(x) cerr << #x << '=' << x << endl
#define ll long long
typedef pair <int, int> PII;
typedef unsigned int uint;
typedef unsigned long long ull;
#define i128 __int128
#define fi first
#define se second
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
#define ClockA clock_t start, end; start = clock()
#define ClockB end = clock(); cerr << "time = " << double(end - start) / CLOCKS_PER_SEC << "s" << endl;
inline int rd(){int x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}while (ch >= '0' && ch <= '9')x = (x << 3) + (x << 1) + ch - '0', ch = getchar();return x * f;
}
#define rd rd()void wt(int x){if (x < 0)putchar('-'), x = -x;if (x > 9)wt(x / 10);putchar(x % 10 + '0');return;
}
void wt(int x, char k){wt(x),putchar(k);
}namespace Star_F{const int N = 200005;int n, m;bool vis[N], f;int h[N],e[N],ne[N],idx;void add(int a,int b){e[++idx] = b, ne[idx] = h[a], h[a] = idx;}void bfs(){queue<PII> q;q.push({1, 0});while(!q.empty()){int u  = q.front().fi,ti=q.front().se;q.pop();for (int i = h[u]; i;i=ne[i]){int j = e[i];if(j==1){cout << ti + 1 << endl;f = 1;return;}if(!vis[j]){q.push({j,ti + 1});vis[j] = 1;}}}} void Main(){n = rd, m = rd;FOR(i,1,m){int a, b;a = rd, b = rd;add(a, b);}bfs();if(!f) cout << -1;}}signed main(){// freopen(".in","r",stdin);// freopen(".out","w",stdout);ClockA;int T=1;// T=rd;while(T--) Star_F::Main();// ClockB;return 0;
}/*
*          ▀▀▀██████▄▄▄       _______________
*          ▄▄▄▄▄  █████████▄  /                 \
*         ▀▀▀▀█████▌ ▀▐▄ ▀▐█ | Code has no BUG!  |
*      ▀▀█████▄▄ ▀██████▄██ | _________________/
*       ▀▄▄▄▄▄  ▀▀█▄▀█════█▀ |/
*            ▀▀▀▄  ▀▀███ ▀       ▄▄
*         ▄███▀▀██▄████████▄ ▄▀▀▀▀▀▀█▌   ______________________________
*       ██▀▄▄▄██▀▄███▀ ▀▀████      ▄██  █                               \\
*    ▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███     ▌▄▄▀▀▀▀█_____________________________ //
*    ▌    ▐▀████▐███▒▒▒▒▒▐██▌
*    ▀▄▄▄▄▀   ▀▀████▒▒▒▒▄██▀
*              ▀▀█████████▀
*            ▄▄██▀██████▀█
*          ▄██▀     ▀▀▀  █
*         ▄█             ▐▌
*     ▄▄▄▄█▌              ▀█▄▄▄▄▀▀▄
*    ▌     ▐                ▀▀▄▄▄▀
*     ▀▀▄▄▀     ██
* \  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀
* \- ▌           Name: Star_F              ▀ ▀
*  - ▌                            (o)          ▀
* /- ▌            Go Go Go !               ▀ ▀
* /  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀
*/
  • [ABC348F] Oddly Similar

其实就是个暴力,用 bitset 优化一下就行。
先写出用 bool 数组能过的代码,再把 bool数组 最后一维用 bitset 优化掉。

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
#define DEBUG(x) cerr << #x << '=' << x << endl
#define ll long long
typedef pair <int, int> PII;
typedef unsigned int uint;
typedef unsigned long long ull;
#define i128 __int128
#define fi first
#define se second
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
#define ClockA clock_t start, end; start = clock()
#define ClockB end = clock(); cerr << "time = " << double(end - start) / CLOCKS_PER_SEC << "s" << endl;
inline int rd(){int x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}while (ch >= '0' && ch <= '9')x = (x << 3) + (x << 1) + ch - '0', ch = getchar();return x * f;
}
#define rd rd()void wt(int x){if (x < 0)putchar('-'), x = -x;if (x > 9)wt(x / 10);putchar(x % 10 + '0');return;
}
void wt(int x, char k){wt(x),putchar(k);
}namespace Star_F{const int N = 2001, M = 1000;int n, m, a[N][N], res;bitset<N> cnt[N][M], f;void Main(){n = rd, m = rd;for (int i = 1; i <= n; ++ i )for (int j = 1; j <= m; ++ j ){a[i][j] = rd;cnt[j][a[i][j]][i] = 1;}for (int i = 1; i <= n; ++ i ) {f.reset();for (int j = 1; j <= m; ++ j ) f ^= cnt[j][a[i][j]];f[i] = 0;		 res += f.count();}wt(res/2, '\n');}
}signed main(){// freopen(".in","r",stdin);// freopen(".out","w",stdout);ClockA;int T=1;// T=rd;while(T--) Star_F::Main();// ClockB;return 0;
}/*
*          ▀▀▀██████▄▄▄       _______________
*          ▄▄▄▄▄  █████████▄  /                 \
*         ▀▀▀▀█████▌ ▀▐▄ ▀▐█ | Code has no BUG!  |
*      ▀▀█████▄▄ ▀██████▄██ | _________________/
*       ▀▄▄▄▄▄  ▀▀█▄▀█════█▀ |/
*            ▀▀▀▄  ▀▀███ ▀       ▄▄
*         ▄███▀▀██▄████████▄ ▄▀▀▀▀▀▀█▌   ______________________________
*       ██▀▄▄▄██▀▄███▀ ▀▀████      ▄██  █                               \\
*    ▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███     ▌▄▄▀▀▀▀█_____________________________ //
*    ▌    ▐▀████▐███▒▒▒▒▒▐██▌
*    ▀▄▄▄▄▀   ▀▀████▒▒▒▒▄██▀
*              ▀▀█████████▀
*            ▄▄██▀██████▀█
*          ▄██▀     ▀▀▀  █
*         ▄█             ▐▌
*     ▄▄▄▄█▌              ▀█▄▄▄▄▀▀▄
*    ▌     ▐                ▀▀▄▄▄▀
*     ▀▀▄▄▀     ██
* \  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀
* \- ▌           Name: Star_F              ▀ ▀
*  - ▌                            (o)          ▀
* /- ▌            Go Go Go !               ▀ ▀
* /  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀
*/
  • [ABC349D] Divide Interval

挺简单的一道题,贪心。
每次肯定是能跑多远跑多远,把 \(2^i\) 打表出来,从大到小枚举,再判断能否整除。

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
#define DEBUG(x) cerr << #x << '=' << x << endl
#define ll long long
typedef pair <int, int> PII;
typedef unsigned int uint;
typedef unsigned long long ull;
#define i128 __int128
#define fi first
#define se second
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
#define ClockA clock_t start, end; start = clock()
#define ClockB end = clock(); cerr << "time = " << double(end - start) / CLOCKS_PER_SEC << "s" << endl;#define int long long
inline int rd(){int x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}while (ch >= '0' && ch <= '9')x = (x << 3) + (x << 1) + ch - '0', ch = getchar();return x * f;
}
#define rd rd()void wt(int x){if (x < 0)putchar('-'), x = -x;if (x > 9)wt(x / 10);putchar(x % 10 + '0');return;
}
void wt(char x){putchar(x);
}
void wt(int x, char k){wt(x),putchar(k);
}namespace Star_F{const int N = 10000005;ll l,r,h1[N],h2[N],ans,a[N];void Main(){l = rd, r = rd;a[0] = 1;FOR(i, 1, 62) a[i] = a[i - 1] << 1ll;while (l != r){ROF(i,60,0){if (l + a[i] <= r && l % a[i] == 0){h1[++ans] = l;h2[ans] = l + a[i];l += a[i];break;}}}wt(ans, '\n');FOR(i,1,ans) cout<<h1[i]<<" "<<h2[i]<<endl;}}signed main(){// freopen(".in","r",stdin);// freopen(".out","w",stdout);ClockA;int T=1;// T=rd;while(T--) Star_F::Main();// ClockB;return 0;
}/*
*          ▀▀▀██████▄▄▄       _______________
*          ▄▄▄▄▄  █████████▄  /                 \
*         ▀▀▀▀█████▌ ▀▐▄ ▀▐█ | Code has no BUG!  |
*      ▀▀█████▄▄ ▀██████▄██ | _________________/
*       ▀▄▄▄▄▄  ▀▀█▄▀█════█▀ |/
*            ▀▀▀▄  ▀▀███ ▀       ▄▄
*         ▄███▀▀██▄████████▄ ▄▀▀▀▀▀▀█▌   ______________________________
*       ██▀▄▄▄██▀▄███▀ ▀▀████      ▄██  █                               \\
*    ▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███     ▌▄▄▀▀▀▀█_____________________________ //
*    ▌    ▐▀████▐███▒▒▒▒▒▐██▌
*    ▀▄▄▄▄▀   ▀▀████▒▒▒▒▄██▀
*              ▀▀█████████▀
*            ▄▄██▀██████▀█
*          ▄██▀     ▀▀▀  █
*         ▄█             ▐▌
*     ▄▄▄▄█▌              ▀█▄▄▄▄▀▀▄
*    ▌     ▐                ▀▀▄▄▄▀
*     ▀▀▄▄▀     ██
* \  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀
* \- ▌           Name: Star_F              ▀ ▀
*  - ▌                            (o)          ▀
* /- ▌            Go Go Go !               ▀ ▀
* /  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀
*/
  • [AGC032B] Balanced Neighbors

考虑一个图满足

  • 不连通
  • 每个点和这个点的临点的和为 \(S\)

那么这个图的补图满足

  • 联通
  • 每个点的所有的邻点的和为 \(T\)(因为顶点总和是不变的,所以 \(T=总顶点和 - S\),而S \(S\) 也是不变的。

image

构造不连通,且每个点和这个点的临点的和为 \(S\) 的图很容易 构造,按照 \(n\) 的奇偶分类即可。

点击查看代码
#include <bits/stdc++.h>
using namespace std;#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
#define DEBUG(x) cerr << #x << '=' << x << endl
#define ll long long
typedef pair<int, int> PII;
typedef unsigned int uint;
typedef unsigned long long ull;
#define i128 __int128
#define fi first
#define se second
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
#define ClockA clock_t start, end; start = clock()
#define ClockB end = clock(); cerr << "time = " << double(end - start) / CLOCKS_PER_SEC << "s" << endl;// 输入函数
inline int rd() {int x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9') {if (ch == '-') f = -1;ch = getchar();}while (ch >= '0' && ch <= '9')x = (x << 3) + (x << 1) + ch - '0', ch = getchar();return x * f;
}void wt(int x) {if (x < 0) putchar('-'), x = -x;if (x > 9) wt(x / 10);putchar(x % 10 + '0');
}void wt(char x) {putchar(x);
}void wt(int x, char k) {wt(x), putchar(k);
}namespace Star_F {void Main() {int n = rd(); printf("%d\n", n * (n - 1) / 2 - n / 2);FOR(i, 1, n) {FOR(j, i + 1, n) {if (n & 1) { if (i + j != n) { printf("%d %d\n", i, j); }} else { if (i + j != n + 1) { printf("%d %d\n", i, j); }}}}}
}signed main() {// freopen(".in", "r", stdin);// freopen(".out", "w", stdout);ClockA;int T = 1;// T = rd();while (T--) Star_F::Main();ClockB;return 0;
}/*
*          ▀▀▀██████▄▄▄       _______________
*          ▄▄▄▄▄  █████████▄  /                 \
*         ▀▀▀▀█████▌ ▀▐▄ ▀▐█ | Code has no BUG!  |
*      ▀▀█████▄▄ ▀██████▄██ | _________________/
*       ▀▄▄▄▄▄  ▀▀█▄▀█════█▀ |/
*            ▀▀▀▄  ▀▀███ ▀       ▄▄
*         ▄███▀▀██▄████████▄ ▄▀▀▀▀▀▀█▌   ______________________________
*       ██▀▄▄▄██▀▄███▀ ▀▀████      ▄██  █                               \\
*    ▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███     ▌▄▄▀▀▀▀█_____________________________ //
*    ▌    ▐▀████▐███▒▒▒▒▒▐██▌
*    ▀▄▄▄▄▀   ▀▀████▒▒▒▒▄██▀
*              ▀▀█████████▀
*            ▄▄██▀██████▀█
*          ▄██▀     ▀▀▀  █
*         ▄█             ▐▌
*     ▄▄▄▄█▌              ▀█▄▄▄▄▀▀▄
*    ▌     ▐                ▀▀▄▄▄▀
*     ▀▀▄▄▀     ██
* \  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀
* \- ▌           Name: Star_F              ▀ ▀
*  - ▌                            (o)          ▀
* /- ▌            Go Go Go !               ▀ ▀
* /  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀
*/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/819484.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

面试题:如何能够保证T2在T1执行完后执行,T3在T2执行完后执行?——CountDownLatch原理

CountDownLatch的使用方式 CountDownLatch用于某个线程等待其他线程执行完任务再执行,与thread.join()功能类似。常见的应用场景是开启多个线程同时执行某个任务,等到所有任务执行完再执行特定操作,如汇总统计结果。 面试题:如何能够保证T2在T1执行完后执行,T3在T2执行完后…

读数据工程之道:设计和构建健壮的数据系统17存储的原材料

存储的原材料1. 存储 1.1. 存储是数据工程生命周期的基石1.1.1. 是数据获取、转换和服务主要阶段的基础1.1.1.1. 当构建数据管道时,随着数据经过获取、转换和服务阶段,工程师会选择适当的抽象来存储他们的数据1.1.2. 当数据在生命周期中移动时,它会被多次存储1.1.2.1. 必须在…

JAVA 前三次题目集总结

在过去的一个月里完成了java的前三次大作业对于JAVA的语法以及面向对象编程还不台上手,接下来说前三次大作业。 前三次大作业要是围绕答题判题系统展开的每次作业都在完善这个程序的功能可以说 1.第一次作业判分功能 在第一次作业阶段,核心任务是建立一个能够接收题目信息和答…

数据结构 - 树,三探之代码实现

本文介绍了使用数组和链表两种方式实现二叉树,包括初始化、节点操作(如获取、添加、删除)、以及遍历方法(前序、中序、后序、层次遍历)。测试代码已上传至代码库。书接上回,今天和大家一起动手来自己实现树。相信通过前面的章节学习,大家已经明白树是什么了,今天我们主…

不限次数无广告的短网址生成工具推荐

无论是在社交媒体、营销推广还是日常分享,短网址都能让我们更加便捷地分享内容。然而,在众多的短网址生成工具中,用户常常会遇到一些令人头疼的问题:跳转次数限制、插入广告等等。本文将为大家推荐一款不限次数且无广告的短网址生成工具——小码短链接,并详细介绍其优势。…

使用文件重定向

在Linux终端使用了下文件重定向在试的时候命令比较混乱,再重新捋一下:首先使用vim编辑器创建一个名为test.cpp的文件。 具体内容如下:然后使用g++ -o test test.cpp命令编译生成可执行文件test。接着使用vim编辑器创建了输入文件data.txt 具体内容如下:再运行命令./test &l…

The 2022 ICPC Asia Xian Regional Contest 前六题

VP一场,成都赛前找手感,这次还不戳,前三题略讲The 2022 ICPC Asia Xian Regional Contest 签到题题解 CFJ J. Strange Sum 易证最多只能选两个,从大到小排序后 \(\max(0, a_1) + \max(0, a_2)\) 即为所求。 void solve(){cin>>n;vector<ll>a(n+1);for(int i=1;…

利用数组处理批量数据

数组是一组有序数据的集合。数组中各数据的排列有一定规律,下标代表数据在数组中的序号 用一个数组名和下标来唯一的确定数组中的元素 数组中的每一个元素都属于同一个数据类型。不能把不同类型的数据放在同一个数组中 将数组和循环结合起来,可以有效的处理大批量的数据 怎样…

执行yum install 的时候提示【没有可用的软件包】的解决方案

这种情况,可能是yum 源不正确的问题,解决方案如下: 1.执行cd /etc/yum.repos.d,进入这个目录下,查看文件是否存在并检查文件内容的正确性 2、CentOS-Base.repo文件可以在网上下载一个,以下是范文# CentOS-Base.repo # # The mirror system uses the connecting IP addres…

MySQL安装-Linux系统

MySQL安装-Linux系统本文在此只介绍一种安装方式,其他安装方法可以查阅其他相关资料。 一、准备工作 1、下载MySQL社区版 官方网站:https://www.mysql.com/ ,找到下载DOWNLOADS,下载操作系统对应的社区版本。本文使用的数据库版本是5.7.41选择对应的MySQL版本和系统以及系统…

newc++file.cpp在哪

本人的newc++file.cpp文件在C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VC\VCProjectItems可以在这个cpp文件里面自己选择是否写#define _CRT_SECURE_NO_WARNINGS 如果写了,则在visual studio中新建的cpp文件都有这个这个预处理命令主要是为…

Android13冻结进程分析:如何提高设备性能和用户体验

本文介绍了Android13中的冻结进程功能,它是一种重要的资源管理策略,可以提高系统性能和稳定性,同时最大限度地节省设备的资源和电池消耗。 文章讨论了如何合理分配资源,包括CPU、内存等,以提高设备性能和用户体验。此外,文章还提到了冻结进程对应用程序线程的影响,并介绍…