自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

0x3f3f3f3f

我要一步一步往上爬,在最高点乘着叶片往前飞

  • 博客(62)
  • 收藏
  • 关注

原创 HDU 1010 —— Tempter of the Bone DFS+剪枝

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1010题意:从S走到D,其中X是墙,不能走;给定时间 t ,问能否从S到D正好花费 t 时间(一步即为一秒);思路:用DFS+剪枝;此处有两种剪枝:1、从S到D的最短时间是 tmp = abs(sx-dx)+abs(sy-dy),如果 tmp > t,显然是“NO”;2、如果 t

2017-02-09 16:30:27 361

原创 HDU 2177 —— 取(2堆)石子游戏

原题:http://acm.hdu.edu.cn/showproblem.php?pid=2177#include#includeusing namespace std;int a, b;int main(){ while(cin>>a>>b){ if(a == 0 && b == 0) break; double tmp = (s

2016-12-02 23:11:07 426

原创 HDU 1527 —— 取石子游戏(入门水题)

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1527#include#includeusing namespace std;int a, b;int main(){ while(cin>>a>>b){ int k = abs(a-b); double tmp = (sqrt(5)+1)/2.0

2016-12-02 22:30:15 379

原创 HDU 1907 —— John

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1907题意:取法和Nim游戏一样,但是最后拿完的那个人是loser;思路:需要考虑特殊情况 —— 最开始每堆的个数都为1,这个时候对堆数进行奇偶判断;#includeusing namespace std;const int maxn = 50;int cas, n;int a[

2016-12-02 16:01:53 313

原创 HDU 1849 —— Rabbit and Grass

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1849思路:以两个棋子为例,如果当前它们在不同的位置,那么先手只需要将两个棋子变成在同一个位置,就能获胜,与Nim博弈类似;#includeusing namespace std;int m;int main(){ while(cin>>m){ if(m ==

2016-12-02 12:18:27 346

原创 POJ 2234 —— Matches Game 入门水题

原题:http://poj.org/problem?id=2234#includeusing namespace std;int m;int main(){ while(cin>>m){ int x = 0; while(m--){ int y; cin>>y; x =

2016-12-02 12:08:10 284

转载 Nim博弈讲解篇

Nim游戏的概述:还记得这个游戏吗?给出n列珍珠,两人轮流取珍珠,每次在某一列中取至少1颗珍珠,但不能在两列中取。最后拿光珍珠的人输。后来,在一份资料上看到,这种游戏称为“拈(Nim)”。据说,它源自中国,经由被贩卖到美洲的奴工们外传。辛苦的工人们,在工作闲暇之余,用石头玩游戏以排遣寂寞。后来流传到高级人士,则用便士(Pennies),在酒吧柜台上玩。最有名的玩法,是把十二枚便

2016-12-02 12:06:38 337

原创 Codeforces Beta Round #17 D. Notepad

原题:http://codeforces.com/contest/17/problem/D题意:求[(b-1)*b^(n-1)]%c, 如果ans = 0, 则ans = c;思路:指数循环节 ——(其中Φ为欧拉函数);#include #define ll __int64 using namespace std; const int maxn

2016-11-28 16:52:35 246

原创 HDU 1069 —— Monkey and Banana

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1069#include#includeusing namespace std;const int maxn = 1100;int n;int dp[maxn];int T = 0;struct node{ int x, y, z; friend bool operato

2016-07-02 16:52:18 290

原创 Codeforces Round #260 (Div. 2)

A. Laptops题意:有n台电脑,给出每台电脑的价格 p 和质量q ;问是否存在这样的电脑——价格比另一台低并且质量比另一台好;如果存在就输出 “Happy Alex”,否则输出“Poor Alex”;#include#includeusing namespace std;const int maxn = 1e5+5;int n;int p[maxn],

2016-05-29 17:02:34 296

原创 POJ 1087 —— A Plug for UNIX

原题:http://poj.org/problem?id=1087题意:n个插座,m个电器及其对应的插座,k种转化器,转换器(u,v)表示可以把原本需要u插座的电器转接到v插座上,问最少有多少设备没有插座用,每种转换器数量不限;;#include#include#include#include#include#include#include#define in

2016-05-09 23:14:24 863

原创 HDU 3605 —— Escape 状态压缩+最大流

原题:http://acm.hdu.edu.cn/showproblem.php?pid=3605#include#include#include#include#include#include#include#define inf 1e9using namespace std;const int maxn = 1500;const int maxm = 1

2016-05-09 14:29:00 957

原创 HDU 2883 —— kebab

原题:http://acm.hdu.edu.cn/showproblem.php?pid=2883#include#include#include#include#include#include#define inf 1e9using namespace std;const int maxn = 41000;const int maxm = 8040000;int

2016-05-08 23:06:53 670

原创 HDU 2732 —— Leapin' Lizards

原题:http://acm.hdu.edu.cn/showproblem.php?pid=2732#include#include#include#include#include#include#define inf 1e9using namespace std;const int maxn = 850;const int maxm = 200000;int cas

