A.ABB

原题

Fernando was hired by the University of Waterloo to finish a development project the university started some time ago. Outside the campus, the university wanted to build its representative bungalow street for important foreign visitors and collaborators.

Currently, the street is built only partially, it begins at the lake shore and continues into the forests, where it currently ends. Fernando’s task is to complete the street at its forest end by building more bungalows there. All existing bungalows stand on one side of the street and the new ones should be built on the same side. The bungalows are of various types and painted invarious colors.

The whole disposition of the street looks a bit chaotic to Fernando. He is afraid that it will look even more chaotic when he adds new bungalows of his own design. To counter balance the chaos of all bungalow shapes, he wants to add some order to the arrangement by choosing suitable colors for the new bungalows. When the project is finished, the whole sequence of bungalow colors will be symmetric, that is, the sequence of colors is the same when observed from either end of the street.

Among other questions, Fernando wonders what is the minimum number of new bungalows he needs to build and paint appropriately to complete the project while respecting his self-imposed bungalow color constraint.

Input Specification

The first line contains one integer N (1 \leq N \leq 4·10^{5})N(1≤N≤4⋅10
5
), the number of existing bungalows in the street. The next line describes the sequence of colors of the existing bungalows, from the beginning of the street at the lake. The line contains one string composed of N lowercase letters(“a” through “z”), where different letters represent different colors.

Output Specification

Output the minimum number of bungalows which must be added to the forest end of the street and painted appropriately to satisfy Fernando’s color symmetry demand.

input:
3
abboutput:
1
input:
12
recakjenecepoutput:
11

题目大意:

给出一个字符串,求在其后最少添加多少个字符可以使整个字符串为回文串。

题解:

考试没自己想出来,经过队友提醒才想明白。
贪心,为了形成最短的回文串,回文的中心位置一定出现在靠近右端的位置,因此只需枚举从左往右位置i,检验s(i,n)是否能构成回文串,当可以构成时,i 左边的字符数就是需要添加的字符数。
同时本题的数据范围成谜,按理说这个o(n^2)的算法大概率会卡,但可能是我时间复杂度计算有误,或者数据很水 ,居然以非常短的时间过了,妙。

代码实现:

#include<iostream>
#include<cmath>
using namespace std;
int n,cnt;
char s[400005];
int main(){scanf("%d%s",&n,s+1);for(int i=1;i<=n;i++){cnt=0;for(int k=0;k<=(n-i+2)/2;k++){if(s[i+k]==s[n-k]&&i+k<n-k) cnt+=2;else if(i+k==n-k) cnt++;else break;}if(cnt==n-i+1){printf("%d\n",i-1);return 0;}}printf("%d\n",n-1);return 0;
}

C. Bob in Wonderland

原题

A chain, as everybody knows, is made of connected links. Typically, all links are of the same shape and size. Bob is a blacksmith apprentice, and he is making his own first iridium chain.He follows the traditional formula of chain-making. It says:

• If there is no chain yet, make a link and it will be a piece of your chain.

• If there is a piece of chain, make another link and connect it to one other link in the piece of chain you already have.

Bob made the first link. Then, each time he made another link, he connected it to some other link in his piece of chain, exactly as the formula told him to do.

When he finished, he realized that the object he created did not resemble a usual chain at all.In an effort to straighten the chain, he repeatedly took two links which seemed to be at the ends of the chain and tried to pull them apart as far as he could. But there were some more pieces of the “chain” dangling down from the straightened piece at various places.

It was obvious to Bob that his work is not finished yet and he decided to call the object he produced the unfinished chain. After some more pondering, Bob came to a conclusion that he has to break some links and reconnect them to the rest of the unfinished chain more cautiously to obtain a straight chain he aims to produce. In a straight chain, each link is connected to at most two other links and a straight chain cannot be separated into more pieces without breaking a link.

Being now more careful, Bob is going to progress in simple steps. In one step he will choose a link, say A, connected to another link, say B, in the unfinished chain. He will then break A,disconnect it from B and reconnect A to some other link, say C, in the unfinished chain. If there are more links other than B originally connected to A, Bob will keep them connected toA during the whole step.

What is the minimum number of steps Bob has to perform to get a straight chain?

Input Specification

The first line contains one integer N (1 ≤ N ≤ 3 · 10^5 ), the number of links in the unfinished chain. The links are labeled 1, 2, . . . , N. Each of the next N − 1 lines has two integers denoting the labels of two connected links in the unfinished chain. The connections are listed in arbitrary order. The unfinished chain is guaranteed to form only one piece.

Output Specification

Output the minimum number of steps which will turn Bob’s unfinished chain into a straight chain.

