原创 Codeforces 161D Distance in Tree

A tree is a connected graph that doesn’t contain any cycles. The distance between two vertices of a tree is the len

原创 HDU 5525 Product

Problem Description Given a number sequence A1,A2....An,indicating N=∏ni=1iAi.What is the product of all the divisors

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

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

原创 Find a Mother Vertex in a Graph

Find a Mother Vertex in a Graph 解題思路:存在兩種方法可以解決這個問題 1. 並查集 我們利用並查集維護一個一個頂點爲根節點且其子樹的所有節點均可由該根節點到達,維護這樣的一個個集合。合併時按照有向邊的

原创 Mr. X and His Shots

題目鏈接 #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #include <iostream> #in

原创 Library Query

Library Query 解題思路:建立1000棵樹狀數組維護一下即可。 #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include

原创 UVA 11134 Fabled Rooks

題目鏈接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65530#problem/D 解題思路:由於行和列之間是不相互影響的,因此我們對行和列分開進行處理。然後對於每行和每列

原创 位運算總結

總結一些簡單的位運算的操作並利用位運算來解決一些問題,注意: &, |, ^在進行位運算時是將操作數的符號位也考慮在內的。 求解整數的絕對值 int abs(int a) { return (a ^ (a>>31)) - (a

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

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

原创 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開始搜索,沿着跳躍數的規則進行擴展,找出所有小於等於給定值的跳躍數的個數。

原创 Subsequence Weighting

題目鏈接 #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #include <set> #include

原创 Wiggle Subsequence

A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate betw

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