20240528训练题目(2022 国际大学生程序设计竞赛亚洲区域赛 (南京站))

D题

题目描述

You’re the researcher of the International Chat Program Company (ICPC). Today, you discover the following chat history when reviewing some research data.

SUA (2022/12/04 23:01:25)

I’m out of ideas for competitive programming problems! Please give me a problem about sequences.

BOT (2022/12/04 23:01:27)

Sure. Here is a competitive programming problem about sequences.

Given an integer sequence a 1 , a 2 , ⋯   , a n a_1, a_2, \cdots, a_n a1,a2,,an of length n n n and four other integers k k k, m m m, c c c and d d d, your goal is to maximize the k k k-th largest element in the sequence.

To achieve the goal, you can perform the following operation at most once: select a continuous sub-array of length m m m and add an arithmetic sequence with length m m m, initial term c c c and common difference d d d to the sub-array.

More formally, you can select an integer p p p satisfying 1 ≤ p ≤ n − m + 1 1 \le p \le n - m + 1 1pnm+1 and add ( c + d i ) (c + di) (c+di) to a p + i a_{p + i} ap+i for all KaTeX parse error: Expected 'EOF', got '&' at position 9: 0 \le i &̲lt; m.

Calculate the largest possible value of the k k k-th largest element in the sequence after at most one operation.

The k k k-th largest element in the sequence is the k k k-th element in the sorted sequence after sorting all elements from the largest to the smallest. For example, the 3 3 3rd largest element in sequence { 5 , 7 , 1 , 9 } \{5, 7, 1, 9\} {5,7,1,9} is 5 5 5, while the 3 3 3rd largest element in sequence { 9 , 7 , 5 , 9 } \{9, 7, 5, 9\} {9,7,5,9} is 7 7 7.

SUA (2022/12/05 00:15:17)

This problem seems difficult! Please teach me the solution.

BOT (2022/12/05 00:15:30)

Sure. Firstly, we can…

[DATA EXPUNGED]

Unfortunately, parts of the chat history are lost due to a disk failure. You’re amazed at how a chat program can create a competitive programming problem. To verify whether the chat program can create valid problems, you decide to try on this problem.

Input

There is only one test case in each test file.

The first line contains five integers n n n, k k k, m m m, c c c and d d d ( 1 ≤ k , m ≤ n ≤ 2 × 1 0 5 1 \le k, m \le n \le 2 \times 10^5 1k,mn2×105, 0 ≤ c , d ≤ 1 0 9 0 \le c, d \le 10^9 0c,d109) indicating the length of the sequence, your goal, the length, initial term and common difference of the arithmetic sequence.

The second line contains n n n integers a 1 , a 2 , ⋯   , a n a_1, a_2, \cdots, a_n a1,a2,,an ( 0 ≤ a i ≤ 1 0 9 0 \le a_i \le 10^9 0ai109) indicating the sequence.

Output

Output one line containing one integer indicating the largest possible value of the k k k-th largest element in the sequence after at most one operation.

AC代码

//二分
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5+100;
int n,k,m,c,d,a[N],f[N];
bool check(int x) {
	memset(f,0,sizeof(f));
	int cnt=0;
	for(int i=1; i<=n; i++) {
		if(a[i]>=x)cnt++;
	}
	if(cnt>=k)return true; 
	for(int i=1; i<=n; i++) {
		if(a[i]<x)
		{
			int l,r,p,maxx,minn;
			l=max(i-m+1,0ll);
			maxx=a[i]+c+d*(i-l);
			if(maxx<x)continue; 
			minn=a[i]+c;
			if(d==0)p=0;
			else p=(x-minn-1)/d+1;
			p=max(p,0ll);
			r=i-p;
			f[l]++;
			f[r+1]--;
		}
	}
	int res=0;
	for(int i=1; i<=n; i++) {
		f[i]+=f[i-1];
		res=max(res,f[i]);
	}
	return res+cnt>=k;
}
signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>k>>m>>c>>d;
	for(int i=1; i<=n; i++)cin>>a[i];
	int l=0,r=1e18,mid;
	while(l<=r) {
		mid=(l+r)/2;
		if(check(mid))l=mid+1;
		else r=mid-1;
	}
	cout<<r<<'\n';
	return 0;
}

G题

题目描述

You are lost deep in the forest. The only thing that is still accompanying you is your stoat. It has an initial attack of 1 1 1. It is your only Beast at the beginning.

A single path revealed itself before you. On the path are n n n event marks. Every event mark falls into one of the following:

  • Card Choice: A dentizen of the forest shall grace your caravan. You will gain an additional Beast. It will always have an initial attack of 1 1 1.
  • Mysterious Stone: You will be compelled to make a worthy sacrifice. Two Beasts from your caravan of your choice will perform the ritual: one to be lost forever, adding its attack onto the other. Failure to perform the ritual will forbid you to go on.
  • Fork in the Road: You will choose to trigger either a Card Choice or a Mysterious Stone. You can’t choose to do nothing.

