当前位置:网站首页>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 .
 Insert picture description here

#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 ——
 Insert picture description here

#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;
}


原网站

版权声明
本文为[Keranyu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120622163604.html