当前位置:网站首页>"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 7
"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 7
2022-08-10 15:05:00 【Bold!】
C.Constructive Problems Never Die
Question meaning:
Given a sequence A of length n, Ai<=n.
Please find a permutation P such that for all i, Pi!=Ai.
If possible, output YES and output the permutation.
Otherwise, output NO.
Ideas:
The input is an array of a, and the b array is preprocessed first, b[i]=i.
When i
Next, consider b[n].
If b[n]==a[n],
Find the previous b[i] and b[n] to exchange,
If b[n]!=a[n]&&The exchanged a[i]!=b[i],
means that it works and exits the loop.
If that doesn't work, revert to the way it was before.
If no feasible ones are found after traversing the previous ones,
will output NO.
Code:
#include using namespace std;const int N = 1e5+10;int n,a[N],b[N];int main(){int t;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=n;i++) {scanf("%d",&a[i]);b[i]=i;}for(int i=1;i
F.Candies
Question meaning:
Given a series of circular numbers, each time you can choose adjacent equal numbers or numbers that add = x
and eliminate them to get a candy,Ask how many candies you can get.
Thinking:
Double pointer.
First, the candies that satisfy the elimination while processing the input,
ans++,j– after each elimination.
If it is not satisfied, it is j++. When j==0, because j-1 cannot be realized,
So it can only be j++.
Because it is circular, the last input may be eliminated with the first
input, so the last two pointers are used, and
handles the first and last.
The first i=0, the last j–.
Because each input will go to the next digit of the last existing digit
, so you need j-go back to the last digit first.
Code:
#include using namespace std;const int N = 1e5+10;int a[N];int n,x,ans,i,j;int main(){scanf("%d%d",&n,&x);for(i=0;i0){if(a[j]==a[j-1]||a[j]+a[j-1]==x){ans++;j--;}else j++;}else j++;}i=0;j--;while(j>i&&(a[j]==a[i]||a[j]+a[i]==x)){j--;i++;ans++;}printf("%d\n",ans);return 0;}
G.Regular Expression
Question meaning:
Give q queries, each query gives a string consisting of lowercase letters.
Please output the length and number of the shortest regular expression matched by this string.
Ideas:
After analyzing the examples given and testing with test sites,
learned that only .* + can shorten the string length.
. Can be used in any position, indicating an arbitrary letter, * and + cannot be used in the first position,
* means copy the preceding letter any number of times (can be 0 times), + means inAdd any string of any length (>1) after it.
Then each regular expression can only start with a letter or ..
(1) When the string length is 1,
matches itself and .
(2) When the string length is 2,
1> All characters in the string are the same, such asaa
Then the matching cases are:
Starting with the letter a:
aa
a+
a*
a.
Starting with .:
…
.+
.*
.a
There are 8 types in total.
2> Not all characters are the same: such as ab
ab
a+
a.
…
.+
.b
(3) When length>=3
We found that .+ must match any string.
Therefore, when length>=3, the shortest length must be 2.
1> When all letters are the same, such as aaa
Start with a letter:
a+
a*
Start with a dot:
.+
.*
Totalfour.
2>Not all letters are the same:
Then you can't use *
that means copying, so only
a+
.+
There are two cases in total
As for the modulo mentioned in the title, it's pure scaring!
Code:
#include using namespace std;int main(){int q;string s;scanf("%d",&q);while(q--){cin>>s;if(s.size()==1) puts("1 2");else{bool f=1;for(int i=1;i
边栏推荐
- How does vue clear the tab switching cache problem?
- Steam教育在新时代中综合学习论
- 等保2.0一个中心三重防护指的是什么?如何理解?
- PAT甲级 1014 排队等候(队列大模拟+格式化时间)
- 640. Solving Equations: Simple Simulation Problems
- 容器化 | 在 S3 实现定时备份
- “国资云”和“国家云”能给市场带来怎样的变革?
- 正则表达式(包含各种括号,echo,正则三剑客以及各种正则工具)
- 老板加薪!看我做的WPF Loading!!!
- High-paid programmers & interview questions series 135 How do you understand distributed?Do you know CAP theory?
猜你喜欢
随机推荐
司空见惯 - 股市狠狠下跌后,何時能反弹?
富爸爸穷爸爸之读书笔记
微信扫码登陆(1)—扫码登录流程讲解、获取授权登陆二维码
XML基本学习
小程序-语音播报功能
[Gazebo Introductory Tutorial] Lecture 3 Static/Dynamic Programming Modeling of SDF Files
Go Context基本使用
antd组件中a-modal设置固定高度,内容滚动显示
格式化输出当前时间
Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
《论文阅读》PLATO: Pre-trained Dialogue Generation Model with Discrete Latent Variable
Rich Dad Poor Dad Reading Notes
BFT机器人带你走进智慧生活 ——探索遨博机器人i系列的多种应用
公网IP和内网IP的区别[通俗易懂]
Zhaoqi Technology Innovation High-level Talent Entrepreneurship Competition Platform
TestLink导出用例转换工具
SWIG教程《二》
【有限元分析】异型密封圈计算泄漏量与参数化优化过程(带分析源文件)
易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
redhat替换yum源时redhat.repo无法删除或无法禁用的问题解决方法