Codeforces Round #738 (Div. 2)

Codeforces Round #738 (Div. 2)

文章目录

  • A
    • 题解:
    • 代码:
  • B
    • 题意:
    • 题解:
    • 代码:
  • C
    • 题意:
    • 题解:
    • 代码:
  • D1
    • 题意:
    • 题解:
    • 代码:

题号题目知识点
AMocha and Math
BMocha and Red and Blue
CMocha and Hiking
D1Mocha and Diana (Easy Version)
D2Mocha and Diana (Hard Version)
EMocha and Stars

A

题解:

可以任意选区间,可以操作多次,也就是任何数都可以进行&操作,所以答案就是所有&的结果

代码:

// Problem: A. Mocha and Math
// Contest: Codeforces - Codeforces Round #738 (Div. 2)
// URL: https://codeforces.com/contest/1559/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Data:2021-08-16 19:15:42
// By Jozky#include <bits/stdc++.h>
#include <unordered_map>
#define debug(a, b) printf("%s = %d\n", a, b);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
clock_t startTime, endTime;
//Fe~Jozky
const ll INF_ll= 1e18;
const int INF_int= 0x3f3f3f3f;
template <typename T> inline void read(T& x)
{T f= 1;x= 0;char ch= getchar();while (0 == isdigit(ch)) {if (ch == '-')f= -1;ch= getchar();}while (0 != isdigit(ch))x= (x << 1) + (x << 3) + ch - '0', ch= getchar();x*= f;
}
template <typename T> inline void write(T x)
{if (x < 0) {x= ~(x - 1);putchar('-');}if (x > 9)write(x / 10);putchar(x % 10 + '0');
}
void rd_test()
{
#ifdef LOCALstartTime= clock();freopen("in.txt", "r", stdin);
#endif
}
void Time_test()
{
#ifdef LOCALendTime= clock();printf("\nRun Time:%lfs\n", (double)(endTime - startTime) / CLOCKS_PER_SEC);
#endif
}
int main()
{//rd_test();int t;read(t);while (t--) {int n;read(n);ll ans= 0;for (int i= 1; i <= n; i++) {int x;read(x);if (i == 1)ans= x;elseans= ans & x;}printf("%d\n", ans);}return 0;//Time_test();
}

B

题意:

长度为n的字符串,由BR?三种符号组成,现在要求你将?填上B/R,使得相同符号相邻的情况最少

题解:

找到第一个非?的字符,然后从该点开始向前向后一次填充,每次填充?时填与其相邻的相反元素
这样保证最优

代码:

// Problem: B. Mocha and Red and Blue
// Contest: Codeforces - Codeforces Round #738 (Div. 2)
// URL: https://codeforces.com/contest/1559/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Data:2021-08-16 19:24:33
// By Jozky#include <bits/stdc++.h>
#include <unordered_map>
#define debug(a, b) printf("%s = %d\n", a, b);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
clock_t startTime, endTime;
//Fe~Jozky
const ll INF_ll= 1e18;
const int INF_int= 0x3f3f3f3f;
template <typename T> inline void read(T& x)
{T f= 1;x= 0;char ch= getchar();while (0 == isdigit(ch)) {if (ch == '-')f= -1;ch= getchar();}while (0 != isdigit(ch))x= (x << 1) + (x << 3) + ch - '0', ch= getchar();x*= f;
}
template <typename T> inline void write(T x)
{if (x < 0) {x= ~(x - 1);putchar('-');}if (x > 9)write(x / 10);putchar(x % 10 + '0');
}
void rd_test()
{
#ifdef LOCALstartTime= clock();freopen("in.txt", "r", stdin);
#endif
}
void Time_test()
{
#ifdef LOCALendTime= clock();printf("\nRun Time:%lfs\n", (double)(endTime - startTime) / CLOCKS_PER_SEC);
#endif
}
int main()
{//rd_test();int t;read(t);while (t--) {int n;read(n);string s;cin >> s;int pos= n + 1;for (int i= 0; i < s.length(); i++) {if (s[i] != '?') {pos= i;break;}}for (int i= pos - 1; i >= 0; i--) {if (s[i] == '?') {if (s[i + 1] == 'R')s[i]= 'B';elses[i]= 'R';}}for (int i= pos + 1; i < s.length(); i++) {if (s[i] == '?') {if (s[i - 1] == 'R')s[i]= 'B';elses[i]= 'R';}}cout << s << endl;}//Time_test();
}

C

题意:

有n+1个点,其中1~n个点,1有条到2的边,2有条到3的边…n-1有条到n的边
1到n这些点与n的连边关系题目给出,问能否将所有点全走一遍(每个点最多只能走一次)

