Codeforces Round

编程学习:Codeforces Round #A1A2BCE Round #A1A2BCE是Codeforces竞赛中的一个回合,每个回合都有一系列的编程问题需要解决。本文中,我们以一个求解两数之和的问题为例,给出了一个使用哈希表的解决方案。当然,每个回合的问题都有不同的特点和难度级别,所以参赛者需要根据题目的要求和限制选择合适的算法和数据结构,以获得最佳的解决方案。然后,遍历数组,对于每个元素,计算目标值与当前元素的差值,并检查该差值是否已经在字典中。给定一个整数数组,我们需要找到数组中的两个元素,使它们的和等于给定的目标值。运行代码后,我们得到了预期的输出结果。 阅读详情

http://codeforces.com/contest/1029

A. Many Equal Substrings

You are given a string t consisting of n lowercase Latin letters and an integer number kk.
Let’s define a substring of some string s with indices from l to r as s[l…r].
Your task is to construct such string ss of minimum possible length that there are exactly k positions i such that s[i…i+n−1]=t. In other words, your task is to construct such string s of minimum possible length that there are exactly k substrings of s equal to t.
It is guaranteed that the answer is always unique.

Input

The first line of the input contains two integers n and k (1 ≤ n,k ≤50) — the length of the string t and the number of substrings.
The second line of the input contains the string t consisting of exactly n lowercase Latin letters.

