https://vjudge.net/contest/419545

目录

  • A - Airplane AtCoder - abc129_a
  • B - Balance AtCoder - abc129_b
  • C - Typical Stairs AtCoder - abc129_c
  • D - The Rank CodeForces - 1017A
  • E - The Bits CodeForces - 1017B
  • F - News Distribution CodeForces - 1167C
  • G - Regular Bracket Sequence Again? Gym - 102766D
  • H - Singhal and GCD Gym - 102767C
  • I - Super Jumping! Jumping! Jumping! HDU - 1087
  • J - Max Sum HDU - 1231

A - Airplane AtCoder - abc129_a

Problem Statement
There are three airports AAA, BBB and CCC, and flights between each pair of airports in both directions.

A one-way flight between airports AAA and BBB takes PPP hours, a one-way flight between airports BBB and CCC takes QQQ hours, and a one-way flight between airports CCC and AAA takes RRR hours.

Consider a route where we start at one of the airports, fly to another airport and then fly to the other airport.

What is the minimum possible sum of the flight times?

Constraints
1≤P,Q,R≤1001 ≤ P , Q , R ≤ 1001≤P,Q,R≤100 All values in input are integers.

取 min(P+Q,P+R,Q+R)min(P+Q, P+R, Q+R)min(P+Q,P+R,Q+R) 即可。


B - Balance AtCoder - abc129_b

Problem Statement
We have NNN weights indexed 111 to NNN . The mass of the weight indexed iii is WiW _iWi​ .

We will divide these weights into two groups: the weights with indices not greater than TTT , and those with indices greater than TTT , for some integer 1≤T<N1 ≤ T < N1≤T<N . Let S1S_1S1​ be the sum of the masses of the weights in the former group, and S2S_2S2​ be the sum of the masses of the weights in the latter group.

Consider all possible such divisions and find the minimum possible absolute difference of S1S_1S1​ and S2S_2S2​ .

Constraints
2≤N≤100,1≤Wi≤1002 ≤ N ≤ 100,1 ≤ W_i ≤ 1002≤N≤100,1≤Wi​≤100 All values in input are integers.

数据范围很小,枚举 TTT 的位置,前后分别求和做差,取差的最大值即可。


C - Typical Stairs AtCoder - abc129_c

Problem Statement
There is a staircase with NNN steps. Takahashi is now standing at the foot of the stairs, that is, on the 000-th step. He can climb up one or two steps at a time.

However, the treads of the a1a_1a1​-th, a2a_2a2​-th, a3a_3a3​-th, … , aMa_MaM​-th steps are broken, so it is dangerous to set foot on those steps.

How many are there to climb up to the top step, that is, the NNN-th step, without setting foot on the broken steps? Find the count modulo 1,000,000,0071 ,000,000,0071,000,000,007 .

Constraints
1≤N≤105,0≤M≤N−1,1≤a1<a2<...<aM≤N−11 ≤ N ≤ 10^5 ,0 ≤ M ≤ N − 1,1 ≤ a_1 < a_2 < . . . < a_M ≤ N − 11≤N≤105,0≤M≤N−1,1≤a1​<a2​<...<aM​≤N−1

基本模型是动态规划,第 iii 个台阶的情况来自于第 i−1,i−2i-1,i-2i−1,i−2 个台阶的情况,dp[i]=(dp[i−1]+dp[i−2])%moddp[i] = (dp[i - 1] + dp[i - 2]) \% moddp[i]=(dp[i−1]+dp[i−2])%mod,若第 kkk 个台阶坏掉,则 dp[k]=0dp[k] = 0dp[k]=0,另外特别注意第一个台阶和第二个台阶坏掉的情况。


D - The Rank CodeForces - 1017A

Problem Description
John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.

There are n students, each of them has a unique id (from 1 to n). Thomas’s id is 1. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.

In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids.

Please help John find out the rank of his son.

Input
The first line contains a single integer n (1≤n≤1000) — the number of students.

Each of the next n lines contains four integers ai, bi, ci, and di (0≤ai,bi,ci,di≤100) — the grades of the i-th student on English, German, Math, and History. The id of the i-th student is equal to i.

