# K Centers Problem | Set 1 (Greedy Approximate Algorithm)

Given n cities and distances between every pair of cities, select k cities to place warehouses (or ATMs or Cloud Server) such that the maximum distance of a city to a warehouse (or ATM or Cloud Server)...

# Assign directions to edges so that the directed graph remains acyclic

Assign directions to edges so that the directed graph remains acyclic解题思路：首先我们考虑怎么加边，假设原图只有有向边构成。对于每一条无向边（u，v）如果在原图中u->v是可达的，则我们添加的这条边的指向肯定是u->v；反过来如果v->u是可达的，则添加的边的指向肯定是v->u；如果u->v,v->u均不可达，则添加的新边的指向可...

# Print all Jumping Numbers smaller than or equal to a given value

Print all Jumping Numbers smaller than or equal to a given value解题思路： 1. bfs 从0开始搜索，沿着跳跃数的规则进行扩展，找出所有小于等于给定值的跳跃数的个数。之所以能够用bfs求解是因为即使给定一个很大的数，满足条件的跳跃数的数目也是很小的，因此整个bfs的搜索空间是很小的，足够高效。 2.数位DP dp[i][j]:...

# Shortest Path in a weighted Graph where weight of an edge is 1 or 2

Shortest Path in a weighted Graph where weight of an edge is 1 or 2解题思路： bfs适用于求解权值相同的图的最短路径。因此对原图进行改造，拆点u–>u,u’。其中u负责入边，u’负责出边。建图过程：w(u,u’)=1，如果w(u,v)=1，建边(u’,v)=0；如果w(u,v)=2，则建边（u’,v）=1。通过上面建图过程，我们只需...

# Find a Mother Vertex in a Graph

Find a Mother Vertex in a Graph解题思路：存在两种方法可以解决这个问题 1. 并查集 我们利用并查集维护一个一个顶点为根节点且其子树的所有节点均可由该根节点到达，维护这样的一个个集合。合并时按照有向边的指向合并即可。 2.直接dfs 假设如果存在一棵有某个顶点生成的dfs树，则我们只需要对原先的有向图不断地进行dfs即可，保存该趟dfs最后遍历的顶点。最终判断该...

# Library Query

Library Query解题思路：建立1000棵树状数组维护一下即可。#include #include #include #include #include #include #include #include #include #include...

# Wiggle Subsequence

A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either posi...

# uva 1611 Crane

There are n crates waiting to be loaded onto a ship. The crates are numbered 1, 2, … , n, the numbers determining the order of loading. Unfortunately, someone messed up the transit and the crates are...

# Codeforces 195E Building Forest

An oriented weighted forest is an acyclic weighted digraph in which from each vertex at most one edge goes.The root of vertex v of an oriented weighted forest is a vertex from which no edge goes and wh...

# UVA 1608 Non-boring sequences

e were afraid of making this problem statement too boring, so we decided to keep it short. A sequence is called non-boring if its every connected subsequence contains a unique element, i.e. an elem...

241条 共17页1 2 3 4 5 ... 下一页 尾页
个人资料
• 访问：85033次
• 积分：3067
• 等级：
• 排名：第12541名
• 原创：230篇
• 转载：11篇
• 译文：0篇
• 评论：3条
文章分类
评论排行
最新评论