当前位置:网站首页>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;
}
边栏推荐
- ctfshow web255 web 256 web257
- Leetcode 23. 合并K个升序链表
- [go basics] 2 - go basic sentences
- SQL statement view SQL Server 2005 version number
- Leetcode topic [array] -136- numbers that appear only once
- 力扣今日题-1200. 最小绝对差
- yolov5 xml数据集转换为VOC数据集
- Ecole bio rushes to the scientific innovation board: the annual revenue is 330million. Honghui fund and Temasek are shareholders
- Scanf read in data type symbol table
- Use preg_ Match extracts the string into the array between: & | people PHP
猜你喜欢
How does Xiaobai buy a suitable notebook
Collections in Scala
DM database password policy and login restriction settings
1、卡尔曼滤波-最佳的线性滤波器
Newh3c - network address translation (NAT)
Système de surveillance zabbix contenu de surveillance personnalisé
ZABBIX monitoring system custom monitoring content
[CV] Wu Enda machine learning course notes | Chapter 9
What if I forget the router password
Unity-Text上标平方表示形式+text判断文本是否为空
随机推荐
[Chongqing Guangdong education] National Open University spring 2019 455 logistics practice reference questions
The text box displays the word (prompt text) by default, and the text disappears after clicking.
DM8 database recovery based on point in time
2022 examination questions for safety managers of metal and nonmetal mines (underground mines) and examination papers for safety managers of metal and nonmetal mines (underground mines)
What if the wireless network connection of the laptop is unavailable
Moher college phpMyAdmin background file contains analysis traceability
Wechat has new functions, and the test is started again
Flutter 集成 amap_flutter_location
How to solve the problem that computers often flash
SSRF vulnerability exploitation - attack redis
Conversion of yolov5 XML dataset to VOC dataset
Unity write word
Système de surveillance zabbix contenu de surveillance personnalisé
FRP intranet penetration, reverse proxy
2022 tower crane driver examination and tower crane driver examination questions and analysis
Comparison between sentinel and hystrix
zabbix监控系统部署
Using the rate package for data mining
Application of isnull in database query
ZABBIX monitoring system deployment