When you walk through the winding road, the event marks will be triggered in order. Find out the maximum average of attack for your Beasts you can achieve after all event marks are completed.

Input

There are multiple test cases. The first line of the input contains an integer T T T indicating the number of test cases. For each test case:

The first line contains one integer n n n ( 1 ≤ n ≤ 1 0 6 1 \le n \le 10^6 1n106) indicating the number of event marks.

The second line contains n n n integers a 1 , a 2 , ⋯   , a n a_1, a_2, \cdots, a_n a1,a2,,an ( − 1 ≤ a i ≤ 1 -1 \le a_i \le 1 1ai1) where a i a_i ai indicates the type of the i i i-th event mark: 1 1 1 means a Card Choice, − 1 -1 1 means a Mysterious Stone and 0 0 0 means a Fork in the Road.

It’s guaranteed that the sum of n n n over all test cases does not exceed 1 0 6 10^6 106.

Output

For each test case output one line.

If it is impossible to complete all event marks, output one integer − 1 -1 1.

Otherwise it can be proven that the answer is a rational number p ′ q ′ \frac{p'}{q'} qp. Output two integers p p p and q q q where p q \frac{p}{q} qp is the simplest fraction representation of p ′ q ′ \frac{p'}{q'} qp.

p q \frac{p}{q} qp is the simplest fraction representation of p ′ q ′ \frac{p'}{q'} qp if p q = p ′ q ′ \frac{p}{q} = \frac{p'}{q'} qp=qp and the greatest common divisor of p p p and q q q is 1 1 1.

AC代码

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
int a[N];
void solve()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)	cin>>a[i];
	int p=1,q=1,c=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==1)
		{
			p++;
			q++;
		}
		else if(a[i]==-1)
		{
			q--;
			if(q<1)
			{
				if(c<=0)
				{
					cout<<"-1"<<'\n';
					return;
				}
				else//不合理时返回时,将0转成”-1“使用
				{
					c--;
					p++;
					q+=2;
				}
			}
		}
		else if(a[i]==0)
		{
			if(q<2)	q++,p++;//不合理时返回时,将0转成”1“使用
			else	c++,q--;//0用来趋向最大值,将0转成”-1“使用
		}
	}
	cout<<p/__gcd(q,p)<<' '<<q/__gcd(p,q)<<'\n';
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--)	solve();
	return 0; 
}

I题

题目描述

Given a string S = s 0 s 1 ⋯ s n − 1 S = s_0s_1\cdots s_{n-1} S=s0s1sn1 of length n n n, let f ( S , d ) f(S, d) f(S,d) be the string obtained by shifting S S S to the left d d d times. That is f ( S , d ) = s ( d + 0 )   m o d   n s ( d + 1 )   m o d   n ⋯ s ( d + n − 1 )   m o d   n f(S, d) = s_{(d+0)\bmod n}s_{(d+1)\bmod n}\cdots s_{(d+n-1)\bmod n} f(S,d)=s(d+0)modns(d+1)modns(d+n1)modn. We say S S S is a perfect palindrome if for all non-negative integer d d d, f ( S , d ) f(S, d) f(S,d) is a palindrome.

You’re now given a string A = a 0 a 1 ⋯ a n − 1 A = a_0a_1\cdots a_{n-1} A=a0a1an1 of length n n n consisting only of lower-cased English letters. You can perform the following operation on A A A any number of times (including zero times): Choose an integer i i i such that KaTeX parse error: Expected 'EOF', got '&' at position 9: 0 \le i &̲lt; n and change a i a_i ai to any lower-cased English letter.

Calculate the minimum number of operations needed to change A A A into a perfect palindrome.

We say a string P = p 0 p 1 ⋯ p n − 1 P = p_0p_1\cdots p_{n-1} P=p0p1pn1 of length n n n is a palindrome, if p i = p n − 1 − i p_i = p_{n-1-i} pi=pn1i for all KaTeX parse error: Expected 'EOF', got '&' at position 9: 0 \le i &̲lt; n.

Input

There are multiple test cases. The first line of the input contains an integer T T T indicating the number of test cases. For each test case:

The first and only line contains a string a 0 a 1 ⋯ a n − 1 a_0a_1\cdots a_{n-1} a0a1an1 ( 1 ≤ n ≤ 1 0 5 1 \le n \le 10^5 1n105) consisting only of lower-cased English letters.

It is guaranteed that the total length of strings of all test cases will not exceed 1 0 6 10^6 106.

Output

For each test case output one line containing one integer indicating the minimum number of operations needed to change A A A into a perfect palindrome.

AC代码

//签到题
#include<bits/stdc++.h>
using namespace std;
int v[27];
void solve()
{
	memset(v,0,sizeof(v));
	string s;cin>>s;
	int ma=0;
	for(int i=0;i<s.size();i++)	ma=max(ma,++v[s[i]-'a']);
	cout<<s.size()-ma<<'\n';
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;cin>>t;
	while(t--)	solve();
	return 0;
}
  • 21
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值