关闭

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)...
阅读(327) 评论(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->v;反过来如果v->u是可达的,则添加的边的指向肯定是v->u;如果u->v,v->u均不可达,则添加的新边的指向可...
阅读(240) 评论(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求解是因为即使给定一个很大的数,满足条件的跳跃数的数目也是很小的,因此整个bfs的搜索空间是很小的,足够高效。 2.数位DP dp[i][j]:...
阅读(129) 评论(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(u,v)=1,建边(u’,v)=0;如果w(u,v)=2,则建边(u’,v)=1。通过上面建图过程,我们只需...
阅读(206) 评论(0)

Find a Mother Vertex in a Graph

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

Library Query

Library Query解题思路:建立1000棵树状数组维护一下即可。#include #include #include #include #include #include #include #include #include #include...
阅读(129) 评论(0)

位运算总结

总结一些简单的位运算的操作并利用位运算来解决一些问题,注意: &, |, ^在进行位运算时是将操作数的符号位也考虑在内的。 求解整数的绝对值 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...
阅读(345) 评论(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 first difference (if one exists) may be either posi...
阅读(203) 评论(0)

Subsequence Weighting

题目链接#include #include #include #include #include #include #include #include #include using namespace std; typedef long l...
阅读(116) 评论(0)

Mr. X and His Shots

这里写链接内容#include #include #include #include #include #include #include using namespace std; const int maxn = 100010;struct Line {...
阅读(152) 评论(0)

Coloring Tree

给你一棵N个节点的树(无向无环连通图),每个节点有一个颜色。你知道树的根节点(树的根节点是一个特殊的节点,是树节点中唯一没有父节点的)。颜色用1到109范围内的整数表示。现在,你需要回答M个查询,每个查询询问以节点s为根的子树节点中,不同颜色的数目。(s会在输入中给出)。输入格式第一行包含3个空格分隔的整数 (N M root)表示树的节点数、查询数和根节点。接下来N行,每行包含着2个空格分隔的整数...
阅读(127) 评论(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. Unfortunately, someone messed up the transit and the crates are...
阅读(368) 评论(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 weighted forest is a vertex from which no edge goes and wh...
阅读(355) 评论(0)

UVA 12265 Selling Land

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65530#problem/S解题思路:递推+单调栈。具体思路见紫书。#include #include #include #include #include #include <iostrea...
阅读(556) 评论(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 subsequence contains a unique element, i.e. an elem...
阅读(633) 评论(0)
241条 共17页1 2 3 4 5 ... 下一页 尾页
    个人资料
    • 访问:85033次
    • 积分:3067
    • 等级:
    • 排名:第12541名
    • 原创:230篇
    • 转载:11篇
    • 译文:0篇
    • 评论:3条
    文章分类
    最新评论