样例输入1
5
4 3
1 2
4 5
3 2
样例输出1
0
样例输入2
6
1 3
3 2
3 4
4 5
4 6
样例输出2
2
样例输入3
7
1 2
2 3
3 4
4 5
3 6
6 7
样例输出3
1

题目大意:

把一个树变成一条直链。

题解

对于一条直链,记录每一个结点的度,显然是这样的:

  i  1 2 3 4 5 6 7 8 9
c[i] 1 2 2 2 2 2 2 2 1

即除两个端点的度为1之外,其余的都为2
而对于一棵树,把其变成一个这样的直链,就是不断把度多于2的点链接的边挪到度为1的点上,直至树的节点度表和链的特征相符合的过程。因此,不需要关注将谁移动到谁上的过程状态问题,只需要暴力减2就可以了!

但是考试过程中以为是必须先求出树的直径并在最长路径上进行操作,可以说是自以为很高深的操作了。

代码实现

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int x,y,cnt[300005],tot,n;
int main(){scanf("%d",&n);for(int i=1;i<n;i++){scanf("%d%d",&x,&y);cnt[x]++,cnt[y]++;}for(int i=1;i<=n;i++)if(cnt[i]>2) tot+=(cnt[i]-2);printf("%d\n",tot);
}

E. Zeldain Garden

原题

Boris is the chief executive officer of Rock Anywhere Transport (RAT) company which specializes in supporting music industry. In particular, they provide discount transport for manypopular rock bands. This time Boris has to move a large collection of quality Mexican concertloudspeakers from the port on the North Sea to the far inland capital. As the collection isexpected to be big, Boris has to organize a number of lorries to assure smooth transport. Themultitude of lorries carrying the cargo through the country is called a convoy

Boris wants to transport the whole collection in one go by a single convoy and without leavingeven a single loudspeaker behind. Strict E.U. regulations demand that in the case of largetransport of audio technology, all lorries in the convoy must carry exactly the same number ofpieces of the equipment.

To meet all the regulations, Boris would like to do some planning in advance, despite the fact thathe does not yet know the exact number of loudspeakers, which has a very significant influenceon the choices of the number and the size of the lorries in the convoy. To examine variousscenarios, for each possible collection size, Boris calculates the so-called “variability”, which isthe number of different convoys that may be created for that collection size without violatingthe regulations. Two convoys are different if they consist of a different number of lorries.

For instance, the variability of the collection of 6 loudspeakers is 4, because they may be evenlydivided into 1, 2, 3, or 6 lorries.

Input Specification

The input contains one text line with two integers N,M(1≤N≤M≤10^12 ), the minimum and the maximum number of loudspeakers in the collection.

Output Specification

Print a single integer, the sum of variabilities of all possible collection sizes betweenNN and MM,inclusive.

样例输入1
2 5
样例输出1
9样例输入2
12 12
样例输出2
6样例输入3
555 666
样例输出3
852

题目大意:

废话真的很多,但是总结起来就一句话,
求n到m中的各个数字的因子数之和

题解:

本题的范围决定,埃式筛mle(导致我想的分解定理做法架空),朴素算法tle(导致不能暴力x ),只能寻找o(n)或者o(logn)的做法。通过找规律,可以发现一个神奇的现象(以8为例):

数字   因子数目        1-n的因子数和
1       1           1
2       2           3
3       2           5
4       3           8
5       2           10
6       4           14
7       2           16
8       4           20

可推导发现,∑int(n/i) [1<=i<=n] 即为1-n的因子数和
然后就可以做了 但是这个做法依然会在1e12的数据面前瑟瑟发抖。我们又发现,∑n/i即是函数y=n/x的一个离散值和,这个函数关于y=x对称,对称为点(√n,√n),因此由函数图像面积对称可以知道,只需求出前√n数据范围内的面积ans,ans*2-√n × √n即为答案

代码实现

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,m;
ll get(ll n){long long ans=0, t=sqrt((double)(n));for(int i=1; i<=t; i++)ans += n/i;ans = ans*2-t*t;return ans;
}
int main(){scanf("%lld%lld",&n,&m);cout<<get(m)-get(n-1)<<endl;return 0;
}

队友提出了另一个解法,可以解决埃式筛在此时mle的问题。通过从小到大枚举素数对n进行唯一分解定理的分解过程,可以比较显著的降低时间消耗,但是本题数据过大,依然t了,但是这种融筛法于内的做法还蛮厉害。
附上队友代码图

