自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(40)
  • 收藏
  • 关注

原创 浅谈—中国剩余定理

首先,学这个之前,要跪舔孔子 引出例题: 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二。问物几何? 这个显然非常的神奇 说明一下 x≡2(mod 3); x≡3(mod 5); x≡2(mod 7); 我们可以写成: x=m1(mod x1) x=m2(mod x2) x=m3(mod x3) 这样的话我们就要写成一个x=(a1*m1)+(a2

2015-02-01 11:13:37 447

转载 浅谈—拓展欧几里德

最近几天都在学数论,看到一篇写的挺好的,转载一下. 学是学明白了大概意思的,细节还有点不懂 首先、扩展欧几里得定理:对于两个不全为0的整数a、b,必存在一组解x,y,使得ax+by==gcd(a,b); 实现如下: int gcd(int a,int b){ int t,d; if(b==0) { x=1;

2015-01-30 10:59:52 424

原创 浅谈—线性筛选素数

这是一个很有趣的专题,花了一个上午理解了。 很明显,就是用来筛选素数的,时间复杂度为O(n) 具体思路:       1.线性筛素数           (1)先for一遍                 (2)判断有没有被否认过是一个素数,若没有,添加一个素数                 (3)无论是不是,都for一遍,把下面的合数都筛一遍              

2015-01-29 15:29:32 355

原创 Ural 1001. Reverse Root

呵. #include #include #include #include #include #include using namespace std; long long a[1100000]; int main() { int len=0; while(scanf("%I64d",&a[++len])!=EOF); for(int i=len-1;i>=1;i--) print

2015-05-15 19:35:42 315

原创 Ural 1000. A+B Problem

哈. #include #include using namespace std; int main() { int a,b; scanf("%d%d",&a,&b); printf("%d\n",a+b); return 0; }

2015-05-15 19:15:02 314

原创 bzoj 1087 题解

状态压缩的dp Code: /************************************************************** Problem: 1087 User: wohenshuai Language: C++ Result: Accepted Time:120 ms Memory:19344 kb ******

2015-02-05 15:44:58 359

原创 bzoj 1079 题解

迭代加深搜索,加点dp的味道 状态定义有点神奇 dp[a][b][c][d][e][l]表示还剩a个1,b个2,c个3,d个4,e个5,最后一个属于什么分类来分 那么的话就从b变成a就是(b-1),(a+1) 然后用组合数学相乘即可。 今天感谢ouyangwenbin Code: /*********************************************

2015-02-04 16:37:56 399

原创 bzoj 2463 题解

不要问我为什么 Code: /************************************************************** Problem: 2463 User: wohenshuai Language: C++ Result: Accepted Time:0 ms Memory:1272 kb *********

2015-02-04 16:33:13 432

原创 bzoj 1088 题解

确定第一第二个剩下的往下推 Code: /************************************************************** Problem: 1088 User: wohenshuai Language: C++ Result: Accepted Time:20 ms Memory:1360 kb **

2015-02-04 16:31:39 315

原创 bzoj 1083 题解

最小生成树 Code: /************************************************************** Problem: 1083 User: wohenshuai Language: C++ Result: Accepted Time:32 ms Memory:1604 kb **********

2015-02-04 16:30:03 276

原创 bzoj 1047 题解

单调序列优化dp 单调队列求最大最小值…… 首先,我们用一个单调队列维护行最小值 如果发现队首的元素“过期”了,那么就把它丢掉 如果队尾元素的值小于(大于)当前的值,那么就把它丢掉 例如: 模拟操作: 1 2 3 4 5 6 7 8 9 10 11

2015-02-04 16:27:04 334

原创 bzoj 1050 题解

sort+并查集 Code: /************************************************************** Problem: 1050 User: wohenshuai Language: C++ Result: Accepted Time:912 ms Memory:1452 kb ******

2015-02-04 16:25:50 292

原创 bzoj 1054 题解

bfs Code: /************************************************************** Problem: 1054 User: wohenshuai Language: C++ Result: Accepted Time:40 ms Memory:1356 kb ************

2015-02-04 16:24:21 345

原创 bzoj 1059 题解

二分匹配图,i和j建边 Code: /************************************************************** Problem: 1059 User: wohenshuai Language: C++ Result: Accepted Time:256 ms Memory:1316 kb ***

2015-02-04 16:22:49 297

原创 bzoj 1045 题解

简单dp 首先,最终每个小朋友的糖果数量可以计算出来,等于糖果总数除以n,用ave表示。 假设标号为i的小朋友开始有Ai颗糖果,Xi表示第i个小朋友给了第i-1个小朋友Xi颗糖果,如果Xi 对于第一个小朋友,他给了第n个小朋友X1颗糖果,还剩A1-X1颗糖果;但因为第2个小朋友给了他X2颗糖果,所以最后还剩A1-X1+X2颗糖果。根据题意,最后的糖果数量等于ave,即得到了一

2015-02-04 16:17:31 458

原创 bzoj 2464 题解

spfa 相邻的构图 Code: /************************************************************** Problem: 2464 User: wohenshuai Language: C++ Result: Accepted Time:564 ms Memory:68384 kb **

2015-02-04 16:07:27 377

原创 bzoj 1085 题解

爆搜+评估函数,其实就是简单A* if(res+k-1>min(ans,15)) return ; 判断一下你有多少个不同,然后再比较步数 Code: #include #include #include #include #include using namespace std; int n,m; char str[510][510]; struct node { int x,y

2015-02-02 16:22:35 282

原创 bzoj 2464 题解

spfa不解释 Code: /************************************************************** Problem: 2464 User: wohenshuai Language: C++ Result: Accepted Time:564 ms Memory:68384 kb ******

2015-02-02 16:21:40 308

原创 bzoj 2761 题解

cgh的水题. 两次sort出结果 Code: /************************************************************** Problem: 2761 User: wohenshuai Language: C++ Result: Accepted Time:1064 ms Memory:994

2015-02-02 14:39:25 262

原创 bzoj 1053 题解

这是一道数论题 首先我们知道,一个数的因子的个数就等于每个质因数的幂+1的积 通过这个我们可以知道。 一个数满足要求,一定要质因数的次幂是按质因数的从小到大而从大到小排序的 打个比方: 54=2*3*3                12=2*2*3 因为质因数个数是一样的,所以54不合法,只能取12 这样的话,就从小到大爆搜 传进四个参数,第1个是现在枚举到第几个质数,第2个是枚

2015-02-02 14:15:16 342

原创 bzoj 1003 题解

spfa+dp 这道题题目有点别扭,不是很懂。 最后问oywb才懂。 其实是每一天都走一辆船,但后一天和前一天走的不同,那就要加上k的费用。 思路: 1.先用一个mindis[i][j]表示第i天走到第j天怎样走才是最优的。 (单一种方案来走) 2.之后用一个f数组存最优解 f[i]=min(f[i],f[j-1]+mindis[i][j]*(i-j+1)+k) 单一方案走

2015-02-02 10:32:25 402

原创 Vijos p1052 题解

高斯消元第一题,虽然坑了很多次,但是还是很好的基础题。 用double做就好了,小心高斯消元爆double类型 Code: #include #include #include #include #define LL long long #define DB double using namespace std; int n; DB a[110][110]; DB find_[110]; v

2015-01-31 10:13:58 296

原创 Poj 1061 题解

成绩出来了,看起来是挺高的,但年级排名感觉还是没升. 感觉要好好学习了. 昨天定了一个目标,有点不切实际.(hehe) 这是我学Exgcd的第一题,记得以前打过。 学回来挺简单的。 if(c%d!=0) { printf("Impossible\n"); return ; } x=x*(c/d); y=y*(c/d); LL k=a*b/d; x

2015-01-30 11:14:15 301

原创 Hdu 2098 题解

第一次学线性筛选素数,水一下 Code: #include #include #include using namespace std; int prime[11100],pr,n; bool v[11100]; void Solve() { memset(v,1,sizeof(v)); pr=0; for(int i=2;i<=10000;i++) { if(v[i]

2015-01-29 09:49:11 311

原创 Noip 2014 days1 生活大爆炸版 石头剪刀布

拼命打case就好了,没什么好说的。 Dl说这是小学生赛的题... Code: #include #include #include #include using namespace std; int n,na,nb; int a[210],b[210]; void Input() { scanf("%d%d%d",&n,&na,&nb); for(int i=0;i<na;i++)

2015-01-19 13:12:57 239

原创 Noip 2014年 提高组复赛

花了两天时间,把提高组的题都做了一下,感觉挺累的 day1:(1) 就是sb题,拼命打case即可              (2)一道稍微有点技巧的题目,每个节点找出自己周围的点的和然后等价一下即可              (3)我没敢敲,我的思路是dp每一个状态,然后顺便记录最大值即可,可以用滚动数组优化,时间复杂度到O(nm) 刚好能过 day2:(1)dp扫一下+预处理即可

2015-01-19 13:09:15 382

原创 Hdu 2196 题解

用了两种做法, 一种是每一个节点做根来扫 果断O(n(n+m)) 显然不行 另一种是1做根,判断每种情况 把另外一个孩子节点的最大值和连上去的值加起来做treedp即可 时间复杂度O(n+m) Code: #include #include #include #define max(x,y) (x)>(y)?(x):(y) using namespace std; int n; str

2015-01-14 13:59:23 367

原创 Hdu 1520 题解

简单树形dp f[x][1]+=f[y][0]; f[x][0]+=max(f[y][0],f[y][1]); 最后加上自己的权值即可。 Code: #include #include #include using namespace std; struct node { int x,y,next; }a[1110000]; int first[110000],len; int dp

2015-01-13 12:51:09 264

原创 Poj 1273 题解

模板题,dinic网络流,直接上代码。 Just prepare for the exam。 记得数组开大,多组数据。 Code: #include #include #include #include using namespace std; struct node { int x,y,c,next,other; }a[6110000]; int len,first[1110000]

2015-01-10 13:56:16 277

原创 Poj 1579 题解

记忆性搜索,注意判断数组的边界 #include #include #include #include using namespace std; int f[30][30][30],a,b,c; int ans; int dfs(int x,int y,int z) { if(x<=0||y<=0||z<=0) return f[0][0][0]=1; else if(x>20||y>2

2015-01-09 13:42:53 265

原创 Poj 1458 题解

简单的二维一边推 Code: #include #include #include #include #include using namespace std; char st1[1100],st2[1100]; int f[1100][1100]; void Solve() { memset(f,0,sizeof(f)); for(int i=1;i<=strlen(st1+1);i

2015-01-09 13:22:31 276

原创 Poj 1170 题解

本来想用5个数表达一个状态的。 但是先起来麻烦。 结果用5维数组做咯。 离散化了。 还是一次ac Code: #include #include #include #include #include using namespace std; struct node { int p[6]; int val; }a[1100]; int ls=0,len=0; mapmp; int

2015-01-08 13:42:57 323

原创 Poj 1163 题解

打完后编译都没编译直接acv. Code: #include #include #include #include using namespace std; int a[1100][1100],n; int f[1100][1100]; void Input() { scanf("%d",&n); for(int i=1;i<=n;i++) { for(int j=1;j<

2015-01-08 12:53:53 318

原创 Poj 1157 题解

一开始看错了题意。 记得个前面留够位置和后面留够位置就好了。 还有f别忘了清空为-99999 Code: #include #include #include #include using namespace std; int f[110][110]; int a[110][110]; int n,m; void Input() { scanf("%d%d",&n,&m); for

2015-01-07 13:55:25 355

原创 比赛-2015.01.03

又是一次gdkoi的学校选拔的比赛。 伤心透了。 满分:400   分数:132 题目如下: 中位数 【题目描述】    给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b。中位数是指把所有元素从小到大排列后,位于中间的数。 【输入格式】 第一行为两个正整数n和b ,第二行为1~n 的排列。 【输出格式】 输出一个整数,即中位数为b的连续子序列个数

2015-01-06 13:39:42 453

原创 Poj 1088 题解

水题dp,其实就是记忆化搜索 #include #include #include #include using namespace std; int f[110][110]; int a[110][110],n,m; void Input() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) s

2015-01-01 00:56:19 282

原创 Poj 1050 题解

最大子矩阵和。 O(n^3) 不做太多诠释了。直接上代码,不懂评论即可。 今天尽量多刷点题 #include #include #include using namespace std; int a[110][110],n; int f[110][110]; void Input() { scanf("%d",&n); for(int i=1;i<=n;i++) for(in

2014-12-31 13:42:20 582

原创 Poj 1036 题解

一道dp题。 一开始看起来蒙了,但是其实很简单。 他的门是可以不动的。 也就是说你这个小偷到上一个小偷的这段时间如果大于两者fat的差的话绝对值就必定满足。 之后就是dp了 你每一个小偷都继承这上一个来枚举即可,f[i]表示第i个小偷能偷到的荣誉。 其实就是继承的时候判断一下继承的上一个是否合法即可 Code: #include #include #include #include

2014-12-30 13:50:26 374

原创 Poj 1018 题解

这是一道简单的dp题。 首先想想,b/p最大,就是想让b最大,p最小。 状态定义f[i][j]=前i行最小最小值为j的最小价值p,这样用b/p才最大,最后一个个枚举。(自然保证最大) 为什么一个个枚举可以呢 其实联系一下p想想就好了。 对了,还有的就是用c++ 提交 Code: #include #include #include using nam

2014-12-29 13:57:27 412

原创 Poj 1014 题解

第一次发poj,原百度空间已经放弃了。 还是贴个网址吧,容易找一点。 http://hi.baidu.com/scqmysgfqrajrtr 一道多重背包的题。 一开始直接背包 Code: #include #include #include #include using namespace std; int a[7];int t=0; bool v[21000]; void

2014-12-28 15:49:55 331

空空如也

空空如也

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

TA关注的人

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