自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(11)
  • 收藏
  • 关注

转载 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)

2016-07-30 11:49:06 1435

原创 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均不可达,则添加的新边的指向可

2016-07-30 11:28:05 626

原创 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]:

2016-07-30 09:58:10 557

原创 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。通过上面建图过程,我们只需

2016-07-29 22:49:58 544

原创 Find a Mother Vertex in a Graph

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

2016-07-29 20:16:47 737

原创 Library Query

Library Query解题思路:建立1000棵树状数组维护一下即可。#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <vector>#include <deque>#include <queue>#include <stack>#include <map>#include

2016-07-25 23:11:49 420

原创 位运算总结

总结一些简单的位运算的操作并利用位运算来解决一些问题,注意: &, |, ^在进行位运算时是将操作数的符号位也考虑在内的。求解整数的绝对值int abs(int a) { return (a ^ (a>>31)) - (a>>31);}求两个数的最大值int max(int a, int b) { return (b&((a-b)>>31)) | (a&(~(a-b)>>3

2016-07-25 23:09:45 677

原创 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

2016-07-22 11:51:57 490

原创 Subsequence Weighting

题目链接#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <vector>#include <set>#include <map>#include <iostream>#include <algorithm>using namespace std;typedef long l

2016-07-21 23:21:02 374

原创 Mr. X and His Shots

这里写链接内容#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <vector>#include <iostream>#include <algorithm>using namespace std;const int maxn = 100010;struct Line {

2016-07-21 22:13:04 561

原创 Coloring Tree

给你一棵N个节点的树(无向无环连通图),每个节点有一个颜色。你知道树的根节点(树的根节点是一个特殊的节点,是树节点中唯一没有父节点的)。颜色用1到109范围内的整数表示。现在,你需要回答M个查询,每个查询询问以节点s为根的子树节点中,不同颜色的数目。(s会在输入中给出)。输入格式第一行包含3个空格分隔的整数 (N M root)表示树的节点数、查询数和根节点。接下来N行,每行包含着2个空格分隔的整数

2016-07-21 20:00:30 623

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除