当前位置:网站首页>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 - Codeforces
https://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 - Codeforces
https://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;
}边栏推荐
- 2022 gas examination registration and free gas examination questions
- NewH3C——ACL
- What if I forget the router password
- Example analysis of C # read / write lock
- DM8 tablespace backup and recovery
- Système de surveillance zabbix contenu de surveillance personnalisé
- go-zero微服务实战系列(九、极致优化秒杀性能)
- zabbix监控系统自定义监控内容
- Snipaste convenient screenshot software, which can be copied on the screen
- Application of isnull in database query
猜你喜欢

How to solve the problem of computer jam and slow down
![[test de performance] lire jmeter](/img/c9/25a0df681c7ecb4a0a737259c882b3.png)
[test de performance] lire jmeter

小程序容器技术与物联网 IoT 可以碰撞出什么样的火花

L1 regularization and L2 regularization

Do you know about autorl in intensive learning? A summary of articles written by more than ten scholars including Oxford University and Google

Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service

Unity text superscript square representation +text judge whether the text is empty

manjaro安装微信

Collections in Scala

Sqli labs download, installation and reset of SQL injection test tool one of the solutions to the database error (# 0{main}throw in d:\software\phpstudy_pro\www\sqli labs-...)
随机推荐
Cancel ctrl+alt+delete when starting up
Three paradigms of database design
Redis 哨兵机制
What determines vacuum permittivity and vacuum permeability? Why do these two physical quantities exist?
WordPress get_ Users() returns all users with comparison queries - PHP
Application of isnull in database query
根据数字显示中文汉字
How to re enable local connection when the network of laptop is disabled
Difference between static method and non static method (advantages / disadvantages)
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
Flutter integrated amap_ flutter_ location
snipaste 方便的截图软件,可以复制在屏幕上
es6总结
1、卡尔曼滤波-最佳的线性滤波器
Système de surveillance zabbix contenu de surveillance personnalisé
Need help resetting PHP counters - PHP
[performance test] read JMeter
Comprendre la méthode de détection des valeurs aberrantes des données
C # implements a queue in which everything can be sorted
Unity write word
https://codeforces.com/contest/1682/problem/A