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

embedded/2024/9/22 23:50:00/

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

http://www.ppmy.cn/embedded/43648.html

相关文章

STM32-11-电容触摸按键

STM32-01-认识单片机 STM32-02-基础知识 STM32-03-HAL库 STM32-04-时钟树 STM32-05-SYSTEM文件夹 STM32-06-GPIO STM32-07-外部中断 STM32-08-串口 STM32-09-IWDG和WWDG STM32-10-定时器 STM32电容触摸按键 电容触摸按键原理&#xff1a; 无手指触摸&#xff1a;上电时&…

常见排序算法之插入排序

目录 一、直接插入排序 1.1 什么是插入排序 1.2 代码思路 1.3 C语言源码 二、希尔排序 2.0 插入排序的弊端 2.1 什么是希尔排序&#xff1f; 2.2 排序思路 2.3 C语言源码 一、直接插入排序 1.1 什么是插入排序 插入排序是一种简单直观的排序算法&#xff0c;它通过构…

图像上下文学习|多模态基础模型中的多镜头情境学习

【原文】众所周知&#xff0c;大型语言模型在小样本上下文学习&#xff08;ICL&#xff09;方面非常有效。多模态基础模型的最新进展实现了前所未有的长上下文窗口&#xff0c;为探索其执行 ICL 的能力提供了机会&#xff0c;并提供了更多演示示例。在这项工作中&#xff0c;我…

elasticdump和ESM

逐个执行如下命令&#xff1b; 1.拷贝analyzer如分词&#xff08;需要分词器&#xff0c;可能不成功&#xff0c;不影响复制&#xff09; ./elasticdump --inputhttp://[来源IP地址]:9200/[来源索引] --outputhttp://[目标IP地址]:9200/[目标索引] --typeanalyzer 2.拷贝映射…

unity 制作app实现底部导航栏和顶部状态栏

前段时间在用unity制作一个app&#xff0c;发现有个问题用unity制作的app&#xff0c;他默认是没有顶部状态栏的&#xff0c;也没有底部的导航栏&#xff0c;是一个全部覆盖的状态。但仔细观察可以发现&#xff0c;正常app&#xff0c;顶部状态栏是有的&#xff0c;而且是透明的…

HBase安装

安装HBase 提示&#xff1a;需要安装好hadoop和zookeeper 安装zookeeper可参考 一、确定HBase版本 去网站确认 https://hbase.apache.org/book.html#hadoop二、下载HBase安装包 去清华大学镜像站下载 https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/三、安装HBase …

Java | Leetcode Java题解之第103题二叉树的锯齿形层序遍历

题目&#xff1a; 题解&#xff1a; class Solution {public List<List<Integer>> zigzagLevelOrder(TreeNode root) {List<List<Integer>> ans new LinkedList<List<Integer>>();if (root null) {return ans;}Queue<TreeNode> n…

HCIP的学习(24)

第七章&#xff0c;VLAN—虚拟局域网 ​ 通过在交换机上部署VLAN技术&#xff0c;将一个规模较大的广播域在逻辑上划分成若干个不同的、规模较小的广播域。 ​ IEEE 802.1Q标准----虚拟桥接局域网标准----Dot1Q标准 标签协议标识符&#xff1a;0x8011&#xff08;代表数据帧是8…