Output
Print the rank of Thomas Smith. Thomas’s id is 1.

由于Thomas的id是1,所以之后任何一个与他同分的都排在他的后面,所以只需要在读入的时候统计比Thomas总分高的人数就可以了,答案就是人数+1。


E - The Bits CodeForces - 1017B

Problem Description
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:

Given two binary numbers aaa and bbb of length nnn. How many different ways of swapping two digits in aaa (only in aaa, not bbb) so that bitwise OR of these two numbers will be changed? In other words, let ccc be the bitwise OR of aaa and bbb, you need to find the number of ways of swapping two bits in aaa so that bitwise OR will not be equal to ccc.

Note that binary numbers can contain leading zeros so that length of each number is exactly nnn.

Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, 010102010102010102 OR 100112=110112100112 = 110112100112=110112.

Well, to your surprise, you are not Rudolf, and you don’t need to help him… You are the security staff! Please find the number of ways of swapping two bits in a so that bitwise OR will be changed.

Input
The first line contains one integer nnn (2≤n≤105)(2≤n≤105)(2≤n≤105) — the number of bits in each number.

The second line contains a binary number aaa of length nnn.

The third line contains a binary number bbb of length nnn.

bitwise OR 的结果改变肯定只来自于串 aaa 中交换的两个位,因此只需要考察这两个位置 aaa、bbb 的情况。对于 a,ba,ba,b 同一位置的情况,可以分为以下四种情况:

编号 a b
A 0 0
B 0 1
C 1 0
D 1 1

手动模拟后发现,只有其中 AC,AD,BC,CA,CB,DAAC,AD,BC,CA,CB,DAAC,AD,BC,CA,CB,DA 的交换情况会使结果改变,又因为顺序无关,所以只需要 AC,AD,BCAC,AD,BCAC,AD,BC。因此只要计算AAA、BBB、CCC、DDD出现的次数,输出 A∗C+A∗D+B∗CA*C+A*D+B*CA∗C+A∗D+B∗C 即可。本题思考的关键在于如何避免两两枚举交换的位,根据有贡献的交换的特征,设法将其拆开来统计。


F - News Distribution CodeForces - 1167C

Problem Description
In some social network, there are nnn users communicating with eachother in mmm groups of friends. Let’s analyze the process of distributing some news between users.

Initially, some user xxx receives the news from some source. Then he or she sends the news to his or her friends (two users are friends if there is at least one group such that both of them belong to this group). Friends continue sending the news to their friends, and so on.
The process ends when there is no pair of friends such that one of
them knows the news, and another one doesn’t know.

For each user xxx you have to determine what is the number of users that will know the news if initially only user xxx starts distributing it.

Input
The first line contains two integers nnn and mmm (1≤n,m≤5⋅105)(1≤n,m≤5⋅10^5)(1≤n,m≤5⋅105) — the number of users and the number of groups of friends, respectively.

Then m lines follow, each describing a group of friends. The iii-th line begins with integer kik_iki​ (0≤ki≤n)(0≤k_i≤n)(0≤ki​≤n) — the number of users in the iii-th group. Then ki distinct integers follow, denoting the users belonging to the iii-th group.

It is guaranteed that ∑i=1mki≤5⋅105∑_{i=1}^{m}k_i≤5⋅10^5∑i=1m​ki​≤5⋅105.

Output
Print nnn integers. The iii-th integer should be equal to the number of users that will know the news if user iii starts distributing it.

从某一个用户开始的所有有交集的圈子最后都会传达到,所以我们干脆把所有有交集的圈子用并查集合并到一起。但题目给出的是每个圈子里的人,我们要把他转化成每个人所在的圈子。由于人数和圈数都很多,直接开二维不明智,所以决定用链式前向星,把所在的圈子串成链。但后来发现如果边串边用并查集合并,前面存进去的再也用不上,所以只需要first数组,不需要nxt数组,更加方便。最后每个人对其所在的大圈子有一个贡献,查询的时候取大圈子的人数即可。需要注意的是,有的人可能不属于任何一个圈子。还有并查集记得路径压缩和启发式合并。


