自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

  • 博客(388)
  • 资源 (1)
  • 收藏
  • 关注

原创 Codeforces Beta Round #97 (Div. 2) (三进制)

B. Ternary Logic time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya very much likes computers. Re

2011-12-10 23:10:29 852

原创 Codeforces Beta Round #97 (Div. 2)

A. Presents time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya very much likes gifts. Recently he

2011-12-10 23:08:23 949

原创 POJ 1696 Space Ant (叉积,三点共线)

题意:有一种蚂蚁只能向左拐,求它路径最多可以经过几个点。并按经过顺序输出点的编号。 题解:可以归纳证明一定存在一条路径,使得蚂蚁可以经过所有的点。那么我们每次只需要找到一个点,使得其余所有点都在它的左方向···直到把所有n个点都找完。 #include #include #include #include #include using std::swap; using std::mem

2011-12-10 16:16:19 945

原创 POJ 1419 Intersection (判线段与矩形相交)

题意:判断线段是否与矩形相交(非规范相交)。需要注意的是,当线段在矩形内部时也算作相交。 #include #include #include #include using std::swap; #define eps 1e-8 #define zero(x) (((x)>0?(x):-(x))<eps) struct Point{double x,y;}; struct Line{P

2011-12-09 13:25:33 666

原创 POJ 1066 Treasure Hunt (线段相交)

题意: 从正方形外围任意一点出发,到达指定点最少通过几次线段?(每次只能从线段中点经过) 题解:思路一:枚举外围起点,连接该点与指定点,相交次数最少的即为答案。思路二:先求出所有线段的中点。以指定点位起点bfs,走到正方形外面的最小步数即是结果。搜索过程中,相邻点(u,v)满足条件:u,v的连线不与其他任何一条线段规范相交。 #include #include #include usin

2011-12-08 23:20:44 666

原创 Codeforces Beta Round #95 (Div. 2)

F. Present to Mom time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output How many stars are there in the sky? A yo

2011-12-06 23:07:35 578

原创 Codeforces Beta Round #95 (Div. 2)

E. Yet Another Task with Queens time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A queen is the strongest ch

2011-12-06 23:05:43 549

原创 Codeforces Beta Round #95 (Div. 2) (点双联通)

D. Subway time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A subway scheme, classic for all Berland cities i

2011-12-06 23:04:22 753

原创 Codeforces Beta Round #95 (Div. 2)

C. The World is a Theatre time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n boys and m girls atte

2011-12-06 23:02:12 662

原创 Codeforces Beta Round #95 (Div. 2)

B. Opposites Attract time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Everybody knows that opposites attract

2011-12-06 23:00:49 810

原创 Codeforces Beta Round #95 (Div. 2)

A. cAPS lOCK time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output wHAT DO WE NEED cAPS LOCK FOR? Caps lock is

2011-12-06 22:59:45 741

原创 Codeforces Beta Round #96 (Div. 2) (DP)

E. Logo Turtle time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A lot of people associate Logo programming l

2011-12-06 22:57:28 838

原创 Codeforces Beta Round #96 (Div. 2) (模拟)

D. Piet time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Piet is one of the most known visual esoteric progr

2011-12-06 22:56:05 648

原创 Codeforces Beta Round #96 (Div. 2)

C. Turing Tape time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output INTERCAL is the oldest of esoteric programmi

2011-12-06 22:53:47 862

原创 Codeforces Beta Round #96 (Div. 2) (二进制数取模)

B. Unary time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Unary is a minimalistic Brainfuck dialect in which

2011-12-06 22:52:32 1574

原创 Codeforces Beta Round #96 (Div. 2)

A. HQ9+ time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output HQ9+ is a joke programming language which has only

2011-12-06 22:49:44 735

原创 POJ 2635 Pick-up sticks (线段相交)

题意:有些人没事儿喜欢往地上任棍子,后面扔的可能盖住前面扔的,显然最后扔的那根棍子一定没被压住,求所有没有被其它棍子压住的棍子。 题解:规范相交。用链表优化下。当然也可以用队列存储下标。 #include #include using namespace std; #define eps 1e-8 #define max(x,y) ((x)>(y)?(x):(y)) #define min(

2011-12-03 22:32:38 554

原创 POJ 3487 The Stable Marriage Problem (稳定婚姻问题)

题意:http://poj.org/problem?id=3487 /*男生向女生求爱,男生最优稳定匹配*/ #include #include #include using namespace std; #define MAXN 50 int Mpref[MAXN][MAXN]; // Mpref[i][j]表示男生i第j偏爱的女生 int Wpref[MAXN][MAXN];

2011-11-30 23:30:52 1986

原创 组合数学习题(由逆序列生成排列)

