排序:
默认
按更新时间
按访问量

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 distan...

2016-07-30 11:49:06

阅读数:409

评论数:0

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->...

2016-07-30 11:28:05

阅读数:315

评论数:0

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求解是因为即使给定一个很大的数,满足条件的跳...

2016-07-30 09:58:10

阅读数:190

评论数:0

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...

2016-07-29 22:49:58

阅读数:257

评论数:0

Find a Mother Vertex in a Graph

Find a Mother Vertex in a Graph解题思路:存在两种方法可以解决这个问题 1. 并查集 我们利用并查集维护一个一个顶点为根节点且其子树的所有节点均可由该根节点到达,维护这样的一个个集合。合并时按照有向边的指向合并即可。 2.直接dfs 假设如果存在一棵有某个顶点...

2016-07-29 20:16:47

阅读数:247

评论数:0

Library Query

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

2016-07-25 23:11:49

阅读数:171

评论数:0

位运算总结

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

2016-07-25 23:09:45

阅读数:395

评论数:0

Wiggle Subsequence

A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The...

2016-07-22 11:51:57

阅读数:240

评论数:0

Subsequence Weighting

题目链接#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #include <set> #in...

2016-07-21 23:21:02

阅读数:156

评论数:0

Mr. X and His Shots

这里写链接内容#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #include <iostream...

2016-07-21 22:13:04

阅读数:236

评论数:0

Coloring Tree

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

2016-07-21 20:00:30

阅读数:151

评论数:0

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. Unfortunatel...

2016-01-06 20:46:22

阅读数:406

评论数:0

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 weight...

2016-01-06 15:46:58

阅读数:402

评论数:0

UVA 12265 Selling Land

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65530#problem/S解题思路:递推+单调栈。具体思路见紫书。#include <ctime> #include <cmath> #include ...

2015-12-25 16:56:25

阅读数:605

评论数:0

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...

2015-12-23 21:58:58

阅读数:753

评论数:0

UVA 1471 Defense Lines

After the last war devastated your country, you - as the king of the land of Ardenia - decided it was high time to improve the defense of your capit...

2015-12-22 16:50:55

阅读数:326

评论数:0

UVA 11134 Fabled Rooks

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65530#problem/D解题思路:由于行和列之间是不相互影响的,因此我们对行和列分开进行处理。然后对于每行和每列采用贪心的方法进行安置即可。#include <cmat...

2015-12-17 21:28:49

阅读数:1551

评论数:0

HDU 3943 K-th Nya Number

Problem Description Arcueid likes nya number very much. A nya number is the number which has exactly X fours and Y sevens(If X=2 and Y=3 , 17244127...

2015-12-13 14:44:39

阅读数:262

评论数:0

ZOJ 3293 Simple Sequence

Recently, watashi finds a simple sequence S = {si} i >= 1 in a book. This sequence is determined by the following rules:For each si, si is a posit...

2015-12-13 13:42:06

阅读数:259

评论数:0

leetcode Count of Smaller Numbers After Self

You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of sma...

2015-12-12 22:58:49

阅读数:481

评论数:0

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