G - Regular Bracket Sequence Again? Gym - 102766D

Problem Description
You have a collection of NNN opening brackets ‘(’ and NNN closing brackets ‘)’.

A bracket sequence is NNN periodic if it has a period of length NNN.

Example - “)()(” NNN=2. It is NNN periodic but “)(()” is not.

Your task is to find out how many distinct regular bracket sequence can be formed using these 2N2N2N brackets such that sequence is not NNN periodic.

As the answer can be rather large, print the remainder after dividing it by 1000000007(109+7)1000000007(10^9+7)1000000007(109+7).

Recall what the regular bracket sequence is:

“()” is regular bracket sequence. if s is regular bracket sequence then “(”+s+")" is regular bracket sequence. if s and t are regular bracket sequences then s+t is regular bracket sequence. For example, “()()”, “(())()”, “(())” and “()” are regular bracket sequences, but “)(”, “()(” and “)))” are not.

Input
The first line contains a single integer T(1≤T≤103)T(1≤T≤10^3)T(1≤T≤103) — the number of test cases in the input. Then TTT test cases follow.

Each query contains one integer N(1≤N≤103)N(1≤N≤10^3)N(1≤N≤103): the number of opening and closing brackets you have.

Output
For each test from the input print the number of distinct regular bracket sequence we can form using NNN opening bracket and NNN closing bracket and sequence is not NNN periodic modulo 1000000007(109+7)1000000007(10^9+7)1000000007(109+7).

Print the answers to the tests in the order in which the tests are given in the input.

Example
Input:
4
1
2
3
4
Output:
1
1
5
12
Note
In the first query — The regular bracket sequence which can be formed by 111 opening bracket and 111 closing bracket is “()”.

In the second query — The regular bracket sequence which can be formed by 222 opening bracket and 222 closing bracket are “(())” and “()()”. We discard second one because “()()” is 222 periodic.

In the third query — The regular bracket sequence which can be formed by 333 opening bracket and 333 closing bracket are “((()))” , “(())()” , “()(())” , “()()()” and “(()())”. No one is 333 periodic.

貌似与卡特兰数有关,由于没做出来所以不写。


H - Singhal and GCD Gym - 102767C

Problem Description
For the multiset of positive integers a=(a1,a2,…,ak)a=(a_1,a_2,…,a_k)a=(a1​,a2​,…,ak​) define the Greatest Common Divisor (GCDGCDGCD) of a as:

gcd(a)gcd(a)gcd(a) is the maximum positive integer xxx, such that all integers in multiset aaa are divisible on xxx.

For example, gcd(8,12,16)=4gcd(8,12,16)=4gcd(8,12,16)=4.

Singhal has a sequence consisting of nnn integers. He wants to find the subarray of (length>111) whose gcdgcdgcd is maximum possible. If there exist multiple subarrays then choose the largest in length. Help him to find the maximum gcdgcdgcd he can obtain and length of this subarray.

A subarray is the sequence of consecutive elements of the array.

Input
The first line contains a single integer t(1≤t≤105)t(1≤t≤10^5)t(1≤t≤105) — the number of test cases in the input. Then ttt test cases follow.

Each query contains two lines. The first line contains one integer n(2≤n≤105)n(2≤n≤10^5)n(2≤n≤105): the number of integers in the sequence, and the second line contains nnn integers a1,…,an(1≤ai≤109)a_1,…,a_n(1≤a_i≤10^9)a1​,…,an​(1≤ai​≤109).

It is guaranteed that the total sum of n is at most 10510^5105.

Output
Print ttt answers to the test cases. Each answer must be consisting of two integers separate by a space — the maximum gcdgcdgcd he can obtain and the length of the maximum subarray.

没做出来。


I - Super Jumping! Jumping! Jumping! HDU - 1087

Problem Description
Nowadays, a kind of chess game called “Super Jumping! Jumping!
Jumping!” is very popular in HDU. Maybe you are a good boy, and know
little about this game, so I introduce it to you now.

