贪心
Prime me
Nobody can defeat me unless I don't want to win.
展开
-
还是畅通工程(prim&&kruskal)
prime和kruskal两种算法适用于解决最小生成树的两种算法。但是两种算法思想方式所以可以用于解决不同的连通图问题。下面分别详细介绍两种算法的算法思想以及实现过程,最后会分析两种算法的不同适应情况。kruskal此方法可以称为加边法。即将边的权值大小排好序之后按照从小到大的顺序依次将n-1条边加入到生成树中。做法如下:1,先将边的权值将边从小到大进行排序。2,将所有的点看作n棵独立的树组成的森林。3,按排好的顺序依次将边连接到树上,注意的一条筛选条件是每次选择的边的两个点都必须是相互独立的,即原创 2021-11-29 16:14:44 · 236 阅读 · 0 评论 -
最短路算法
今天重新学习贪心,对单源最短路径有了新的认知,迪杰斯特拉算法就是我们常用的最短路算法,该算法本质是在贪心的基础上进行的图论延申。单源最短路径即为从一个点到其他点的最短路。该算法主要通过以下几步来完成。1:初始化最短路数组,dis[1]=0,dis[i]=+1000000000;2:循环n次,每次找出所有点中距离起点最近的那个点,将该点标记后,用该点更新其他的点的最短路距离。以下即为迪杰斯特拉算法的朴素算法代码模板。#include<stdio.h>#include<cstri原创 2021-11-26 20:24:30 · 98 阅读 · 0 评论 -
Fight against involution(第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南))
区间贪心问题,在不减少自己的分的前提下,将自己写作的字数降到最低。要求是尽可能的少写字,但是前提是不能降低自己的得分。先按照上限降低排序,上限相同按照下限相等排序。#include <iostream>#include<algorithm>#include <cstdio>#include<cmath>#include<cstring>using namespace std;const int M = 1e5 + 1;struc原创 2021-11-19 21:04:01 · 554 阅读 · 0 评论 -
C. Slay the Dragon
Recently, Petya learned about a new game “Slay the Dragon”. As the name suggests, the player will have to fight with dragons. To defeat a dragon, you have to kill it and defend your castle. To do this, the player has a squad of n heroes, the strength of t.原创 2021-09-21 18:49:54 · 475 阅读 · 0 评论 -
Almost Sorted Array(最长上升子序列o(nlogn))
We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, selection sort, bubble sort, etc. But sometimes it is an overkill to use these algorithms for an almost sorted array.We say an array is sorted if its elements.原创 2021-07-31 22:01:54 · 116 阅读 · 0 评论 -
FatMouse‘ Trade
极致性价比问题先求出性价比排名,再按照性价比高低从上向下依次录取#include<iostream>#include<algorithm>using namespace std;struct TIME{ int start; int end; bool flag=0;};bool cmp(TIME a,TIME b){ if(a.start==b.start) return a.end<b.end; re原创 2021-04-04 18:59:25 · 48 阅读 · 0 评论 -
贪心问题之会场安排问题
#include<iostream>#include<algorithm>using namespace std;struct TIME{ int start; int end; bool flag=0;};bool cmp(TIME a,TIME b){ if(a.start==b.start) return a.end<b.end; return a.start<b.start;}int ma.原创 2021-04-04 18:11:46 · 119 阅读 · 0 评论 -
今年暑假不AC?--会场安排问题对比题解
***今年暑假不AC?![在这里插入图片描述](https://img-blog.csdnimg.cn/20200930201536656.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjU3NDI4Mg==,size_16,color_FFFFFF,t_70#pic_center)上述两张图片即为题目与检测数据原创 2020-09-30 20:24:24 · 117 阅读 · 0 评论 -
B - Partial Replacement
***B - Partial Replacement ***题目:You are given a number k and a string s of length n, consisting of the characters ‘.’ and ‘’. You want to replace some of the '’ characters with ‘x’ characters so that the following conditions are met:The first characte原创 2021-03-28 10:25:17 · 196 阅读 · 0 评论