ICPC Central Europe Regional Contest 2019【山东大学】 部分题解相关推荐

  1. ICPC Central Europe Regional Contest 2019 K. K==S(AC自动机+矩阵快速幂)

    Progressive hard octave rock tunes (so-called "phorts") are written using a specifific mus ...

  2. Central Europe Regional Contest 2019 J. Saba1000kg (并查集+根号讨论)

    链接:https://ac.nowcoder.com/acm/contest/7817/I 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言524 ...

  3. 2021 ICPC Southeastern Europe Regional Contest Werewolves(树上背包)

    2021 ICPC Southeastern Europe Regional Contest Werewolves(树上背包) 链接 题意:给出一个n个节点的树(n≤3000n\le3000n≤300 ...

  4. ICPC Central Russia Regional Contest (CRRC 19)

    ICPC Central Russia Regional Contest (CRRC 19) 文章目录 ICPC Central Russia Regional Contest (CRRC 19) A ...

  5. 2021 ICPC Southeastern Europe Regional Contest(更新至六题)

    2021 ICPC Southeastern Europe Regional Contest A题签到 A. King of String Comparison 题意:给两个字符串,找出有多少对(l, ...

  6. 2016-2017 Central Europe Regional Contest Hangar Hurdles 克鲁斯卡尔重构树 + 建图

    传送门 文章目录 题意: 思路: 题意: 有一个n∗nn*nn∗n的网格图,有若干位置有障碍,有qqq个询问,每次询问给出两个点坐标x1,y1,x2,y2x1,y1,x2,y2x1,y1,x2,y2, ...

  7. Central Europe Regional Contest 2012 Problem c: Chemist’s vows

    字符串处理的题目: 学习了一下string类的一些用法: 这个代码花的时间很长,其实可以更加优化: 代码: 1 #include<iostream> 2 #include<strin ...

  8. 2021 ICPC Southeastern Europe Regional Contest ABFGJKLN

    |–>传送门<–| A. King of String Comparison 双指针 给定字符串AAA和BBB,计算满足Asub[l,r]A_{sub[l, r]}Asub[l,r]​字典 ...

  9. 2021 ICPC Southeastern Europe Regional Contest 树上dfs+思维

    |–>传送门<–| 题目大意 给定一颗nnn个节点的树,可以从任意一个点开始dfsdfsdfs,求最小字典序的后续遍历. 题解 首先,对于字典序最小的要求,我们一定是从叶结点中的最小值开始 ...

  10. 2015-2016 ACM-ICPC, Central Europe Regional Contest (CERC 15) F.Frightful Formula(大数NTT)

    题目链接:http://codeforces.com/gym/101480/attachments mark一下O(1)快速乘,啥原理啊?还有这个长度计算,貌似也得好好学学啊? 代码: #includ ...

最新文章

  1. 独家 | 虚假疫苗网站如何获取你的个人信息
  2. 浪潮的加班标语炸了,这是顶风作案?网传:1月加班87小时还要扣工资?
  3. python 查看字符编码,[Python]判断系统编码和字符编码chardet
  4. xlrd对excel单列处理
  5. centos -bash: vim: command not found
  6. chattr和lsattr命令的使用(对于root用户也无法修改删除的操作问题)
  7. 折腾 | pytoch、cuda版本问题
  8. 算术编码(Arithmetic Coding)源代码
  9. 移动web开发之rem布局(rem基础、媒体查询、 less 基础、rem适配方案)
  10. mongoDB 使用手册
  11. 关于SPARK_WORKER_MEMORY和SPARK_MEM
  12. python堆排序的库_Python:堆排序
  13. Leetcode392.判断子序列
  14. matlab画一个点电荷电场线,matlab画点电荷电场线
  15. java jsp实验设计心得_jsp课程设计心得_课程设计总结心得
  16. Firefox版哔哩哔哩助手,修改自chrome1.2.1版
  17. GPU深度报告,三大巨头,十四个国内玩家一文看懂【物联网智商精选】
  18. php发布iis0x80070005,iis 0x80070005 解决方法
  19. 自费送几本豆瓣9.0高分Python书籍,助你涨薪至30K
  20. 软考初级程序员上午单选题(13)

热门文章

  1. 2021-03-11 Android 异常情况下长按power按键10s关机或者重启
  2. JAVA程序员必备网站
  3. 我国的居民身份证号码,由由十七位数字本体码和一位数字校验码组成。请定义方法判断用户输入的身份证号码是否合法,并在主方法中调用方法测试结果。规则为:号码为18位,不能以数字0开头,前17位只可以是数字,
  4. Java 居民身份证号校验工具类
  5. 服装行业ERP体系的主要好处
  6. 智联招聘 'python数据分析'职位分析第一篇
  7. 通达OA流程中心触发器使用实例
  8. 第一次去曼谷旅游怎么玩?这份省钱攻略请收好
  9. 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han
  10. 后台弹出界面权限踩坑