2016-05-08 14:51:31 402

原创 poj 2289 —— Jamie's Contact Groups 二分+最大流

原题:http://poj.org/problem?id=2289#include#include#include#include#include#include#include#define inf 1e9using namespace std;const int maxn = 2000;const int maxm = 510000;int n, m, num

2016-05-08 13:43:50 719

原创 POJ 2391 —— Ombrophobic Bovines 二分+Floyd+最大流

原题:http://poj.org/problem?id=2391#include#include#include#include#include#define inf 1LL<<60#define ll long longusing namespace std;const int maxn = 500;const int maxm = 50000;int f, p

2016-05-06 22:39:51 715

原创 POJ 2112 —— Optimal Milking 二分+Floyd+最大流

原题:http://poj.org/problem?id=2112#include#include#include#include#include#include#define inf 0x3f3f3f3fusing namespace std;const int maxn = 250;int dis[maxn][maxn];int k, c, m;int num

2016-05-06 15:54:34 606

原创 POJ 3498 —— March of the Penguins (枚举+最大流)

#include#include#include#include#include#include#define inf 0x3f3f3f3fusing namespace std;const int maxn = 205;int num_nodes;int n;double m;struct Edge{ int from, to, flow, cap;}edge[ma

2016-05-03 22:19:19 395

原创 POJ 1698 —— Alice's Chance

#include#include#include#include#include#include#define inf 0x3f3f3f3fusing namespace std;const int maxn = 50000;int num_nodes;struct Edge{ int from, to, flow, cap;}edge[maxn*2];vector

2016-05-03 21:54:05 398

原创 POJ 3281 —— Dining

原题:http://poj.org/problem?id=3281题意:有F种食物,D种饮料,N头牛;下面N行给出每头牛喜欢的食物种数和饮料种数,并且分别给出喜欢的食物的种类和饮料的种类;问最多可以满足几头牛吃到自己喜欢的食物和饮料;每种食物或者饮料只能提供给一头牛,每头牛只能吃一种食物和饮料;思路:建立一个超级源点 s 和一个超级汇点 t ,因为食物和饮料之间没有直接关系

2016-04-26 22:55:25 318

原创 POJ 1459 —— Power Network

原题:http://poj.org/problem?id=1459题意:一共有n个结点,在这些结点中有 np 个是发电站,有 nc 个是用户,给出m条线路所能运输的电量,以及每个发电站输出的电量、每个用户能接收的电量;问用户所能接收的最大电量;思路:因为是多源多汇,所以我们建立一个超级源点 s = n 和一个超级汇点 t = n+1;建立 s 到发电站的的边,容量就是发电站

2016-04-26 21:19:21 287

原创 POJ 1273 —— Drainage Ditches 入门题

原题:http://poj.org/problem?id=1273题意:有 m 个点,n 条边,求 1 到 m 的最大流,模板题;#include#include#include#include#include#include#define inf 0x3f3f3f3fusing namespace std;const int maxn = 250;int

2016-04-25 15:58:57 306

原创 HDU 3549 —— Flow Problem

原题:http://acm.hdu.edu.cn/showproblem.php?pid=3549题意:求 1 到 n 的最大流,模板题;#include#include#include#include#include#include#define inf 0x3f3f3f3fusing namespace std;const int maxn = 1100

2016-04-25 15:56:56 288

原创 POJ 2553 —— The Bottom of a Graph

原题:http://poj.org/problem?id=2553题意:给出n个点,m条边的有向图;问有多少个点 v 满足—— v能到u,u也能到v(v能到达的所有点都要能回到v);思路:出度 = 0 的强连通分量里的点都满足该情况;#include #include #include #include#include #include #defi

2016-04-21 20:43:44 307

原创 ZOJ 3630 —— Information

原题:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3630题意:有n个点,m条边,删除一个点后,得到强连通分量点数的最大值,求最大点数的最小值;注意:点数 = 1 时为 0 ;思路:枚举每个点为删除点,求出每次强连通分量的最大值,然后取最小的;#include#include#incl

2016-04-17 21:37:29 561

原创 UVALive 6195 —— The Dueling Philosophers Problem

