当前位置:网站首页>Codeforces Round #793 (Div. 2) A B C
Codeforces Round #793 (Div. 2) A B C
2022-06-12 06:34:00 【Keranyu】
A terrible scene :(
The topic still has a certain level of thinking .
A — Palindromic Indices
The main idea of the topic : Give a palindrome string , How many cases are there when a character in the string is deleted so that it is still a palindrome string ?
After deleting a character, it will be realigned , Think about it and you will find that the key is how many consecutive identical characters are in the middle position .
#include<bits/stdc++.h>
using namespace std;
int t;
int main()
{
cin>>t;
while(t--)
{
int n,cnt=0;
string s;
scanf("%d",&n);
cin>>s;
if(n==1)
{
cout<<0<<'\n';
continue;
}
for(int i=(n-1)/2;i>=0;i--)
{
if(s[i]==s[(n-1)/2])
cnt++;
else break;
}
cnt*=2;
if(n&1) cnt--;
printf("%d\n",cnt);
}
return 0;
}
B — AND Sorting
The main idea of the topic : from 0—n-1 The non repeating array of grows to n Of the array . Ask for one X, Any two numbers in the array that are not in the right size position are bitwise summed to get X You can swap places . Finally, make the array orderly , seek X The maximum of .
X Must be a sub mask of all elements that are not in their correct position . The result of bitwise sum of all these numbers is the common sub mask of the largest number . And the number corresponding to this string of sub masks must be in this number sequence . In this way, any two numbers that are not in the correct position can pass through X Realize exchange , At last, the sequence is in order .
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<set>
#define ll long long
#define inf 0x3f3f3f
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
using namespace std;
const int N=1e6+10;
const int mod=13331;
inline int read()
{
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*10+ch-48;ch=getchar();}
return x*f;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int ans=(1<<30)-1;
for(int i=0;i<n;i++)
{
int x=read();
if(x!=i)//x Not in the right position
ans=ans&x;
}
printf("%d\n",ans);
}
return 0;
}
C — LIS or Reverse LIS?
The main idea of the topic : Given an array of positive integers a.a’ yes a Inverse array of .LIS(a) Express a The longest strictly increasing subsequence length in . X = m i n [ L I S ( a ) , L I S ( a ′ ) ] X=min [LIS(a),LIS(a') ] X=min[LIS(a),LIS(a′)], If you can rearrange the array at will , Your task is to determine the maximum possible X.
The answer is in the array ( Number of occurrences >=2 The number of )+( The number of occurrences is 1 Divide the number of numbers by 2, Rounding up ). Starting to be lazy ——
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<set>
#define ll long long
#define inf 0x3f3f3f
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
using namespace std;
const int N=1e6+10;
const int mod=13331;
inline int read()
{
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*10+ch-48;ch=getchar();}
return x*f;
}
map<int,int>s;
int main()
{
int t;
cin>>t;
while(t--)
{
int n=read();
s.clear();
int cnt1=0,cnt2=0,a[200010];
for(int i=1;i<=n;i++)
a[i]=read(),s[a[i]]++;
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)
{
if(a[i]==a[i-1]) continue;
if(s[a[i]]>=2) cnt2++;
else cnt1++;
}
cout<<cnt2+(cnt1+1)/2<<endl;
}
return 0;
}
边栏推荐
- Touch screen setting for win7 system dual screen extended display
- Multithreading (IV) -- no lock (IV) -- unsafe
- AI operation ch8
- Tomato learning notes dvector and other basics
- Node. Detailed installation tutorial of CPM and cnpm (including error resolution)
- Leetcode January 13 daily question 747 At least twice the maximum number of other numbers
- torch在高版本训练的模型在低版本中使用报错
- Deep and detailed analysis of PHP one sentence Trojan horse
- LeetCode-2034. Stock price fluctuation
- Information content security experiment of Harbin Institute of Technology
猜你喜欢

Redis basic notes

Install MySQL tutorial

Multithreading mode (I) -- protective pause and join source code

About session Getattribute, getattribute error

Leetcode January 10 daily question 306 Additive number

leetcode 300. Longest increasing subsequence

勤于奋寻找联盟程序方法介绍

Automatic modeling of Interchange

Dlib face detection

Pytorch implementation of regression model
随机推荐
The eighth day of June training - prefix and
MLP sensor
六月集训 第二天——字符串
SQL注入原理即sqli-labs搭建,sql注入简单实战
Multithreading (IV) -- no lock (IV) -- unsafe
LeetCode-1490. Clone n-ary tree
The first principle of thinking method
[word] word 2010 recording macro batch replacing paragraph marks in the selected text
GET 和 POST 的区别及留言板代码实现
Solution: unsatisfieddependencyexception: error creating bean with name 'authaspect':
It only takes 10 minutes to understand the underlying principle of NiO
Bert use
The seventh day of June training - hash table
PHP 读写 COOKIE
Nodemon cannot load the file c:\users\administrator\appdata\roaming\npm\nodemon PS1, because script execution is prohibited in this system
SQL注入——联合查询union
LeetCode个人题解(剑指offer3-5)3.数组中重复的数字,4.二维数组中的查找,5.替换空格
Pytorch implementation of regression model
六月集训 第七日 ——哈希表
六月集训 第一日——数组