自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

sepNINE的专栏

As brief as possible

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

原创 poj 3134 Power Calculus iddfs(迭代深搜)

iddfs入门题。//poj 3134//sep9#include using namespace std;int n,deep;int a[30];bool iddfs(int pos){ int t; if(pos>deep) return false; if(a[pos]<<(deep-pos)<n) return false; if(a[pos]==n) ret

2015-04-29 11:09:07 1538

原创 poj 3435 检测数独状态是否合法

题意:给一个数独的状态,判断它是否合法。分析:水,直接判断。代码://poj 3435//sep9#include using namespace std;const int maxN=10;const int MAX=maxN*maxN+10;int a[MAX][MAX];int col_check[MAX][MAX];int row_check[MAX][

2015-04-27 20:49:34 1229

原创 poj 3076 Sudoku dlx解数独

16*16的数独,类似poj 3074.//poj 3076//sep9#include #include #define INT_MAX 2147483647using namespace std;const int col_num=16*16*4;const int row_num=16*16*16+10; const int head=0;const int MAX

2015-04-27 19:46:55 878

原创 poj 3074 Sudoku dlx解数独

分析:dlx是从数据结构角度优化01矩阵精确覆盖和重复覆盖的数据结构,它用十字链表只存贮矩阵中的非0元,而01矩阵精确覆盖dfs过程中矩阵会越来越稀疏而且每次恢复现场会浪费大量时间,dlx恰好能解决这两个问题。本题关键是将数独问题转化为01矩阵精确覆盖。数独转化为精确覆盖问题的方法还是参照Knuth的论文,如果读取到一个格子是空的,那么加9行,分别表示这个格子填1到9这9个数字,如果读取到的格

2015-04-27 15:25:32 1472

原创 poj 3744 Scout YYF I 概率dp+矩阵乘法

分析:dis(k,v1,v2)函数求到当前位置概率为v1,到当前位置之前一步的概率为v2,前进k步到达位置的概率,然后矩阵加速。代码://poj 3744//sep9#include #include using namespace std;int pos[12];double p,mat[4][4];double ans[4][4];void mul1(){ d

2015-04-24 23:41:02 839

原创 poj 3580 SuperMemo splay树模板题

splay树 模板题

2015-04-24 01:07:25 1188

原创 poj 2537 Tight words 概率dp

分析:用计数dp思想:DP[I][J]=(DP[I-1][J-1]+DP[I-1][J]+DP[I-1][J+1]),最后再除pow(k+1,n)容易爆精度,改用概率dp思想DP[I][J]=(DP[I-1][J-1]+DP[I-1][J]+DP[I-1][J+1])/(k+1)即可。代码://poj 2537//sep9#includeusing namespace std;

2015-04-23 18:00:52 1113

原创 poj 2425 A Chess Game grundy值

题意:给一个拓扑图,在一些点上有棋子,两个玩家每次轮流将一颗棋子沿有向边移动一次,无法移动则失败。分析:理解nim和状态的grundy值两下就敲出来了。代码://poj 2425//sep9#include #include using namespace std;const int maxN=1024;vector g[maxN];int vis[maxN];

2015-04-22 23:23:29 779

原创 poj 2497 Strategies 模拟水题

水题,直接贴代码。//poj 2497//sep9#include #include using namespace std;int a[32];int main(){ int cases,c=0; scanf("%d",&cases); while(cases--){ int tot,n; scanf("%d%d",&tot,&n); int x2,y2,t

2015-04-21 19:06:22 813

原创 poj 3046 Ant Counting 多项式乘法解可重组合数

题意:裸的求可重组合数。分析:多项式乘法求系数的应用啊,不用dp。代码://poj 3046//sep9#include using namespace std;const int maxN=1024;const int maxL=100024;const int mod=1000000;int num[maxN];int coef[maxL];int tm

2015-04-20 20:01:18 889

原创 poj 2391 Ombrophobic Bovines 二分+最大流

同poj 2112.代码://poj 2391//sep9#include #include #include using namespace std;typedef long long ll;const int maxN=1024;const int maxM=100002;const ll MAX=(1ULL<<63)-1; struct Edge{ int

