当前位置:网站首页>Codeforces Round #793 (Div. 2)(A-D)
Codeforces Round #793 (Div. 2)(A-D)
2022-07-04 08:34:00 【ccsu_yuyuzi】
目录
A. Palindromic Indices
题意:给你一个回文串,你可以删除一个字符串,保证这个回文串还是一个回文串,问有几种删法
思路:只需要把中间一段相同的字符删除一个即可.
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
#define int long long
using namespace std;
const int N =5e5+10,mod=998244353;
void solve()
{
int n;
string s;
cin>>n>>s;
int cnt=0;
if(s.size()%2==0)
{
int l=(s.size()-1)/2;
for(int i=l;i>=0;i--)
{
if(s[i]==s[l])
cnt++;
else
break;
}
cnt*=2;
}
else
{
int l=s.size()/2;
for(int i=l;i>=0;i--)
{
if(s[i]==s[l])
cnt++;
else
break;
}
cnt=cnt*2-1;
}
cout<<cnt<<"\n";
return ;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}
B. AND Sorting
Problem - B - Codeforceshttps://codeforces.com/contest/1682/problem/B
题意:给你一个数组,有原本的升序的数组得来(原本是0,1,2,3...n-1),存在一个x,当(a[i]&a[j])==x的时候,即可进行交换,问当x最大是多少的时候我们可以从原数组得到题目所给的数组.
思路:要让x作为中转站可以将所有的不同位置上的数字进行两两交换,吧不在原来位置上的数字相&即可:
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
#define int long long
using namespace std;
const int N =5e5+10,mod=998244353;
void solve()
{
int n,x;
cin>>n;
int ans=-1;
for(int i=1;i<=n;i++)
{
cin>>x;
if(ans==-1&&x!=i-1)
{
ans=x;
}
else if(ans!=-1&&x!=i-1)
{
ans&=x;
}
}
cout<<ans<<"\n";
return ;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}
C. LIS or Reverse LIS?
题意:给你一个数组,你可以在它重新排列之后,求得它的正向的严格最长上升子序列的长度还有反向的严格最长上升子序列的长度.两者取最小值,求这个最小值最大是多少.
思路:我们用map记录所有数组元素的个数,map的长度即为他升序的最长长度,然后我们统计这个升序序列中每个元素超过2个的个数,将他们拼在右边,即为反向最长上升子序列的长度,但是由于可能左边的正向最长上升子序列的长度大于右边的反向最长上升子序列的长度.我们可以适当地把左边的一些数字移动到右边去.举个例子:
数组
1 1 1 2 3 4 4 4 4 4 4 5 6 6
我们进行操作后,分别把反向和正向的最长上升子序列放在两边:
1 2 3 4 5 6 6 4 1
这个时候结果的值为3,但是我们发现可以适当地移动一些左边的值到右边,就变成了:
1 2 4 5 6 6 4 3 1
如上操作即可求出答案
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
using namespace std;
const int N =5e5+10,mod=998244353;
map<int,int>ma;
int a[200005];
void solve()
{
ma.clear();
int n,x;
cin>>n;
for(int i=1;i<=n;i++)
cin>>x,ma[x]++;
if(n==1)
{
cout<<"1\n";
return ;
}
int len1=ma.size(),len2=0;
for(auto &it:ma)
{
if(it.second>=2)
len2++;
}
int ans=(len1+len2+1)/2;
cout<<ans<<"\n";
return ;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}
D. Circular Spanning Tree
Problem - D - Codeforceshttps://codeforces.com/contest/1682/problem/D
题意:给你一个字符串,(0-n-1)对应1-n点的度数的奇偶性,当当前的点的度数为奇数的时候,字符表示为'1',反之为'0'.我们要根据这个字符串构造一棵树出来.
思路:首先排除不可能成立的情况.我们知道树存在n-1调边,那么肯定存在偶数个度数为奇数的点,而且这些点度数要大于0.那么除此之外直接输出NO.
然后就是对于树的构造.我们可以把每个度数为奇数的点作为一条链的头,因为度数为奇数的点肯定有偶数个,那么必定有偶数条链,我们直接把链尾相连(都连到同一条链子的链尾,这样可以避免交叉).这样每个链尾本身有度数1,再去链接奇数个点,度数肯定就变成了偶数.即可成立.
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
using namespace std;
vector<int>wei;
void solve()
{
wei.clear();
int n,st=0;
string s;
cin>>n>>s;
int cnt=0,len=s.size();
for(int i=0;i<len;i++)
{
if(s[i]=='1')
cnt++,st=i;
}
if(cnt<2||cnt%2==1)
{
cout<<"NO\n";
return ;
}
cout<<"YES\n";
for(int i=0;i<len;i++)
{
if(s[(st+i+1)%len]=='1')
{
wei.push_back((st+i)%len);
continue;
}
cout<<(st+i)%len+1<<" "<<(st+i+1)%len+1<<"\n";
}
for(int i=1;i<wei.size();i++)
{
cout<<wei[0]+1<<" "<<wei[i]+1<<"\n";
}
return ;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}
边栏推荐
- PHP session variable passed from form - PHP
- 1、卡尔曼滤波-最佳的线性滤波器
- 墨者学院-Webmin未经身份验证的远程代码执行
- WordPress get_ Users() returns all users with comparison queries - PHP
- 一文了解数据异常值检测方法
- Unity text superscript square representation +text judge whether the text is empty
- Comparison between sentinel and hystrix
- snipaste 方便的截图软件,可以复制在屏幕上
- How does Xiaobai buy a suitable notebook
- DM8 command line installation and database creation
猜你喜欢
C, Numerical Recipes in C, solution of linear algebraic equations, Gauss Jordan elimination method, source code
What does range mean in PHP
Chrome is set to pure black
根据数字显示中文汉字
[performance test] read JMeter
Redis 哨兵机制
SSRF vulnerability exploitation - attack redis
1. Getting started with QT
1. Qt入门
The second session of the question swiping and punching activity -- solving the switching problem with recursion as the background (I)
随机推荐
如何通过antd的upload控件,将图片以文件流的形式发送给服务器
Li Kou today's question -1200 Minimum absolute difference
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources
snipaste 方便的截图软件,可以复制在屏幕上
The right way to capture assertion failures in NUnit - C #
ctfshow web255 web 256 web257
DM8 uses different databases to archive and recover after multiple failures
Question 49: how to quickly determine the impact of IO latency on MySQL performance
Leetcode 23. 合并K个升序链表
1. Kalman filter - the best linear filter
string. Format without decimal places will generate unexpected rounding - C #
【性能測試】一文讀懂Jmeter
团体程序设计天梯赛-练习集 L1-006 连续因子
DM database password policy and login restriction settings
Fault analysis | MySQL: unique key constraint failure
Cannot click button when method is running - C #
Using the rate package for data mining
Redis sentinel mechanism
es6总结
猜数字游戏