自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

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

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

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

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

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

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

原创 位运算总结

总结一些简单的位运算的操作并利用位运算来解决一些问题,注意: &, |, ^在进行位运算时是将操作数的符号位也考虑在内的。求解整数的绝对值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 652

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

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

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

原创 Coloring Tree

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

2016-07-21 20:00:30 562

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

2016-01-06 20:46:22 662

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

2016-01-06 15:46:58 589

原创 UVA 12265 Selling Land

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

2015-12-25 16:56:25 803

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

2015-12-23 21:58:58 1010

原创 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 capital city. A part of your forti cation is a line of ma

2015-12-22 16:50:55 515

原创 UVA 11134 Fabled Rooks

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

2015-12-17 21:28:49 1779

原创 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 , 172441277 and 47770142 are nya numbers.But 14777 is not a ny

2015-12-13 14:44:39 471

原创 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 positive integer.It's an increasing sequence. For each i >=

2015-12-13 13:42:06 457

原创 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 smaller elements to the right of nums[i].Example:Given

2015-12-12 22:58:49 683

原创 ZOJ 3505 Yet Another Set of Numbers

You are given yet another set of numbers. The numbers in this set obey these rules:Each number will start with a non-zero digit.Each number contains at most N digits and only 0, 1, 2 and 3 are availab

2015-12-12 22:09:01 341

原创 POJ 3208 Apocalypse Someday

DescriptionThe number 666 is considered to be the occult “number of the beast” and is a well used number in all major apocalypse themed blockbuster movies. However the number 666 can’t always be used i

2015-12-12 11:54:00 713

原创 Codeforces 600E Lomsat gelral

You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour.Let’s call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subt

2015-11-30 19:03:28 1093

原创 Codeforces 295B Greg and Graph

Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has in

2015-11-26 21:34:19 520

原创 HDU 4276 The Ghost Blows Light

My name is Hu Bayi, robing an ancient tomb in Tibet. The tomb consists of N rooms (numbered from 1 to N) which are connected by some roads (pass each road should cost some time). There is exactly one r

2015-11-25 15:56:09 541

原创 Codeforces 527D Clique Problem

The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph G. It is required to find a subset of vert

2015-11-23 21:49:07 453

原创 Codeforces 448C Painting Fence

Bizon the Champion isn’t just attentive, he also is very hardworking.Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in

2015-11-21 16:43:59 404

原创 Codeforces 557C Arthur and Table

Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.In total the table Arthur bought has n legs, the length of the i-th leg is li

2015-11-20 23:03:05 455

原创 HDU 4003 Find Metal Mineral

Problem Description Humans have discovered a kind of new metal mineral on Mars which are distributed in point‐like with paths connecting each of them which formed a tree. Now Humans launches k robots

2015-11-18 00:32:55 315

原创 HDU 1011 Starship Troopers

Problem Description You, the leader of Starship Troopers, are sent to destroy a base of the bugs. The base is built underground. It is actually a huge cavern, which consists of many rooms connected wi

2015-11-16 21:37:39 382

原创 Codeforces 598E Chocolate Bar

You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar.In one move you can break any single rectangular p

2015-11-14 17:18:04 509

原创 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 length (in edges) of the shortest path between these vertices.You are given a tree with n

2015-11-13 22:46:55 556

原创 Codeforces 513B2 Permutations

You are given a permutation p of numbers 1, 2, …, n. Let’s define f(p) as the following sum:Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possibl

2015-11-12 21:39:44 852

原创 Codeforces 558C Amr and Chemistry

Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For th

2015-11-07 15:10:25 720

原创 Codeforces 489D Unbearable Controversy of Being

Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It’s no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one

2015-11-07 09:41:31 389

原创 Codeforces 547B Mike and Feet

Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-t

2015-11-06 17:42:03 807

原创 Codeforces 460C Present

Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He plan

2015-11-06 14:41:59 756

原创 Codeforces 339C Xenia and Weights

C. Xenia and Weightstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia has a set of weights and pan sca

2015-11-03 21:22:30 888

原创 Codeforces 592D Super M

D. Super Mtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAri the monster is not an ordinary monster. She

2015-11-01 12:31:45 1403

原创 HDU 5525 Product

Problem DescriptionGiven a number sequence A1,A2....An,indicatingN=∏ni=1iAi.What is the product of all the divisors of N? InputThere are multiple test cases.First line of each case c

2015-10-31 22:23:17 653

空空如也

空空如也

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

TA关注的人

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