原题:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4206题意:有n个点,给出m条限制关系,即a必须在b前面;将这n个点进行先后排序,如果只有一种排序方法,则输出 1 ;如果有多种,则输出 2 ;如果无法给出排序(即存在矛盾关

2016-04-16 16:42:23 385

原创 CodeForces 475B —— Strongly Connected City

原题:http://codeforces.com/problemset/problem/475/B题意:有n条横线和m条竖线形成一个网格图,第一行给出每条横线的方向,第二行给出每条竖线的方向;问图中的任意两个交点是否可以相互到达(只能沿着线的方向走);思路:就是判断该图是否强连通;那么如何建图?—— 每条线上相邻的点之间按照该线的方向建立一条单向边;#includeu

2016-04-16 15:53:02 343

原创 POJ 2186 —— Popular Cows

原题:http://poj.org/problem?id=2186题意:问有多少个点满足条件 —— 其他所有的点都可以到达它;思路:先求强连通分量,然后反向构建DAG图,新图中的点权就是每个强连通分量所包含的点的个数(因为强连通分量中任意两点均可达);如果新图中入度 = 0 的点超过一个就输出 0 ,否则就输出该点的点权;Q:为什么要反向建图? A:反向建图就将问题转化成了从该

2016-04-15 22:51:45 280

原创 POJ 1236 —— Network of Schools

原题:http://poj.org/problem?id=1236题意:有n个点,下面n行给出与第i个点相连的结点;在某个点放置软件,那么与该点相连的点也可以得到该软件,问最少要在几个点放置软件;第二问是至少要添加几条边使得该图强连通;思路:通过强连通求得DAG图,第一问就是求新图中入度 = 0 的点的个数;第二问就是求新图中max ( 入度 = 0 的点个数, 出度 = 0 的点

2016-04-15 20:49:34 283

原创 HDU 1269 —— 迷宫城堡

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1269思路:即强连通分量的个数为1;#include#include#include#includeusing namespace std;const int maxn = 11000;const int maxm = 110000;int n, m;int head

2016-04-12 22:54:44 330

原创 POJ 2762 —— Going from u to v or from v to u? 强连通+拓扑

原题:http://poj.org/problem?id=2762题意:判断图中任意两点是否单连通;思路:求强连通分量,缩点构建新图,然后进行拓扑排序,每次入度 = 0 的点只能有一个,如果多于一个则输出“No”;#include#include#include#include#includeusing namespace std;const int max

2016-04-12 22:45:18 270

原创 HDU 1827 —— Summer Holiday

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1827思路:先求强连通分量,缩点构建新图,新图中入度 = 0 的点的个数就是所求的最少人数,对于每个入度 = 0 的强连通分量选取最小的话费值,其和即为所求的最少话费;

2016-04-11 21:41:06 286

原创 HDU 3836 —— Equivalent Sets

原题:http://acm.hdu.edu.cn/showproblem.php?pid=3836题意:问至少要加几条边,使得该图强连通(即图中任意两点都连通);思路:先求原图的强连通分量,然后进行缩点构建新图,在新图中,求入度 = 0 和 出度 = 0 的个数,两者的最大值即为答案;#include#include#include#includeusing n

2016-04-11 16:06:54 335

原创 Educational Codeforces Round 9

A. Grandma Laura and Apples题意:n 和 p 分别表示有n次购买以及苹果的单价p;下面n行,half表示购买一半的苹果,halfplus表示购买一半的苹果再赠送半个苹果,n次购买之后苹果没有剩余,问一共卖了多少钱;思路:因为最后苹果没有剩余,即为0,所以我们从最后一次购买进行倒推,half — 直接*2,halfplus — 先+0.5再*2;

2016-04-06 22:11:34 347

原创 UVA 540 —— Team Queue

原题:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=481题意:有n组人,给出每组人的编号;有两种操作 —— 1、ENQUEUE X 表示将编号为X的人入队,如果队列当中已经有与X同组的成员,那么就将X排在同组的最后一个成员的后面;如果队列中没有

2016-03-28 20:52:56 419

原创 HDU 1423 —— Greatest Common Increasing Subsequence

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1423题意:求最长上升公共子序列的个数;注意:每组数据之间要空一行,最后一组数据结束不需要空行;#include#include#include#includeusing namespace std;const int maxn = 510;int cas, n, m;in

2016-03-13 21:19:18 342

原创 HDU 1025 —— Constructing Roads In JGShining's Kingdom 最长上升子序列

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1025题意:有n个穷城市,n个富城市,每个穷城市都要从某个富城市运输一种物资(穷城市和富城市的物资供需一对一),需要建立道路,但任意两条路不能交叉;穷城市和富城市分    别位列平行线两侧(均按1 - n 分布);   给出城市个数n,下面n行输入两个数字 p 和 r 表示穷城市p要从富城市r运

2016-03-07 22:43:07 359

原创 POJ 3903 —— Stock Exchange 最长上升子序列

原题:http://poj.org/problem?id=3903题意:求最长上升子序列的个数;#include#includeusing namespace std;const int maxn = 1000000+10;int stack[maxn];int n;int main(){ while(~scanf("%d", &n)) { int top

2016-03-07 21:10:28 378

原创 POJ 1631 —— Bridging signals 最长上升子序列

原题:http://poj.org/problem?id=1631题意:有n个数,求最长上升子序列的个数;#include#includeusing namespace std;const int maxn = 40000+10;int stack[maxn];int cas, n;int main(){ scanf("%d", &cas); while(cas

2016-03-07 21:04:42 340

原创 POJ 1887 —— Testing the CATCHER 最长下降子序列

原题:http://poj.org/problem?id=1887求最长下降子序列个数注意输出格式!O(n²)#include#includeusing namespace std;int dp[100000000];int a[100000000];int cas = 0;int main(){ int tmp; while(~scanf("%d",

2016-03-07 20:47:38 741

空空如也

空空如也

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

TA关注的人

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