自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 蓝桥杯 买不到的数目

动态规划,当可以被凑出来的数的连续个数等于最小的那个a时,之后所有的数都可以被凑出。与凑包子那题一样。#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int ans[100000];int a,b;int ...

2018-03-31 21:16:01 462 2

原创 蓝桥杯 剪格子

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int ans[15][15];int ok[15][15];int Min=100000;int Count=0;int n,m;int sum=0;...

2018-03-31 20:42:52 116

原创 欧几里得算法求最大公约数和最小公倍数

求多个最大公约数 直接叠加即可比如求三个数的最大公约数,先把前两个数的最大公约数求出来,再把这个数与第三个数求最大公约数。多个数同理。两个数的乘积等于这两个数的最大公约数和最小公倍数的成绩,所以最大公倍数直接拿两个数乘积除以最小公约数就好了。多个数同理。#include<iostream>#include<cstdio>int gcd(int a,int b)//欧几里...

2018-03-31 19:58:18 456

原创 17蓝桥杯 方格分割

这题搜边更好做,从4,4点开始搜,每走一步中心对称的那个也标记走过,直到走到边界,最后结果除以4#include<iostream>#include<cstdio>#include<cstring> int ans[10][10];int Count=0;void dfs(int x,int y){ ans[x][y]=1;//标记已走 ans[...

2018-03-31 17:52:59 157

原创 17蓝桥杯 迷宫

直接dfs,走到边界就+1把字母转换为数字 输入方便#include<iostream>#include<cstdio>#include<cstring>using namespace std;int ans[20][20];int ok[20][20];int Count=0;void dfs(int x,int y){ ok[x][y]=0...

2018-03-31 15:30:36 183

原创 16蓝桥杯剪邮票

先用全排列选出5张邮票,然后再判断是不是连通图就好了。 dfs和bfs都可以做 #include<iostream>#include<cstdio>#include<algorithm>#include<queue>#include<cstring>using namespace std;int ans[12]={0,0,0,...

2018-03-30 20:31:19 124

原创 17蓝桥杯 包子凑数