The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path. Your task is to output the maximum value according to the given chessmen list.
Input
Input contains multiple test cases. Each test case is described in a line as follow: NNN value1value_1value1​ value2value_2value2​ ……… valueNvalue_NvalueN​ It is guarantied that NNN is not more than 100010001000 and all valueivalue_ivaluei​ are in the range of 323232-int. A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each case, print the maximum according to rules, and one line one case.

看了半天发现是个最长上升子序列裸题,O(n2)O(n^2)O(n2) 即可解。


J - Max Sum HDU - 1231

给定K个整数的序列 N1,N2,...,NK{ N_1, N_2, ..., N_K }N1​,N2​,...,NK​,其任意连续子序列可表示为 Ni,Ni+1,...,Nj{ N_i, N_{i+1}, ..., N_j }Ni​,Ni+1​,...,Nj​,其中 1<=i<=j<=K1 <= i <= j <= K1<=i<=j<=K。最大连续子序列是所有连续子序列中元素和最大的一个, 例如给定序列 −2,11,−4,13,−5,−2{ -2, 11, -4, 13, -5, -2}−2,11,−4,13,−5,−2,其最大连续子序列为 11,−4,13{ 11, -4, 13 }11,−4,13,最大和 为 202020。
在今年的数据结构考卷中,要求编写程序得到最大和,现在增加一个要求,即还需要输出该 子序列的第一个和最后一个元素。
Input
测试输入包含若干测试用例,每个测试用例占 222 行,第 111 行给出正整数K(<10000)K( < 10000)K(<10000),第 222 行给出 KKK 个整数,中间用空格分隔。当 KKK 为 000 时,输入结束,该用例不被处理。
Output
对每个测试用例,在1行里输出最大和、最大连续子序列的第一个和最后一个元素,中间用空格分隔。如果最大连续子序列不唯一,则输出序号i和j最小的那个(如输入样例的第 222、333 组)。若所有 KKK 个元素都是负数,则定义其最大和为 000,输出整个序列的首尾元素。
Sample Input
6
-2 11 -4 13 -5 -2
10
-10 1 2 3 4 -5 -23 3 7 -21
6
5 -8 3 2 5 0
1
10
3
-1 -5 -2
3
-1 0 -2
0
Sample Output
20 11 13
10 1 4
10 3 5
10 10 10
0 -1 -2
0 0 0

边界条件加上 000 的存在有点烦人,没调出来。大致上是先做前缀和,然后取 max{sj−si∣0<=i<j<=n}max\{s_j - s_i|0<=i<j<=n\}max{sj​−si​∣0<=i<j<=n},方法是扫一遍最大值,然后在最大值左边扫最小值,更新一次差值,然后往右边重复这个步骤,直到没法再往右或者差值不再变大。

while (curj < k) {for(int j = curi + 1; j <= k; ++j)if (sum[j] > sum[curj])curj = j;for(int i = curi + 1; i <= curj - 1; ++i)if (sum[i] < sum[curi])curi = i;if (sum[curj] - sum[curi] > sum[maxj] - sum[mini])mini = curi, maxj = curj;else break;
}

上面这段代码只是大概思路,具体的边界条件还是有错。


PS:题面处理有点烦人,下次干脆传图片好了。