题解:

不难发现,从1出发,是可以到n的(经过了1到n所有点),现在还剩n+1
如果点n+1能到1或者n能到n+1,那就可以顺利到点n+1
或者从aia_{i}ai可以到n+1,从n+1也可以到ai+1a_{i+1}ai+1,这样也行

代码:

// Problem: C. Mocha and Hiking
// Contest: Codeforces - Codeforces Round #738 (Div. 2)
// URL: https://codeforces.com/contest/1559/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Data:2021-08-16 19:47:58
// By Jozky#include <bits/stdc++.h>
#include <unordered_map>
#define debug(a, b) printf("%s = %d\n", a, b);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
clock_t startTime, endTime;
//Fe~Jozky
const ll INF_ll= 1e18;
const int INF_int= 0x3f3f3f3f;
template <typename T> inline void read(T& x)
{T f= 1;x= 0;char ch= getchar();while (0 == isdigit(ch)) {if (ch == '-')f= -1;ch= getchar();}while (0 != isdigit(ch))x= (x << 1) + (x << 3) + ch - '0', ch= getchar();x*= f;
}
template <typename T> inline void write(T x)
{if (x < 0) {x= ~(x - 1);putchar('-');}if (x > 9)write(x / 10);putchar(x % 10 + '0');
}
void rd_test()
{
#ifdef LOCALstartTime= clock();freopen("in.txt", "r", stdin);
#endif
}
void Time_test()
{
#ifdef LOCALendTime= clock();printf("\nRun Time:%lfs\n", (double)(endTime - startTime) / CLOCKS_PER_SEC);
#endif
}
const int maxn= 2e4 + 9;
vector<int> vec[maxn];
int a[maxn];
int main()
{//rd_test();int t;read(t);while (t--) {int n;read(n);for (int i= 1; i < n; i++)vec[i].push_back(i + 1);for (int i= 1; i <= n; i++) {cin >> a[i];}if (a[1] == 1) {printf("%d", n + 1);for (int i= 1; i <= n; i++) {printf(" %d", i);}printf("\n");continue;}else if (a[n] == 0) {printf("%d", 1);for (int i= 2; i <= n + 1; i++) {printf(" %d", i);}printf("\n");continue;}bool f= 0;for (int i= 1; i < n; i++) {if (a[i] == 0 && a[i + 1] == 1) {for (int j= 1; j <= n; j++) {printf("%d ", j);if (j == i)printf("%d ", n + 1);}printf("\n");break;}}if (f == 0)continue;elseprintf("-1\n");}//Time_test();
}

D1

题意:

有两个森林,现在要求你在第一个森林加边,第二个森林会自动进行一样的操作,两个森林都不允许出现环,问最多能加多少边?

题解:

利用并查集分开维护两个森林,对于边u和v,如果uv在第一个森林不在一个集合内,在第二个森林也不在一个集合内,才可以加入
O(n2n^2n2)

代码:

// Problem: D1. Mocha and Diana (Easy Version)
// Contest: Codeforces - Codeforces Round #738 (Div. 2)
// URL: https://codeforces.com/contest/1559/problem/D1
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Data:2021-08-16 20:01:37
// By Jozky#include <bits/stdc++.h>
#include <unordered_map>
#define debug(a, b) printf("%s = %d\n", a, b);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
clock_t startTime, endTime;
//Fe~Jozky
const ll INF_ll= 1e18;
const int INF_int= 0x3f3f3f3f;
template <typename T> inline void read(T& x)
{T f= 1;x= 0;char ch= getchar();while (0 == isdigit(ch)) {if (ch == '-')f= -1;ch= getchar();}while (0 != isdigit(ch))x= (x << 1) + (x << 3) + ch - '0', ch= getchar();x*= f;
}
template <typename T> inline void write(T x)
{if (x < 0) {x= ~(x - 1);putchar('-');}if (x > 9)write(x / 10);putchar(x % 10 + '0');
}
void rd_test()
{
#ifdef LOCALstartTime= clock();freopen("in.txt", "r", stdin);
#endif
}
void Time_test()
{
#ifdef LOCALendTime= clock();printf("\nRun Time:%lfs\n", (double)(endTime - startTime) / CLOCKS_PER_SEC);
#endif
}
const int maxn= 3000;
int vis[maxn];
int fa[maxn];
int find(int x)
{if (fa[x] != x)return fa[x]= find(fa[x]);return x;
}
void join(int u, int v)
{u= find(u);v= find(v);if (u != v)fa[u]= v;
}
int main()
{//rd_test();int n, m1, m2;cin >> n >> m1 >> m2;if (m1 == n - 1 && m2 == n - 1) {printf("0");return 0;}int tot= min(n - m1 - 1, n - m2 - 1);printf("%d\n", tot);for (int i= 1; i <= 2 * n; i++)fa[i]= i;for (int i= 1; i <= m1; i++) {int u, v;cin >> u >> v;join(u, v);}for (int i= 1; i <= m2; i++) {int u, v;cin >> u >> v;join(u + n, v + n);}// for (int i= 1; i <= n; i++) {// printf("%d ", fa[i + n]);// }// printf("\n");for (int i= 1; i <= n; i++) {for (int j= 1; j <= n; j++) {if (i == j)continue;if (find(i) != find(j)) {if (find(i + n) != find(j + n)) {printf("%d %d\n", i, j);join(i, j);join(i + n, j + n);tot--;if (tot == 0)return 0;}}}}return 0;//Time_test();
}

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

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