扩展欧几里德算法,如果给定n种蒸笼的最大公约数不等于1,那么就有无限多个否则算出不能凑出的数量。dp布尔数组,dp[i]表示i能不能被凑出,能赋值1,不能赋值0。先把初始的蒸笼数全部赋值1,然后从dp[1]开始找,一直到10010(假设边界不超过这个数)。 如果dp[i]不能被凑出,那么直接计数+1如果能凑出,那么将dp[i]的i加上n个蒸笼的数赋值1,也就是将dp[ans[0]]~dp[ans[...

2018-03-26 20:37:20 123

原创 17蓝桥杯 分巧克力

//二分答案 #include<iostream>#include<cstdio>#include<algorithm>using namespace std;int n,k,l,r,ans;struct cho{ int x,y;};cho c[100010];int judge(int x){ int tot=0;//表示以x为边长的巧...

2018-03-25 21:18:09 96

原创 17蓝桥杯 日期问题

我的做法是,先把三种表示法都写出来,再判断合不合法,用然后放入set集合里面去重排序,另外闰年的29号合法,需要另外判断 ,合法就输出,注意如果两种表示法表示的一样,只输出一个,比如02/02/29,只输出2029-02-02。#include<iostream>#include<cstdio>#include<cstring>#include<al...

2018-03-25 20:53:45 134

原创 14蓝桥杯 地宫取宝

使用一个四维数组来进行记忆化dfsx,y表示坐标,z表示当前已拿物品,Max表示当前拿到的最大价值物品那么ok[x][y][z][Max]表示 在点(x,y)处拿了z个物品最大价值为Max这个状态 到 点(n,m)处拿了k物品 这个状态有多少条走法。其中在初始位置拿的最大价值应该是-1,因为后面会有0价值的物品。判出递归边界有两个情况。情况1:不拿最后一个物品就已经有k个物品了情况2:可以拿最后一...

2018-03-24 19:38:35 115

原创 14蓝桥杯 蚂蚁感冒

贪心法先将所有蚂蚁位置按绝对值排序,并记录第一只蚂蚁所在的位置(数组中的位置) 两只蚂蚁碰面后方向调换,其实和不调换一样,题目只是计数,并没有要求记录哪些蚂蚁感冒了所以,有两种情况。 情况1,第一只感冒蚂蚁朝向的那方没有一只与它方向相反的蚂蚁,输出1。 情况2,有的话,将感冒蚂蚁朝向那方所有与它方向相反的蚂蚁计数,并且将感冒蚂蚁背后与它同向的蚂蚁也计数。 将上述两种情况,左右方向各写一次,便可求出...

2018-03-22 08:54:46 103

原创 13蓝桥杯 连号区间

#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int ans[100010];int n,Count=0;int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",...

2018-03-21 20:43:53 134

原创 13蓝桥杯 带分数

#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int ans[9]={1,2,3,4,5,6,7,8,9};//把所有排列弄出来 int Count=0;int main(){ int n; scanf("%d",&n); do{ ...

2018-03-21 19:57:44 118

原创 13年蓝桥杯 翻硬币

贪心法 先将字符串转换为布尔数组01然后从第一个开始比较,如果不同就翻相邻的两个硬币并计数+1 直到结束,一定是最少翻的 #include<iostream>#include<cstdio>#include<cstring> char str1[1005];char str2[1005];int ans1[1005];int ans2[1005];...

2018-03-20 21:20:26 300

原创 洛谷 P1316 丢瓶盖

二分答案#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int ans[100010];int a,b,l=100000000,r,n;bool judge(int x)// { int now=ans[1],tot=1; for(int i=2;...

2018-03-20 19:41:29 108

原创 洛谷 P1308 统计单词数

#include<iostream>#include<cstdio>#include<cstring> using namespace std;char str1[11];char str2[1000010];int Count=0,first=-1;int main(){ gets(str1); gets(str2); int len1=...

2018-03-20 19:33:16 376

原创 P1135 奇怪的电梯

#include<iostream>#include<cstdio>#include<queue>using namespace std;int n,a,b;int ans[210];int ok[210]={0};int bfs(int x)//x为当前楼层 { queue<int> q; q.push(x); while(!...

2018-03-19 21:00:32 194

原创 P1182 数列分段Section II

二分答案确定左边界和右边界后找中间值,验证该值是不是不满足要找到满足中最小的那个(不如说是找到不能满足的最大的那个+1)主要是怎么写好judge函数。将数列在保证分段和不超过mid的情况下 尽可能使得段数最少如果最少段数超过了m,说明满足最大值最小的(ans)一定比该二分答案大,也就是说mid不满足转而找右边的二分点如果没超过m,说明最大值最小的(ans)小于或等于mid,也就是说mid可能是最终...

2018-03-19 20:19:38 807

原创 洛谷P1057 传球游戏

#include<iostream>#include<cstdio>#include<cstring>using namespace std;int n;//记忆化搜索 int ans[33][33]; int f(int x,int y)//当前位置和 剩余次数 { if(y==0){ if(x==0)return ans[0][0]=1...

2018-03-18 19:32:46 213

原创 洛谷P1025 数的划分

和放苹果类似,将程序记忆化搜索#include<iostream>#include<cstdio>#include<cstring>using namespace std;int ans[210][8];//记忆化搜索 int f(int n,int k){ if(n<k)return f(n,n); if(n==0)return ans[...

2018-03-18 19:00:03 143

原创 洛谷 P1029 最大公约数和最小公倍数问题

假设p=x0*k1,q=x0*k2;k1与k2一定互质,如果不互质就存在更大的最大公约数 又因为两个数的乘积等于他们的最大公约数和最小公倍数的乘积 所以p*q=x0*x0*k1*k2=x0*y0即y0=x0*k1*k2将y0/x0,如果除不尽说明不存在这样的p与q除尽了,至少有两对pq组合。然后从x0到sqrt(y0/x0)穷举,得出两个数k1,k2,若k1与k2互质,说明又是两对。 #inclu...

2018-03-17 20:41:21 475

原创 洛谷 P1010 幂次方

//使用分治的思想,先将n化为二进制倒序(直接放里面存相当于倒着存)存放入字符数组//然后利用递归 将每一位是1的下标放入dfs()再进行一次转换//当循环到位数位二进制倒数第二位且有效时直接输出2//当循环到位数位二进制倒数第一位且有效时直接输出2(0)//除了第一位不放+号以外,其他只要不是0的项都放+号 #include<iostream>#include<c...

2018-03-16 20:51:55 184

原创 洛谷 P1226 取余运算||快速幂

#include<iostream>#include<cstdio>#include<cstring>using namespace std;typedef long long ll; ll a,n,m;int pow_mod(ll n)//幂取模算法 { if(n==0)return 1; ll x=pow_mod(n/2); ll ans...

2018-03-16 19:51:19 364

原创 洛谷18-03-15-P1141 01迷宫

#include<iostream>#include<cstdio>#include<cstring>using namespace std;int a[4]={-1,1,0,0};int b[4]={0,0,1,-1};int n,m; char ans[1010][1010]; int Count;int Cou[1010][1010];...

2018-03-16 19:18:44 123

原创 洛谷 18-03-14-P1443 马的遍历

对起点进行广搜,将一个点的坐标和到达该点所需要的步数建一个结构体。搜索一个点的八个方向,符合条件的点入队并记录步数标记该点已走过。如果有两条路径走到同一个点,那么因为广搜的原因,该点会自己记录到步数小的那个并且标记了ok数组已走过。#include<iostream>#include<cstdio>#include<queue>#include<cs...

2018-03-14 20:21:45 235

原创 洛谷 18-03-13- P1162 填涂颜色

题目描述由数字0 组成的方阵中,有一任意形状闭合圈,闭合圈由数字1构成,围圈时只走上下左右4个方向。现要求把闭合圈内的所有空间都填写成2.例如:6X6的方阵(n=6),涂色前和涂色后的方阵如下:0 0 0 0 0 00 0 1 1 1 10 1 1 0 0 11 1 0 0 0 11 0 0 0 0 11 1 1 1 1 10 0 0 0 0 00 0 1 1 1 10 1 1 2 ...

2018-03-13 21:06:15 201

原创 洛谷18-03-12-P1019 单词接龙

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int maxlength=0;char str[30][30];int n;int use[20]={0};int leastlink(char str...

2018-03-12 21:35:27 140

原创 洛谷18-03-11-P1101单词方阵

设置一个对应的布尔数组,初始化为0.枚举每个点8个方向。判断该方向是否为 yizhong如果是将对应该方向7个布尔变量置1。#include<iostream>#include<cstdio>#include<cstring>using namespace std;char str[102][102];int ans[101][102];int r[...

2018-03-11 21:05:54 98

原创 洛谷 P1094 纪念品分组

#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;vector<int> l;int w,n,buf,Count=0;int main(){ scanf("%d%d",&w,&

2018-03-10 20:36:15 167

原创 18-03-09 P1090 合并果子

#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<vector>using namespace std;struct rule{ bool operator() (const int &a,const int &amp...

2018-03-09 19:29:47 124

空空如也

空空如也

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

TA关注的人

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