
数学算法
winycg
问题可联系QQ:1241981936
展开
-
hdu 1846 巴什博奕
各位勇敢者要玩的第一个游戏是什么呢?很简单,它是这样定义的:1、 本游戏是一个二人游戏;2、 有一堆石子一共有n个;3、 两人轮流进行;4、 每走一步可以取走1…m个石子;5、 最先取光石子的一方为胜;如果游戏的双方使用的都是最优策略,请输出哪个人能赢。Input输入数据首先包含一个正整数C(C每组测试数据占一行,包含两个整数n和m(1原创 2016-03-28 20:12:33 · 446 阅读 · 0 评论 -
hdu 1907 尼姆博弈变形 最后取得人为输
Problem DescriptionLittle John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to eat several M&Ms of the same color原创 2016-03-28 21:04:45 · 611 阅读 · 0 评论 -
尼姆博弈问题+sg函数
具体的sg函数见链接:点击打开链接sg函数模板int f[105],sg[1005];//f[]为所要拿取的球数int sg_dfs(int x){ if(sg[x]!=-1) return sg[x]; bool visited[1005];//必须在函数里面定义,在全局定义会出错 memset(visited,0,si原创 2016-04-05 23:45:08 · 1197 阅读 · 0 评论 -
poj Georgia and Bob + 蓝桥杯决赛原题:高僧斗法 阶梯博弈大法
Language:DefaultGeorgia and BobTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 8812 Accepted: 2832DescriptionGeorgia and Bob decide to play a self原创 2016-04-06 20:45:30 · 1491 阅读 · 2 评论 -
hdu 2516 (斐波那契数列)
Problem Description1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍。取完者胜.先取者负输出"Second win".先取者胜输出"First win". Input输入有多组.每组第1行是2 Output先取者负输出"Second win".原创 2016-05-23 22:51:33 · 481 阅读 · 0 评论 -
异或的应用及性质
异或是一种基于二进制的位运算,用符号XOR或者 ^ 表示,其运算法则是对运算符两侧数的每一个二进制位,同值取0,异值取1。它与布尔运算的区别在于,当运算符两侧均为1时,布尔运算的结果为1,异或运算的结果为0。1、交换律 :a^b=b^a2、结合律:(a^b)^c == a^(b^c)3、对于任何数x,都有x^x=0,x^0=x4、自反性 A ^ B ^ B转载 2016-09-20 23:50:01 · 580 阅读 · 0 评论 -
第7届山东省赛sdut 3566---Triple Nim
Problem DescriptionAlice and Bob are always playing all kinds of Nim games and Alice always goes first. Here is the rule of Nim game: There are some distinct heaps of stones. On each turn, tw原创 2016-10-07 17:21:42 · 599 阅读 · 0 评论 -
sdut 2878 Circle (求期望+高斯消元求解)
题目描述You have been given a circle from 0 to n - 1. If you are currently at x, you will move to (x - 1) mod n or (x + 1) mod n with equal probability. Now we want to know the expected number of steps原创 2016-05-20 22:24:42 · 620 阅读 · 0 评论 -
染色问题(n个格子,3种颜色)
有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法.递推公式:A1 = 3A2 = 6 //A(3,2)=6A3 = 6 //A(3,3)=6An=2*A(n-2)+A(n-1), n>=4证明:考虑第n-1个格子:1. 如果这个格子原创 2016-05-23 16:25:21 · 8667 阅读 · 0 评论 -
UVA 11722 概率几何
题意很简单,就是高中概率几何最基础的问题:两个人分别等可能在[t1,t2]和[s1,s2]出现,若一个人等待超过w分钟,则两人无法相遇,求相遇概率。设人分别为x,y,满足t1s1|x-y|求上式所包围的面积即可本题的难度在于求解各种情况,如图6种情况#include#include#include#include#include#include原创 2017-04-20 00:19:25 · 502 阅读 · 0 评论 -
UVA 11021 全概率公式+递推的使用
题意:K只麻球,每只麻球活一天就会死,临死之前可能会生出新的麻球,生i个麻球的概率为p(i),求m天后麻球都死亡的概率每只麻球相互独立,设一只麻球及其后代在m天后死亡的概率为f(m)最终答案为:#include#include#include#include#include#include#include#include#include#def原创 2017-04-20 15:21:24 · 692 阅读 · 0 评论 -
UVA 11762 概率dp+期望
题意:一个人每天玩游戏,玩一局胜利的概率为p,一天最多玩n次,如果当天某时刻胜率大于p则结束,第二天继续玩,如果某天玩了n次胜率还是不大于p,则失败不再玩,求玩的天数的期望蓝皮书134页设d[i][j]表示前i局获胜了j局的概率d[i][j]=d[i-1][j]*(1-p)+d[i-1][j-1]*p (j/ielse d[i][j]=0 //d[i]原创 2017-04-21 21:54:01 · 359 阅读 · 0 评论 -
ZOJ 3593.One Person Game 扩展欧几里得+逼近
DescriptionThere is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point A at first and your aim is point B. There are 6 kinds of operations原创 2016-04-12 21:00:01 · 449 阅读 · 0 评论 -
威佐夫博弈
威佐夫博弈一共有2堆石子,每堆石子个数也是任意的,双方轮流从中取出石子1.每次有2种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。2.最后把石子全部取完者为胜者Answer为1表示赢,0表示输,a,b为2堆石子的数量 if (a > b) swap(a, b); int c = b -原创 2016-03-27 22:51:18 · 386 阅读 · 0 评论 -
尼姆博弈 Match Games
DescriptionHere is a simple game. In this game, there are several piles of matches and two players. The two player play in turn. In each turn, one can choose a pile and take away arbitrary number原创 2016-03-27 22:20:27 · 538 阅读 · 0 评论 -
fzu 2213 通过圆心坐标和半径判断两圆的关系
Two different circles can have at most four common tangents.The picture below is an illustration of two circles with four common tangents.Now given the center and radius of two circles, yo原创 2017-04-17 23:40:45 · 1622 阅读 · 0 评论 -
二维凸包
二维凸包模板p[1010]//输入的点集,res[1010]//输出的点集int n;//点的个数int cmp(Point a,Point b)//先对x坐标排序,在比较y坐标{ if(a.x==b.x) return a.y<b.y; return a.x<b.x;}int ConvexHull()//返回凸包顶点数{ sort(p,p+原创 2016-05-06 23:30:10 · 2154 阅读 · 0 评论 -
poj 1654 在方格中求多边形的面积
DescriptionYou are going to compute the area of a special kind of polygon. One vertex of the polygon is the origin of the orthogonal coordinate system. From this vertex, you may go step by step原创 2016-05-07 19:34:08 · 798 阅读 · 0 评论 -
poj 2318 叉积的应用+二分
DescriptionCalculate the number of toys that land in each bin of a partitioned toy box.Mom and dad have a problem - their child John never puts his toys away when he is finished playing with t原创 2016-05-07 23:55:53 · 2718 阅读 · 0 评论 -
半平面交 poj 3335(判断是否有内核) poj 3525 (半平面交+二分)
poj 3335DescriptionThis year, ACM/ICPC World finals will be held in a hall in form of a simple polygon. The coaches and spectators are seated along the edges of the polygon. We want to p原创 2016-05-13 20:18:26 · 512 阅读 · 0 评论 -
hdu 5858 正方形和内切圆的几何问题
Problem Descriptioncjj is fun with math problem. One day he found a Olympic Mathematics problem for primary school students. It is too difficult for cjj. Can you solve it?Give you the side l原创 2016-08-21 23:01:48 · 786 阅读 · 0 评论 -
fzu 2231 根据坐标面上的点找平行四边形个数
Problem Description在一个平面内给定n个点,任意三个点不在同一条直线上,用这些点可以构成多少个平行四边形?一个点可以同时属于多个平行四边形。 Input多组数据(每组数据第一行一个整数n(4 Output每组数据输出一个整数,表示用这些点能构成多少个平行四边形。 Sample Input40 11 01 12 0 S原创 2016-09-07 21:06:41 · 1473 阅读 · 0 评论 -
sdut 2603 向量的旋转变换与旋转角的关系(山东第4届省赛)
Problem Description Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess set out immedia原创 2017-04-18 14:31:59 · 438 阅读 · 0 评论 -
CodeForces - 801D 凸多边形的性质
You are given a convex polygon P with n distinct verticesp1, p2, ..., pn. Vertexpi has coordinates(xi, yi) in the 2D plane. These vertices are listed in clockwise order.You can choose a real原创 2017-04-23 22:45:27 · 807 阅读 · 0 评论 -
仿射变换
仿射变换包括常见的平移,缩放和旋转等。对于二维向量,可用变换矩阵代表旋转和缩放,不能表示平移所谓齐次坐标就是将一个原本是n维的向量用一个n+1维向量来表示。如向量(x1,x2,…,xn)的齐次坐标表示为(hx1,hx2,…hxn,h),其中h是一个实数。显然一个向量的齐次表示是不唯一的,齐次坐标的h取不同的值都表示的是同一个点,比如齐次坐标[8,4,4]、[4,2,2]表示的都是二原创 2017-04-25 23:59:58 · 1039 阅读 · 0 评论 -
母函数
母函数又称生成函数。定义是给出序列:a0,a1,a2,.......ak,......,那么函数G(x)=a0+a1*x+a2*x2+......ak*xk称为序列a0,a1,a2,.......ak,......的母函数(即生成函数)。题1:若有1克、2克、3克、4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案?构造母函数,如果用x的指数表示称出的重量,则:1个1克的砝码可原创 2016-08-24 16:27:55 · 421 阅读 · 0 评论 -
第一类、第二类Stirling数和Bell数
第一类Stirling数(斯特林数)定义:s(n,k)的一个的组合学解释是:将n个物体排成k个非空循环排列(非空的)的方法数。S(p, k)的递推公式:S(n, k)= (n - 1) * S(n- 1, k) + S(n - 1, k - 1). 边界条件:S(n, 0) = 0, n >= 1. S(n, n) = 1, n>原创 2017-04-18 23:41:39 · 5587 阅读 · 0 评论 -
2012蓝桥杯 取球博弈 基础博弈论
取球博弈今盒子里有n个小球,A、B两人轮流从盒中取球,每个人都可以看到另一个人取了多少个,也可以看到盒中还剩下多少个,并且两人都很聪明,不会做出错误的判断。我们约定:每个人从盒子中取出的球的数目必须是:1,3,7或者8个。轮到某一方取球时不能弃权!A先取球,然后双方交替取球,直到取完。被迫拿到最后一个球的一方为负方(输方)请编程确定出在双方都不判断失误的情况下,对于特定原创 2016-03-19 19:01:55 · 1907 阅读 · 0 评论 -
hdu1576 A/B 扩展欧几里德算法
Problem Description要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。Input数据的第一行是一个T,表示有T组数据。每组数据有两个数n(0 Output对应每组数据输出(A/B)%9973。Sample InputSample O原创 2016-03-05 23:05:17 · 485 阅读 · 0 评论 -
山东省浪潮杯 SDUT3260大整数取模
同余定理:(a+b)% c = (a%c+ b%c)%c(a-b)%c=(a%c-b%c+c)%c;(a*b)%c = ( a%c* b%c)%c 大整数取模运算:1234=((1*10+2)*10+3)*10+4;Association for Couples Math (ACM) is a non-profit organization which is原创 2016-03-10 19:36:12 · 454 阅读 · 0 评论 -
poj 1006 中国剩余定理
题意:人自出生起就有体力,情感和智力三个生理周期,分别为23,28和33天。一个周期内有一天为峰值,在这一 天,人在对应的方面(体力,情感或智力)表现最好。通常这三个周期的峰值不会是同一天。现在给出三个日 期,分别对应于体力,情感,智力出现峰值的日期。然后再给出一个起始日期,要求从这一天开始,算出最少 再过多少天后三个峰值同时出现。 #i原创 2016-03-29 20:27:46 · 360 阅读 · 0 评论 -
hdu 1796 容斥原理
Problem DescriptionNow you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example,原创 2016-04-21 19:59:15 · 519 阅读 · 0 评论 -
hdu 2552 三角函数数学公式使用
MCA山中人才辈出,洞悉外界战火纷纷,山中各路豪杰决定出山拯救百姓于水火,曾以题数扫全场的威士忌,曾经高数九十九的天外来客,曾以一剑铸十年的亦纷菲,歃血为盟,盘踞全国各个要塞(简称全国赛)遇敌杀敌,遇佛杀佛,终于击退辽军,暂时平定外患,三人位置也处于稳态。可惜辽誓不甘心,辽国征南大将军欲找出三人所在逐个击破,现在他发现威士忌的位置s,天外来客的位置u,不过很难探查到亦纷菲v所在何处,只原创 2017-02-28 20:18:41 · 534 阅读 · 0 评论 -
poj 1328 区间,贪心
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the原创 2017-02-05 19:31:00 · 327 阅读 · 0 评论 -
hdu 4565 矩阵快速幂+共轭的应用
Description A sequence S n is defined as: Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate S n. You, a top coder, say: So easy!原创 2016-11-07 18:49:57 · 547 阅读 · 0 评论 -
最长非递减子序列的应用
Description我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增。其中无论是修改前还是修改后,每个元素都必须是整数。 请输出最少需要修改多少个元素。Input第一行输入一个$T (1 \leq T \leq 10)$,表示有多少组数据 每一组数据: 第一行输入一个$N (1 \leq N \leq原创 2016-08-22 22:40:36 · 1453 阅读 · 0 评论 -
hdu 1005 找规律(好坑!!)
Problem DescriptionA number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n).原创 2016-08-12 17:14:11 · 406 阅读 · 0 评论 -
hdu 4793
DescriptionThere's a round medal fixed on an ideal smooth table, Fancy is trying to throw some coins and make them slip towards the medal to collide. There's also a round range which shares exact原创 2016-08-11 21:52:00 · 728 阅读 · 0 评论 -
常用数学函数
math.h 数学函数库,一些数学计算的公式的具体实现是放在math.h里,具体有: 1 三角函数 double sin (double); double cos (double); double tan (double); 2 反三角函数 double asin (double); 结果介于[-PI/2, PI/2] double acos (double); 结果介原创 2016-05-23 18:27:56 · 345 阅读 · 0 评论 -
区间相关问题解法
给定若干个区间,将它们合并之后的长度为多少,区间个数为n,(0Input31 52 43 3Output4#include#include#include#include#include#include#includeusing namespace std;struct node{ long long a;原创 2016-03-27 19:30:40 · 659 阅读 · 0 评论