Output
`
Print such string s of minimum possible length that there are exactly k substrings of s equal to t.
It is guaranteed that the answer is always unique

问题分析:

问题的大意是输出最短的字符串,要求满足其中有k个子字符串和所给字符串相等。本题主要是找到所给字符串最长的前缀字符串和后缀字符串,要求两者相等。然后输出(k-1)次前缀字符串后面的子字符串

AC代码:


/*
author:Manson
date:9.4.2018
theme:
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1005;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    string s,s1;
    cin>>s;
    for(int i = n-1;i >= 1;i--){
        //枚举长度 
        if(s.substr(0,i) == s.substr(n-i)){
            s1 = s.substr(i);
            cout<<s;
            k--;
            while(k--){
                cout<<s1;
            }
            return 0;
        }
    }
    while(k--){
        cout<<s;    
    }
    return 0;
}

B. Creating the Contest

You are given a problemset consisting of n problems. The difficulty of the i-th problem is ai. It is guaranteed that all difficulties are distinct and are given in the increasing order.
You have to assemble the contest which consists of some problems of the given problemset. In other words, the contest you have to assemble should be a subset of problems (not necessary consecutive) of the given problemset. There is only one condition that should be satisfied: for each problem but the hardest one (the problem with the maximum difficulty) there should be a problem with the difficulty greater than the difficulty of this problem but not greater than twice the difficulty of this problem. In other words, let ai1,ai2,…,aip be the difficulties of the selected problems in increasing order. Then for each j from 1 to p−1 ;aij+1≤aij*2 should hold. It means that the contest consisting of only one problem is always valid.
Among all contests satisfying the condition above you have to assemble one with the maximum number of problems. Your task is to find this number of problems.

Input

The first line of the input contains one integer nn (1≤n≤2⋅105) — the number of problems in the problemset.
The second line of the input contains n integers a1,a2,…,an (1≤ai≤109) — difficulties of the problems. It is guaranteed that difficulties of the problems are distinct and are given in the increasing order.

Output

Print a single integer — maximum number of problems in the contest satisfying the condition in the problem statement.

问题分析:

问题大意是有n个数组成的序列,要求找出最长的子序列满足ai+1 <= 2ai。本题就是一道简单的模拟题,一遍循环即可。

AC代码:

/*
author:Manson
date:9.4.2018
theme:
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 2e5+5;
int a[N];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int cnt = 0,ans = 0;
    for(int i = 0;i < n;i++){
        cin>>a[i];
        if(i == 0 || a[i] > 2*a[i-1]){
            cnt = 1;
        }else{
            cnt++;
        }
        ans = max(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}

C. Maximal Intersection

You are given n segments on a number line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
The intersection of a sequence of segments is such a maximal set of points (not necesserily having integer coordinates) that each point lies within every segment from the sequence. If the resulting set isn’t empty, then it always forms some continuous segment. The length of the intersection is the length of the resulting segment or 0 in case the intersection is an empty set.
For example, the intersection of segments [1;5] and [3;10] is [3;5] (length 2), the intersection of segments [1;5] and [5;7] is [5;5](length 0) and the intersection of segments [1;5] and [6;6] is an empty set (length 0).
Your task is to remove exactly one segment from the given sequence in such a way that the intersection of the remaining (n−1)segments has the maximal possible length.

Input

The first line contains a single integer n (2≤n≤3*105) — the number of segments in the sequence.
Each of the next n lines contains two integers li and ri (0≤li≤ri≤109) — the description of the i-th segment.

Output

Print a single integer — the maximal possible length of the intersection of (n−1) remaining segments after you remove exactly one segment from the sequence.

问题分析:

问题大意是给出n个区间,求移除一个区间后,其他n-1个区间相交后的区间的最大长度。本题就是一道模拟题。首先从0-n-1遍历一遍前缀交,然后从n-1到0遍历一遍后缀交,然后比较前缀交和后缀交,表示取出其中一个i区间所得到的区间。得到最大的区间长度。

AC代码:

/*
author:Manson
date:9.4.2018
theme:
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 3e5+5;
const int INF = 1e9+7;
//a[i][0]表示第i个区间左端点,a[i][1]表示第i个区间右端点 
int a[N][3],b[N][3],c[N][3];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i = 0;i < n;i++){
        cin>>a[i][0]>>a[i][1];
    }
    b[0][0] = c[n][0] = -INF;
    b[0][1] = c[n][1] = INF;
    //前缀交,从1到n 
    for(int i = 0;i < n;i++){
        b[i+1][0] = max(b[i][0],a[i][0]);
        b[i+1][1] = min(b[i][1],a[i][1]);
    }
    //后缀交,从n-1到0
    for(int i = n-1;i >= 0;i--){
        c[i][0] = max(c[i+1][0],a[i][0]);
        c[i][1] = min(c[i+1][1],a[i][1]);
    }
    int ans  = 0;
    for(int i = 0;i < n;i++){
        int x1 = max(b[i][0],c[i+1][0]);
        int y1 = min(b[i][1],c[i+1][1]);
        ans = max(ans,y1-x1);
    }
    cout<<ans<<endl;
    return 0;
}

D. Concatenated Multiples

You are given an array a, consisting of n positive integers.
Let’s call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i,j) (i≠j) in array a such that the concatenation of ai and aj is divisible by k.

Input

The first line contains two integers n and k (1≤n≤2*105, 2≤k≤109).
The second line contains n integers a1,a2,…,an (1≤ai≤109).

Output

Print a single integer — the number of ordered pairs of positions (i,j) (i≠j) in array aa such that the concatenation of ai and aj is divisible by k.

问题分析:

问题大意给出n个数,把其中两个数拼接,要求拼接后的数能被k整除,求有多少种拼接方式。本题的主要思路:收先用数学知识化简公式。x*10^(1gy+1)%k+y%k = x*10%k*10%k*… + y%k;
然后用b[N]数组保存各个数的位数,mp[N][N]存储余数个数。mp[i][x]即表示位数为i,余数为x的个数。
最后一层循环1-n个数,然后循环一下y的位数,采用余数互补的个数加入到最终结果中去。

AC代码:

/*
author:Manson
date:9.5.2018
theme:
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 2e5+5;
//mp[i][k]表示i位数的余数为k的个数 
map<int,int >mp[15];
//b存储第i个数的位数 
int a[N],b[N];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i = 1;i <= n;i++){
        cin>>a[i];
        int x = a[i];
        while(x){
            x /= 10;
            b[i]++;
        }
        mp[b[i]][a[i]%k]++;
    }
    ll ans = 0;
    for(int i = 1;i <= n;i++){
        ll x = a[i];
        //除去本身的个数 
        mp[b[i]][x%k]--;
        //枚举后面加了j个0,余数互补 
        for(int j = 1;j <= 10;j++){
            x = x*10%k;
            if(mp[j].count(k-x)){
                ans += mp[j][k-x];
            }
            if(x == 0 && mp[j].count(0)){
                ans += mp[j][0];
            }

        }
        mp[b[i]][a[i]%k]++;
    }
    cout<<ans<<endl;
    return 0;
}

E. Tree with Small Distances

You are given an undirected tree consisting of n vertices. An undirected tree is a connected undirected graph with n-1 edges.
Your task is to add the minimum number of edges in such a way that the length of the shortest path from the vertex 1 to any other vertex is at most 2. Note that you are not allowed to add loops and multiple edges.

Input

The first line contains one integer n (2≤n≤2*105) — the number of vertices in the tree.
The following n-1 lines contain edges: edge i is given as a pair of vertices ui,vi (1≤ui,vi≤n). It is guaranteed that the given edges form a tree. It is guaranteed that there are no loops and multiple edges in the given edges.

Output

Print a single integer — the minimum number of edges you have to add in order to make the shortest distance from the vertex 1 to any other vertex at most 2. Note that you are not allowed to add loops and multiple edges.

问题分析:

问题的大意是给出一棵树,要求1到任意一个节点的距离不能大于2;问至少要添加多少个连线才能满足这个条件。本题就是一个dfs问题,我用的是前式链向星保存的树的结构(看了一下数据量,也可以用vector保存)。在dfs中判断到1的距离是否>2;当大于2是就连线,并且连线过后子节点的父节点要更新为2。

AC代码:

/*
author:Manson
date:9.4.2018
theme:树上dp 
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 2e5+5;
int n,num,res;
//pos距离子节点是否连接到 1,dis记录子节点到1的距离 
int head[N],pos[N],dis[N];
struct node{
    int next;
    int v;
}edge[N*2];

void addedge(int u,int v){
    edge[num].v = v;
    edge[num].next = head[u];
    head[u] = num++;
}

void dfs(int x,int fa){
    int ans = 0;
    for(int i = head[x];i!=-1;i = edge[i].next){
        int v = edge[i].v;
        if(v == fa){
            continue;
        }
        dis[v] = dis[x]+1;
        dfs(v,x);
        ans = max(ans,dis[v]);
        //如果dis>2的子节点连接到 1,那么父节点更新为2 
        if(pos[v] && dis[x] > 2){
            dis[x] = 2;
        }
    }
    if(ans > 2){
        pos[x] = 1;
        dis[x] = 1;
        res++;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    num = 0;
    res = 0;
    memset(head,-1,sizeof(head));
    for(int i = 1;i < n;i++){
        int u,v;
        cin>>u>>v;
        addedge(u,v);
        addedge(v,u);
    }
    dfs(1,-1);
    cout<<res<<endl;
    return 0;
}

F. Multicolored Markers

There is an infinite board of square tiles. Initially all tiles are white.
Vova has a red marker and a blue marker. Red marker can color a tiles. Blue marker can color b tiles. If some tile isn’t white then you can’t use marker of any color on it. Each marker must be drained completely, so at the end there should be exactly a red tiles and exactly b blue tiles across the board.
Vova wants to color such a set of tiles that:
(1)they would form a rectangle, consisting of exactly a+b colored tiles;
(2)all tiles of at least one color would also form a rectangle.
Here are some examples of correct colorings:

https://i-blog.csdnimg.cn/blog_migrate/414044aeef36503c198a18adfd9171d1.png

Here are some examples of incorrect colorings:

https://i-blog.csdnimg.cn/blog_migrate/cac5ed929a2f61603417e662746e6578.png

Among all correct colorings Vova wants to choose the one with the minimal perimeter. What is the minimal perimeter Vova can obtain?
It is guaranteed that there exists at least one correct coloring.

Input

A single line contains two integers a and b (1≤a,b≤1014) — the number of tiles red marker should color and the number of tiles blue marker should color, respectively.

Input

Print a single integer — the minimal perimeter of a colored rectangle Vova can obtain by coloring exactly a tiles red and exactly b tiles blue.
It is guaranteed that there exists at least one correct coloring.

问题分析:

本题的大意是给出a,b,a+b = c;就是求面积为c矩形最大的周长。但是要满足a or b可以单个构成一个矩形。这题我是直接枚举的一边长。没想到就过了。。。

AC代码:

/*
author:Manson
date:9.4.2018
theme:
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1005;
const ll INF = 4e14+5;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b;
    cin>>a>>b;
    ll c  = a+b;
    ll ans = INF;
    ll l = a;
    for(int i = 1;i <= c/i;i++){
        if(a%i == 0){
            l = min(l,a/i);
        }
        if(b%i == 0){
            l = min(l,b/i);
        }
        if(c % i == 0 && c/i>= l){
            ans = min(ans,((c/i+i)*2));
        }
    }
    cout<<ans<<endl;
    return 0;
}
TVS 管击穿电压与钳位电压的工程解析 TVS二极管的核心参数击穿电压(VBR)和钳位电压(VC)常被混淆,但二者具有本质区别。VBR是 阅读详情

相关推荐

深入解析Vivado FIFO的Standard与FWFT模式:性能对比与应用场景

本文深入解析了Vivado FIFO的Standard与FWFT两种工作模式的核心差异。通过对比数据就绪时机、读延迟、控制逻辑和有效深度等关键特性,并结合图像处理、数据包转发等典型应用场景,为FPGA设计者提供了清晰的选择依据和实战配置指南,帮助优化数据流性能与设计效率。

weixin_29219189的博客 260

Codeforces Round 988 (Div. 3)

打了刚刚的牛客又来打codeforces,感觉手感好多了,继续努力!

Beau_Will的博客 1613

北航机器学习期末考试试题2020年春

北航机器学习期末考试试题2020春 看csdn上试题收费,积分还挺高,本着共享的理念,把2020春季ML考试的试题公开,若侵权,立删 前8道题10分,第9题20分 决策树采用ID3算法 对宇宙星球是否适合生存分类 SVM的原理;软间隔、硬间隔;以及对非线性样本点分类 集成学习的原理,以及及串行boosting以及bagging的简单概括 K-means与混合高斯模型的异同以及EM算法的原理,如何计算 马尔可夫随机场最大团;马尔可夫随机场的联合概率分布(势函数表示),贝叶斯网络联合概率分布 PCA主成分基于

qq_43343919的博客 5433

Codeforces Round (思维题)

1.题目引入: You are given two integersllandrr,l≤rl≤r. Find the largest possible value ofamodbamodbover all pairs(a,b)(a,b)of integers for whichr≥a≥b≥lr≥a≥b≥l. As a reminder,amodbamodbis a remainder we get when dividingaabybb. For example,26mo...

weixin_52914088的博客 495

SAP软件外币评估系统配置与操作

文章摘要:本文详细介绍了SAP系统中外币评估的流程、策略及系统操作。外币评估是期末关账的重要环节,主要针对外币未清项目及资产/负债进行汇率重估,生成评估差异过账以反映真实财务状况。文中阐述了三种评估策略(不评估、增量评估、期末评估冲回)及适用场景,并提供了SAP系统外币评估的具体操作步骤(FAGL_FCV/FAGL_FC_VAL事务码)。同时,讲解了货币资金科目和未清项管理科目的评估差异处理方式,以及相关的系统配置(OB59、OBA1等)。文章还区分了已实现和未实现汇兑损益的会计处理,为企业外币业务管理提供

weixin_40672823的博客 1967

数学建模学习(75):全局敏感性分析Morris 方法

敏感性分析 (SA) 是分析不同应用条件下模型行为的基本实践。提出了许多 SA 技术,从简单的筛选方法到计算成本高昂的基于方差的方法。本篇内容我们通过将 Morris 方法来对模型进行分析。

全栈川川 1万+

Codeforces Round 903 (Div. 3)A~F

题意:字符串s每次操作后变成s+s,问能否操作若干次是t是s的字串。思路:数据范围很小,len(s)和len(t)最大25,要么如果枚举到len(s)长度大于等于len(t)的二倍,还没有出现答案,之后就不会出现答案。故需要枚举log2(50)上取整次,即六次。

weixin_62701031的博客 997

【温室气体数据集】CAMS 发布的温室气体(GHG)数据集总结

【温室气体数据集】CAMS 发布的温室气体(GHG)数据集总结

WW、forever的博客 561

Codeforces Round 939

Codeforces Round 939

青少年趣味编程 817

使用geneHapR进行基因单倍型分析(以vcf文件为例)

如下图所示,可以看到,用户需要准备的包括:基因型文件、注释文件和样本信息文件,以及后续会用的表型文件。输出的主要内容有:变异位点的可视化、单倍型网络、地理分布、表型比较和连锁不平衡热图。geneHapR的工作流程。

沉香best的博客 5943

多模态轨迹预测:行人、车辆的交互式推理

多模态轨迹预测:行人、车辆的交互式推理 ,人工智能,计算机视觉,大模型,AI,本文围绕多模态轨迹预测中行人与车辆的交互式推理展开,介绍了其定义,即综合多种信息预测交通参与者未来多种轨迹。涵盖基础概念如轨迹表示、模态、交互关系,技术框架包括数据处理、特征提取、预测模型(物理、机器学习、深度学习模型等)及结果评估。还探讨了交互式推理方法、面临的不确定性处理等挑战、应用场景、未来发展方向、相关工具及实际案例,展现了该技术在智能交通等领域的重要性与发展潜力。​

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 14万+

Codeforces Round 984

Codeforces Round 984

青少年趣味编程 1579

FLUENT 软件中design modeler网格划分后,导出失败:系统显示“在网格文件导出过程中出现异常。请将数据发送给您的技术支持供应商。”...如何解决?

🏆 本文收录于《全栈Bug调优(实战版)》专栏,致力于分享我在项目实战过程中遇到的各类Bug及其原因,并提供切实有效的解决方案。无论你是初学者还是经验丰富的开发者,本文将为你指引出一条更高效的Bug修复之路,助你早日登顶,迈向财富自由的梦想🚀!同时,欢迎大家关注、收藏、订阅本专栏,更多精彩内容正在持续更新中。让我们一起进步,Up!Up!Up!    备注: 部分问题/难题源自互联网,经过精心筛选和整理,结合数位十多年大厂实战经验资深大佬经验总结所得,数条可行方案供所需之人参考。

**My Coding Family** 1480

Codeforces Round 881-930

Codeforces Round 881-930(50题)

青少年趣味编程 3020

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Codeforces Round 987

Codeforces Round 987

青少年趣味编程 1398

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces Round 1019

Codeforces Round 1019

青少年趣味编程 1749

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Codeforces Round 930

Codeforces Round 930

青少年趣味编程 898

Codeforces Round 1023

Codeforces Round 1023

青少年趣味编程 656

Codeforces Round 944

Codeforces Round 944

青少年趣味编程 1102

Codeforces Round 983

Codeforces Round 983

青少年趣味编程 864

Codeforces Round 1018--1032

Codeforces Round 1018--1032

青少年趣味编程 881

Codeforces Round 957

Codeforces Round 957

青少年趣味编程 720

Codeforces Round 1033

Codeforces Round 1033

青少年趣味编程 1006

Codeforces Round 1010

Codeforces Round 1010

青少年趣味编程 1034

Codeforces Round 990

Codeforces Round 990

青少年趣味编程 769

Codeforces Round 947

Codeforces Round 947

青少年趣味编程 980
上一篇: AIM Tech Round 5 (rated, Div. 1 + Div. 2)
下一篇: struts2入门
轩辕小猪
博客等级 码龄10年 104粉丝 83原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址