相关文章

ASP.NET Core 实现带认证功能的Web代理服务器

引言最近在公司开发了一个项目&#xff0c;项目部署架构图如下&#xff1a;思路如图中文本所述&#xff0c;公司大数据集群不允许直接访问外网&#xff0c;需要一个网关服务器代理请求&#xff0c;本处服务器A就是边缘代理服务器的作用。通常技术人员最快捷的思路是在服务器A上…

[ZJOI2010] 排列计数(dp + 组合数)

problem luogu-P2606 solution 我们对 i−⌊i2⌋i-\lfloor\frac i2\rfloori−⌊2i​⌋ 远没有 i−2∗i,2∗i1i-2*i,2*i1i−2∗i,2∗i1 敏感&#xff0c;这其实就是个二叉树&#xff0c;而且是个小根堆。 每个点的值都小于左右儿子的值&#xff08;如果有左右儿子&#xff0…

Unfair contest(个人做法)

Unfair contest 题意&#xff1a; 两个人参赛&#xff0c;n个评委打分&#xff0c;去掉s个最高分&#xff0c;去掉t个最低分&#xff0c;剩下分求平均分&#xff0c;平均分大的获胜。你是第n个评委&#xff0c;此时已知前n-1个评委所打分数&#xff0c;现在轮到你打分&#x…

ASP.NET Core 进程外(out-of-process)托管(7)《从零开始学ASP.NET CORE MVC》

本文出自《从零开始学ASP.NET CORE MVC》推荐文章&#xff1a;ASP.NET Core 进程内(InProcess)托管ASP.NET Core 进程内(InProcess)托管我们先简单回顾下 ASP.NET Core 中,要配置InProcess的服务器&#xff0c;需要在项目文件中添加< AspNetCoreHostingModel >元素&#…

[CQOI2017] 老C的键盘(树形dp + 组合数)

problem luogu-P3757 solution observation:\text{observation}:observation: hi/2−hih_{i/2}-h_ihi/2​−hi​ 的大小关系&#xff0c;其实就是个二叉树的大小关系。 这很类似之前的排列 dpdpdp &#xff0c;迁移过来&#xff0c;我们尝试 f(i,j):if(i,j):if(i,j):i 在子树…

Educational Codeforces Round 112 (Rated for Div. 2)

Educational Codeforces Round 112 (Rated for Div. 2) 题号题目知识点APizzaForcesBTwo TablesCCoin RowsDSay No to PalindromesEBoring Segments尺取线段树FGood GraphLCT(未补)

eShopOnContainers 知多少[10]:部署到 K8S | AKS

1. 引言断断续续&#xff0c;感觉这个系列又要半途而废了。趁着假期&#xff0c;赶紧再更一篇&#xff0c;介绍下如何将eShopOnContainers部署到K8S上&#xff0c;进而实现大家常说的微服务上云。2. 先了解下 Helm读过我上篇文章ASP.NET Core 借助 K8S 玩转容器编排的同学&…

[HEOI2013] SAO(dp + 组合数 + 前缀和)

problem luogu-P4099 solution 两篇前提题解&#xff1a;排列计数&#xff0c;老C的键盘 想必已经看了 CQOI2017 老C的键盘 一题题解了。 这里直接考虑优化状态转移方程。 我们发现 f(u,i),f(v,j)f(u,i),f(v,j)f(u,i),f(v,j)&#xff0c;当枚举 jjj 后&#xff0c;对应的…

cf1555A. PizzaForces

cf1555A. PizzaForces A. PizzaForces 题意&#xff1a; 有三种披萨&#xff0c;第一种有六块&#xff0c;需要花费15分钟&#xff0c;第二种有8块&#xff0c;需要花费20分钟&#xff0c;第三问有10块&#xff0c;需要花费25分钟。 现在要吃x块披萨&#xff0c;问最少时间花…