2021-01-25广州大学ACM寒假训练赛解题心得相关推荐

  1. 2021暨南大学轩辕杯ACM程序设计新生赛题解

    title : 2021暨南大学轩辕杯ACM程序设计新生赛 date : 2021-12-12 tags : ACM,练习记录 author : Linno 题目链接:https://ac.nowco ...

  2. 20200203DLUT寒假训练赛div2-简单搜索专场

    20200203DLUT寒假训练赛div2-简单搜索专场 :比赛地址 A - Find The Multiple 简单的dfs水题,主要是取10x和10x+1两种情况,并且注意函数存储数字必须得用un ...

  3. ACM题解——训练赛2_D - The Beatles

    ACM题解--训练赛2_D - The Beatles 题目描述 Examples Input 2 3 1 1 Output 1 6 Input 3 2 0 0 Output 1 3 Input 1 ...

  4. QLU寒假训练赛题解合集

    为了节省版面: 1.所有寒假训练赛题解都集中在这一篇里 2.所有题解代码都可以直接点击题目链接查看 0115 A题:签到,输出n+1 B题:签到,从左端点向右找一段和小于0的区间,再从右往左找 C题: ...

  5. QLU ACM 2018新生赛解题报告

    QLU ACM 2018 新生赛解题报告 A [1303]约数个数 题目描述 输入 输出 解析 B [1301]Alice and Bob 题目描述 输入 解析 C [1289] 黑白黑 题目描述 输 ...

  6. 湖南师范大学2021年4月1日愚人赛解题报告与标程

    湖南师范大学2021年4月1日愚人赛解题报告与标程 A 题目描述 标程 B 题目描述 标程 C 题目描述 标程 D 题目描述 解法 标程 E 题目描述 解法 F 题目描述 解法 标程 G 题目描述 标 ...

  7. ACM算法训练赛——STL(完结)

    STL训练赛 A - JiaoZhu and SC #include <bits/stdc++.h> #define int long long #define rep(i, a, b) ...

  8. ACM寒假训练第二周总结

    时间:2022.1.17--2022.1.23 一.刷题记录 1. P1271 [深基9.例1]选举学生会 using namespace std; int a[1005]={0}; int main ...

  9. ACM寒假训练第一周总结

    时间:2022.1.11-2022.1.16 一.刷题记录 1. P1042 [NOIP2003 普及组] 乒乓球 #include "iostream" using namesp ...

最新文章

  1. 【廖雪峰Python学习笔记】面向对象编程OOP
  2. My sql 日常维护命令的总结
  3. 周志华:最新实验表明gcForest已经是最好的非深度神经网络方法
  4. Luogu P1654 OSU! | 期望
  5. 在浏览器上浏览vue项目,后退按钮是可以正常返回上一页的,但打包成app后,点击手机上的物理返回按钮就直接退出app回到桌面...
  6. Android从零开始(七)
  7. DNS区域传送、子域授权
  8. node.js路由控制
  9. 字符编码、常见字符集解析(ASCII、Unicode、UTF-8、GB2312等)
  10. php soap详解,关于PHP+SOAP详解
  11. JAVA中日期格式SimpleDateFormat
  12. 一文详解Kafka API
  13. 操作系统两大创始人反目,这个排名第九的 Linux 发行版 OS 何去何从?
  14. 最受Java程序员欢迎的大数据工具排名
  15. 用html设计logo,网页设计中的logo设计方法
  16. 考高级用计算机和外语证,济南:“老外”也能评职称了!2018年度申报开始,这些专业评高级不用考外语计算机...
  17. 什么叫无差别伤害_无差别伤害背后的差别
  18. 笔记本电脑更改计算机驱动怎么进不去,笔记本电脑进入不了BIOS的原因与解决办法...
  19. LOJ3124 CTS2019 氪金手游 概率、容斥、树形DP
  20. 食神软件测试初学者,橙光游戏食神养成计划升阶攻略

热门文章

  1. java.lang.RuntimeException: Unable to start receiver com.yeliner.example.fragmentnews.receiver.Offl
  2. [ 虚拟专用网 ] IPsce 虚拟局域网(安全的IP协议的虚拟专用网)详解(一)
  3. Revit二次开发之按照标高过滤元素
  4. Microsoft CMT 系统
  5. Linux命令之yum命令
  6. 浙江省2022年职称评审申报流程
  7. 计算机自检后反复重启 主引导,电脑开机停留在商标界面-电脑一开机就停留在主板标志界面,进不了bios设置,重启也一样,怎么办?...
  8. openGL之几何变换(绘制球体)---openGL学习笔记(六)
  9. 布里斯托大学计算机科学专业排名,2019上海软科世界一流学科排名计算机科学与工程专业排名布里斯托大学排名第101-150...
  10. 高端化和智能化是一体两面 腾势D9开启中国MPV新豪华时代