2015-04-20 11:51:03 756

原创 poj 2125 Destroying The Graph 最小点权覆盖

题意:求一个图的最小点权覆盖。分析:拆点转化为求最小割。代码://poj 2125//sep9#include #include #include using namespace std;const int maxN=300;const int maxM=100002;struct Edge{ int v,f,nxt;}e[maxM*2+10];que

2015-04-18 23:30:37 942

原创 poj 2112 Optimal Milking 二分+最大流

根据这题可以总结出处理网络流问题中需要“跳过”某一节点的办法(跳过是指需要占用经过某一节点但又不占用其流量):1.floyd求全局最优路径建图前直接跳过。2.拆点成A-A1,A-A1是经过该点的实际流量,并由A1流出相同的流量。+oo流进A,A->B1走需要跳过的流量。代码://poj 2112//sep9#include #include #include using name

2015-04-18 15:09:10 782

原创 poj 2949 Word Rings 参数搜索+负环探测

类似poj 3621。代码://poj 2949//sep9#include #include #include #include #include using namespace std;const int maxL=1024;const int maxM=100100;char s[maxL];struct Words{ int in,out,len;}w

2015-04-18 00:41:15 1000

原创 poj 1275 Cashier Employment 差分约束

差分约束模板题,差分约束是判断联立不等式组是否有解的一种方法,建图是关键。代码://poj 1275//sep9#include #include using namespace std;const int maxM=10024;const int maxN=32;struct Edge{ int v,w,nxt; }edge[maxM];int t[maxN],c

2015-04-17 21:40:19 705

原创 poj 3621 Sightseeing Cows 负环探测解参数搜索

题意:有向图中每个点有一个欢乐值,边有边权,要求一条环路,使环路上欢乐值得和/路径和最大。分析:二分参数,判断是否存在负权,这里判负圈没用spfa,用的是一种效率很高的方法。代码://poj 3621//sep9#include #include using namespace std;const int maxN=1024;const int maxM=5012;

2015-04-17 01:50:02 635

原创 poj 2728 Desert King 参数搜索解最优比例生成树

题意:图中每条边有两个权值(cost,len),求其一棵生成树,使sum(cost)/sum(len)最小。分析:转化为求边权为s0*len-cost的最大生成树+牛顿迭代。s0为具有单调性迭代系数。代码://poj 2728//sep9#include #include #include using namespace std;const int maxN=102

2015-04-16 23:48:12 755

原创 poj 3111 K Best 参数搜索之牛顿迭代法

题意:给n个元素,每个元素有两个属性(v,w),现在要从中选k个,使sum(v)/sum(k)最大。分析:参数搜索的入门题,牛顿迭代比二分快很多。代码://poj 3111//sep9#include #include #include using namespace std;const int maxN=100024;int n,k;double s0,s1;

2015-04-16 21:28:27 890

原创 poj 2886 Who Gets the Most Candies? 线段树动态求第k大的数

题意:n个小孩站一圈,每个小孩拿一个数字,从第k个孩子开始出局,然后下一个出局的孩子是刚刚出局的孩子之前或之后第v个(刚刚出局的孩子的数字是+v则之后v个,-v则之前v个),这样所有孩子终将出局,第p个出局的孩子得f(p)分,f(p)定义为p的因子个数。求分数最高的孩子。分析:设顺时针为正方向,关键是模拟出每次出局的孩子是剩下的孩子中的正方向的第几个,设当前要出局的是第k个,然后要求出

2015-04-15 23:49:45 584

原创 poj 2191 Mersenne Composite Numbers 大数分解

题意:给k,求i是素数且在1~k内并且2^i-1是合数的情况,并将它分解。分析:枚举1至i然后用miller_rabin素数判定和pollard_rho因数分解即可。代码://poj 2191//sep9#include #include #include #define gcc 10007#define max_prime 200000using namespa

2015-04-15 21:28:33 674

原创 poj 2417 Discrete Logging 数论baby_step,giant_step算法