/**************************************************** 采用线段树统计空格个数,从而确定某个数字应该存放在 排列中的位置,总时间复杂度为n*logn *****************************************************/ #include #include using namespace std; #de

2011-11-29 17:13:34 1763

原创 组合数学习题(Gray码生成)

习题二:生成Gray码 /************************************************* //每次调用函数取得code的下一个码(参数code为当前的gray码) void gray ( int n, int *code ) { int t = 0; for ( int i = 0; i < n; i++ ) t += code

2011-11-29 17:12:26 1291 1

原创 ZOJ 2531 Traveller (Gray码)

Traveller Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A traveller plans a round trip through n cities, where n is a power of 2, in which case we simply index them with n

2011-11-29 13:59:59 722

原创 POJ 1082 Calendar Game (博弈)

题意:甲与乙做一个游戏,给定一个1991/1/1至2001/11/4号之间的一个日期,看谁能最终到达2001/11/4。有两种移动方式,1.移动到下一天;2.移动到下一个月的同一天(若下一个月的该天不存在,则不能移动) 题解:如果一个状态的后继状态都是必胜状态,那么它是必败状态。如果一个状态的后继状态中存在必败状态,那么它是必胜状态。 PS:感觉好奇怪,递归时倘若我先处理下一天,再处理下一月,

2011-11-26 22:13:56 873

原创 POJ 1740 A New Stone Game (博弈)

题意:在一般的Nim游戏基础上,加入了一条新规则:每次都可以从所选的堆中,拿出任意个石子放到其它的任意个堆中。 题解:在一般的Nim游戏中,非平衡态->先手胜,平衡态->后手胜。对于任意两堆数量相同的石子,它们对整个局势无影响(它们的异或值等于0,或者说无论甲采取什么方案,乙都可以用对应的方案来纠正状态的变化)。 本题中,如果所有堆的数量两两相等,比如 1,1,2,2,5,5,则后手胜。 如

2011-11-25 22:33:29 701

原创 POJ 2960 S-Nim

题意:在普通的Nim游戏上加入一些限制。给定一个集合S, 每次只能取S的元素个石子。 题解:SG函数。 #include using namespace std; #define MAXN 105 #define MAXM 10005 int h[MAXN]; int s[MAXN]; int SG[MAXM]; int k; void DFS ( int x ) { if ( SG

2011-11-25 16:08:12 1400

转载 跳表

为什么选择跳表 目前经常使用的平衡数据结构有:B树,红黑树,AVL树,Splay Tree, Treep等。   想象一下,给你一张草稿纸,一只笔,一个编辑器,你能立即实现一颗红黑树,或者AVL树 出来吗? 很难吧,这需要时间,要考虑很多细节,要参考一堆算法与数据结构之类的树, 还要参考网上的代码,相当麻烦。   用跳表吧,跳表是一种随机化的数据结构,目前

2011-11-25 10:38:35 5854 3

转载 Nim取子游戏 (SG函数)

Nim游戏(转载) Nim游戏是博弈论中最经典的模型(之一?),它又有着十分简单的规则和无比优美的结论 Nim游戏是组合游戏(Combinatorial Games)的一种,准确来说,属于“Impartial Combinatorial Games”(以下简称ICG)。满足以下条件的游戏是ICG(可能不太严谨):1、有两名选手;2、两名选手交替对游戏进行移动(move),每次一步,选手可以在(

2011-11-24 23:03:30 3248

原创 POJ 1067 取石子游戏 (博弈)

取石子游戏 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25468   Accepted: 8070 Description 有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;

2011-11-24 22:17:02 745

转载 博弈

(一)巴什博弈(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。 很容易想到当n%(m+1) 这个游戏还可以有一种变相的玩法:两个人轮流报数,每次至少报一个,最多报十个,谁能报到100者胜。 (二)威佐夫博弈(Wythoff Game):有两堆各若干个物品,两个人轮流从某一堆或同时从两堆中取同样多的物品,规定每次至少

2011-11-24 21:44:02 972

原创 HDU 1231 最大连续子序列 (dp)

Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{ 11, -4, 13 },最大和 为20。 在今年的数据结构考卷中,要求编写程序得到最大和,现在增加一个要求,即还需要输

2011-11-15 22:30:41 3895

原创 POJ 2337 Catenyms (欧拉回路)

题意:给你n个单词,让每个单词的最后一个字母恰好等于下一个单词的第一个字母。构造这样一个串,使每个单词恰好被用到一次。取字典序最小的。 例如,把 aloha     arachnid    dog   gopher    rat    tiger  串成 aloha.arachnid.dog.gopher.rat.tiger。 若所个的单词不能构成这样一个串,那么输出“***”。 题解:乍一看

2011-11-13 12:25:48 1740

原创 POJ 1041 John's trip (欧拉回路)

题意:John买了新车,想开车去拜访他的朋友,已知每条街道上都恰巧有他的一个朋友,所以他想穿过每条街道一次并且回到起点。城镇上街道总数不超过1995,节点总数不超过44,任意一个节点所关联的街道总数不超过44,每一条街道所关联的两个节点都不同,每条街道的编号也不同。起点是第一次输入的两个节点中较小的那个。若存在多条回路,输出字典序最小的。 #include using namespace st

2011-11-12 18:44:04 1005

原创 POJ 2404 Jogging Trails (中国邮递员问题,状态压缩DP)

题意:Gord在为一场马拉松做准备,他家后面有一个公园,公园里有许多路径,这些路径连接了水上景点(n 题解:计算出任意两点之间的路径,统计出奇度顶点,找出这些奇度顶点的最小带权匹配(貌似计算一般图的最优带权匹配不太好弄,拆点然后用KM做是不对的)。有一个算法叫做Edmonds-Johnson算法可以解决中国邮递员问题,但是我找不到具体代码。 #include using namespa

2011-11-11 16:28:49 3111 1

原创 POJ 1556 The Doors (线段相交+Dijkstra)

题意:找从起点到终点的最短路径。 题解:可以知道,但凡两点不能直达,则一定是沿着墙边界点走的,这样才能保证路径最短。那么只需要再所有可以直达的点间连上一条边,求一次最短路径。注意判断两线段是否相交应该是判断“严格相交”,即不包含端点。 #include #include /* #include //不知道为什么加上这两句就报一些奇怪的错误···· using namespa

2011-11-06 19:56:55 822

原创 POJ 1269 Intersecting Lines (两直线之间的位置关系)

题意:判断两直线之间的位置关系,平行,重合,相交 题解:注意精度 #include #include using namespace std; #define MAX 100 #define eps 1e-8 #define zero(x) ( ((x) > 0 ? (x) : -(x)) < eps ) struct Point { double x, y; };

2011-11-06 16:45:27 471

原创 POJ 3304 Segments (直线与线段相交)

题意:给出许多线段,问能否找到一条直线,使得所有线段在它上面的投影存在交点。 题解:转自http://blog.sina.com.cn/s/blog_6635898a0100n2lv.html 1:把问题转化为是否存在一条直线与每条线段都有交点。证明:若存在一条直线l和所有线段相交,作一条直线m和l垂直,则m就是题中要求的直线,所有线段投影的一个公共点即为垂足。 2:枚举两两线段的各一个端点

2011-11-06 15:56:32 595

原创 POJ 2318 TOYS / POJ 2398 (二分,叉集)

题意:统计每个格子里面的玩具有多少。2318给出分隔板的时候是从左到右,2398的分隔板并没有排序,得自己排一下。两题就是输出有点不同,其他没什么··· POJ 2318: #include using namespace std; #define MAX 5999 struct CardBoard { int x1, y1, x2, y2; double k;

2011-11-06 08:23:02 727

原创 POJ 3737 UmBasketella(三分)

题意:给出圆锥的表面积(包含底面)。求其最大体积,以及此时的底面半径及高 #include #include using namespace std; #define eps 0.00000005 #define PI acos(-1.0) // PI用反三角函数比较准确 int main() { double s; while ( scanf("%lf",&s

2011-11-05 20:00:14 1230

原创 POJ 3301 Texas Trip (三分求极限)

题意:给出许多点的坐标,用最小的正方形覆盖之。 题解:三分。注意精度····。公式神马的画个图推一下即解决 double mid1 = (left + right)/2;              double mid2 = (mid1 + right)/2;          相比  double mid1 =left +(right - left)/3; double mid2 =

2011-11-05 18:15:00 1384

原创 POJ 1679 The Unique MST (次小生成树Prime/Kruskal)

题意:判断图中的最小生成树是否唯一。 题解:只需验是否存在两个或两个以上权值相同的最小生成树。注意:1.图中任意两点间最多只有一条无向边; 2.图可能不连通(此时mst = 0)。 Prime :复杂度 O( V ^ 2 ) #include using namespace std; #define MAX 101 #define INF 999999999 #define

2011-11-05 10:43:15 956

转载 最小生成树模版(Prime+邻接表)

最小生成树模版(Prime+邻接表) 使用优先队列+邻接表的prime算法#include #include using namespace std; typedef struct { long v; long next; long cost; }Edge; typedef struct { long v; lon

2011-11-05 08:42:08 2169

C++ STL 标准模板库

ACMer必备.内容非常详尽,不过是英文版的额。

2012-07-24

空空如也

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

TA关注的人

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