DI是实现面向切面和面向抽象的前提

DI越来越重要DI就是依赖注入&#xff0c;现在来说&#xff0c;大部分框架都是以DI为基础组件的&#xff0c;每一个框架都有自己的DI组件&#xff0c;像dotnet core&#xff0c;java spring等&#xff0c;也都为自己的框架量身打造了DI工具。面向对象的几个原则依赖倒置原则&…

[CQOI2017] 老C的任务(差分 + 树状数组 / K-D tree)

problem luogu-P3755 solution 这题第一眼矩阵内的点权值和&#xff0c;马上就是 K-D tree\text{K-D tree}K-D tree 不过脑子的敲。 这其实就是个二维数点问题&#xff0c;完全可以树状数组。 将矩阵差分成四个以原点为左下角的矩阵。 然后将基站按 xxx 轴排序&#xff0…

.net core 并发下的线程安全问题

抱歉&#xff0c;其实内容并不如题&#xff01;&#xff01;&#xff01;背景&#xff08;写测试demo所出现的异常&#xff0c;供大家学习与拍砖&#xff09;&#xff1a;.net core webapi项目&#xff0c;做了一个授权的filter&#xff08;真正的生产项目的话&#xff0c;JWT很…

cf1555B. Two Tables

cf1555B. Two Tables 题意&#xff1a; 一个大矩阵空间内放置一个矩阵a&#xff0c;现在要再往这个空间内放一个矩阵b&#xff0c;a移动距离len才能放下b&#xff0c;问len最小是多少 题解&#xff1a; 不难发现左右或上下移动是最佳的&#xff0c;斜着移动是最不好的。此时…

cf1555C Coin Rows

cf1555C Coin Rows 题意&#xff1a; 有一个两行m列的地图&#xff0c;每个格子都有对应的价值&#xff0c;有a&#xff0c;b两个人&#xff0c;都从左上角到右下角&#xff0c;且都只能向右向下走&#xff0c;a先出发&#xff0c;a每到一个格子&#xff0c;就会获得这个地方…

C#并行编程(2):.NET线程池

线程 Thread在总结线程池之前&#xff0c;先来看一下.NET线程。.NET线程与操作系统(Windows)线程有什么区别&#xff1f;.NET利用Windows的线程处理功能。在C#程序编写中&#xff0c;我们首先会新建一个线程对象System.Threading.Thread&#xff0c;并为其指定一个回调方法&…

[CQOI2015] 任务查询系统(主席树)

problem luogu-P3168 solution 主席树板题。 将一个任务拆成 lil_ili​ 秒开始&#xff0c;ri1r_i1ri​1 秒结束的两个任务。 但不建议以每一秒作为一个主席树版本&#xff0c;因为一秒中可能有若干个任务开始或结束。 不妨将所有任务按时刻排序&#xff0c;然后以每个任…

ASP.NET Core launchsettings.json文件(8)《从零开始学ASP.NET CORE MVC》:

本文出自《从零开始学ASP.NET CORE MVC》推荐文章&#xff1a;ASP.NET Core 进程外(out-of-process)托管ASP.NET Core launchsettings.json文件在本视频中&#xff0c;我们将讨论在ASP.NET Core项目中launchsettings.json文件的重要性。launchsettings.json文件您将在项目根文件…

[CQOI2017] 老C的方块(网络流染色建图)

problem luogu-P3756 solution 据说要做网络流 24\text{24}24 题中的《方格取数问题》和《骑士共存问题》。 &#xff1f;&#xff1f;&#xff1f;那个不是直接最小割吗&#xff1f;哦原来是从黑白染色来理解的。我还是太水了。 这种题之所以能用网络流做&#xff0c;是因…

cf1555D. Say No to Palindromes

cf1555D. Say No to Palindromes 题意&#xff1a; 给出一个字符串&#xff0c;长度为n&#xff0c;而且都是a,b,c三个字符构成的&#xff0c;然后有m个询问 每个询问给出l r&#xff0c;问要想这个区间内任意长度字串都不是回文子串&#xff0c;至少要改多少个字符 题解&am…

江湖召集:.NET开发者们看过来,这场长沙的开发者技术大会正是为你精心准备的大餐...

看过去&#xff0c;历史的尘埃与沧海桑田古语有云“近代中国&#xff0c;湖南独撑半边天”&#xff0c;湖南长沙&#xff0c;作为湖南省的省会&#xff0c;自古以来便是各界风云人士兴起之地。随着互联网时代的到来&#xff0c;长沙&#xff0c;这座历史悠久的文化名城&#xf…