题意:给p,b,n求最小的l使b^l==n(mod p)。题意:相当于在0~p-1内搜索l满足同余式,baby_step,giant_step相当于分块的二分搜索,设m=sqrt(p), 则将p分为m*m,在m块内每块进行m个数的二分搜索。代码://poj 2417//sep9#include #include #include using namespace std;

2015-04-15 15:27:10 885

原创 poj 1284 Primitive Roots 求素数元根数

题意:给奇素数p,求p有多少原根。分析:phi(p-1),数论有具体证明。代码://poj 1284#include using namespace std;int main(){ int n; while(scanf("%d",&n)==1){ --n; int ans=n; for(int i=2;i*i<=n;++i) if(n%i==0)

2015-04-15 01:02:41 1160

原创 poj 2429 GCD & LCM Inverse miller_rabin素数判定和pollard_rho因数分解

题意:给gcd(a,b)和lcm(a,b),求a+b最小的a和b。分析:miller_rabin素数判定要用费马小定理和二次探测定理。pollard_rho因数分解算法导论上讲的又全又好,网上的资料大多讲不清楚。代码://poj 2429//sep9#include #include #include #define gcc 10007#define max_prime

2015-04-14 01:27:11 835

原创 poj 3480 John anti-SG博弈

题意:跟经典的nim除了胜利条件不一样(nim当游戏者面对空的决策集判负,anti-SG当游戏者面对空的决策集判负),其他都一样。分析:设全局状态为s,单个游戏为t。先手必胜条件:(g(s)!=0&&Existg(t)>1)||(g(s)==0&&Anyg(t)代码://poj 3480//sep9#include using namespace std;int ma

2015-04-09 19:11:44 698

原创 poj 2282 The Counting Problem 按位统计

同poj3286//poj 2282//sep9#includeusing namespace std;typedef __int64 ll;ll b[16];ll f(ll n,ll x){ ll left,m,ans=0; for(ll i=1;i<13;++i){ left=n/b[i]-(x==0); ans+=left*b[i-1]; m=(n%b[i

2015-04-09 00:50:57 572

原创 poj 3286 How many 0's? 按位统计

题意:给m分析:按位算当某位是0时左边有多少种情况,右边有多少种情况,注意左边的情况数为-1时(这时遍历到最高位)是为了把右边多加的情况减去,也就是把0作为开头时的情况减去。代码://poj 3286//sep9#includeusing namespace std;typedef __int64 ll;ll b[16];ll f(ll n){ ll left

2015-04-09 00:41:13 961

原创 poj 3422 Kaka's Matrix Travels 费用流

题意:给一个n*n的矩阵,每次从左上角走到右下角并取走其中的数,求走k次能取到的最大和。分析:费用流边的容量有限制的作用,费用有求和的作用,对于每个点只能取一次,容易想到把这个点拆成两个点并连上容量为1,费用为该点数的边。但明显有的流要“跳过”这个点,如何处理呢?可以加一条容量为无穷,费用为0的边,这样不参加这点费用计算的流就可以"跳过"这个点了。代码://poj 3422/

2015-04-08 16:07:44 605

原创 poj 3587 The Biggest Cake 正弦定理

题意:给n个点,求其中3个点构成三角形的最大外接圆半径。分析:正弦定理,A/sina=B/sinb=C/sinc=ABC/(2*s)=2*R。代码://poj 3587//sep9#include #include using namespace std;const int maxN=700;double dis[maxN][maxN];double x[maxN

2015-04-08 12:11:51 1158 6

原创 poj 3425 Customer support 模拟

模拟水题。代码://poj 3425//sep9#include using namespace std;const int maxN=1000024;int vis[maxN];int main(){ int n; memset(vis,0,sizeof(vis)); int q,a,x,sum=0,correct_num=0; scanf("%d",&n);

2015-04-08 11:07:25 682

原创 poj 4022 ASCII Area dfs求二维面积

题意:给一个有'/','\','.'组成的二维字符数组,求图中‘/’和‘\’组成的面积有多大。分析:每个‘/’和‘\’的格每个贡献1/2的面积,每个多边形内部的'.'贡献1的面积,关键是求多边形内部的’.‘有多少个。一开始往上下左右4个方向搜wa了,原来内部的点可以斜着扩展,比如/./这种情况。但斜着搜要注意避免从多边形内部跑到外部的情况,比如题目中给的sample。 代码:/

2015-04-07 23:20:10 580

原创 poj 3895 Cycles of Lanes 修改tarjan算法求图中最大环

修改tarjan算法求图中最大环

2015-04-07 11:58:06 1862

原创 poj 3014 Cake Pieces and Plates 整数拆分

题意:将m拆成n个数,允许某个数为0,求拆分方案数。分析:裸的整数拆分,设h(m,n)表示将m拆成n个数,允许某数为0的方案数,递推方程见代码。很有意思的是,参考上一篇写poj1221的博文中,设f(m,n)表示将m进行任意份数不允许有0的整数拆分,且最大元素小于等于m的方案数,则h(m,n)==f(m,n)。。。。求解此等式意义。。。代码://poj 3014//sep9

2015-04-06 21:18:06 830

原创 poj 1221 UNIMODAL PALINDROMIC DECOMPOSITIONS 整数拆分

题意:给一个数n,求有多少种和为n的单峰先增序列,比如当n=5时结果为3:(5), (1 3 1), (1 1 1 1 1)。分析:转化为求类似整数拆分问题,f(i,j)的意义是把i进行拆分,最大数小于等于j的方法数。代码://poj 1221//sep9#include using namespace std;const int maxN=300;__int64 a

2015-04-06 20:23:47 980

原创 poj 3881 区间交判断

水题,直接贴代码。//poj 3881//sep9#include using namespace std;const int maxN=10024;int n,m;int a[maxN],b[maxN];bool judge(int x,int y,int i){ if(b[i]<=x||y<=a[i]) return false; return true;}

2015-04-04 00:47:12 857

原创 poj 3970 Party 最小公倍数

题意:给n个数,求它们的最小公倍数。分析:lcm(a,b)==a*b/gcd(a,b);代码://poj 3970//sep9#include using namespace std;typedef long long ll;ll gcd(ll a,ll b){ return a%b==0?b:gcd(b,a%b);}int main(){ int n;

2015-04-03 22:52:21 1279

原创 poj 3940 Grey Area 浮点输出控制

水题,直接贴代码,注意几种控制浮点输出的方法:e格式,以指数形式输出实数。g格式:自动选f格式或e格式中较短的一种输出,且不输出无意义的零。代码://poj 3940//sep9#include using namespace std;const int maxL=64;int cnt[maxL+10];double color[maxL];double area[maxL]

2015-04-03 16:25:19 801

原创 poj 3911 Internet Service Providers 解一元二次方程

少有人做的水题,直接贴代码。//poj 3911//sep9#include using namespace std;typedef long long ll; int main(){ ll n,c; while(scanf("%lld%lld",&n,&c)==2){ if(n==0){ printf("0\n"); continue; } ll

2015-04-03 01:08:44 1127

原创 poj 2455 Secret Milking Machine 二分+最大流

题意:给一图,求从点1到n的t条边不相交的路径,目标是最小化最t条路径中的最大边,输出该最大边。分析:求最值的问题满足单调性都可以用二分来做,二分是加速的枚举方法。这题二分枚举最大边建图,每次用长度小于等于二分值的边建图并置容量为1,求最大流即可。代码://poj 2455//sep9#include #include #include using namespace

2015-04-02 20:26:32 751

原创 poj 3228 Gold Transportation 并查集

题意:有n和城市和m条路,每个城市都有产生金量和收集金量,现在要把所有黄金收集,求经过的最短边是多少。分析:二分+最大流或用并查集合并等价类。//poj 3228//sep9#include #include using namespace std;const int maxN=256;const int maxM=10024;int p[maxN],sum[maxN

2015-04-02 11:06:28 965

原创 poj 3907 Build Your Home 多边形面积

题意:给一个多边形,求它的面积。分析:算一遍叉积即可。代码://poj 3907//sep9#include #include using namespace std;int main(){ float x0,y0,x1,y1; short n; while(scanf("%hd",&n)==1&&n){ float sum=0; scanf("%f%

2015-04-01 21:15:28 836

空空如也

空空如也

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

TA关注的人

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