自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 最大公共子串序列

例如串1ABCE 串2为BCDE 那么他们公共子串就是BCE这里要用到动态规划dp思路:dp[i][j]指的是字符串s1和s2的最长公共子序列要求它的下一个i+1 j+1时候的状态要分情况讨论:情况1:如果他们末尾的字母相等,那么该字母肯定是子序列中的一个dp[i][j]+1就行。情况2:如果不相等,就要取串1i+1和串2j的最大公共子序列和串i和串2j+1的公共子序列 这两个的最优解,...

2020-01-31 21:04:08 219

原创 dp 背包初级

背包问题:每个物品w千克 v个价值 要想在输入的we限定重量内 价值最高。AC代码:#include<stdio.h>#include<string.h>#include<algorithm> using namespace std;int dp[1000][1000];int we;int v[1000];int wm[1000]; in...

2020-01-31 19:19:28 209

原创 锯木头(贪心)

题目来源:点这里题目大致意思就是切木头要付出代价,求最小代价。(贪心)这里考到了二叉数的知识,要领:最小的数和次小的数是兄弟节点。AC代码:#include<stdio.h>#include<algorithm>using namespace std;typedef long long ll; ll l[200005];int main(){ int ...

2020-01-31 16:00:51 795

原创 bfs写法 nightmare

1代表空地 0代表阻挡物 3代表出口 4代表补给站 问最短路径因为可以重复走 为了防止超时 要用一个use数组 要是当前的时间比use数组的大 更新use数组的值 相当于剪枝AC代码:#include<stdio.h>#include<queue>#include<string.h>using namespace std;struct node{...

2020-01-31 12:52:00 507

原创 二维前缀和

题目大致意思求最大矩阵 输入k 矩阵元素和不超过k#include<stdio.h>#include<iostream> #include<algorithm>typedef long long ll;using namespace std;ll a[255][255];ll sum[255][255];int main(){ ll k; ...

2020-01-29 16:13:19 205

原创 非降序数列(思维题)

During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.Now she has a table filled with integers. The table consists of n rows and m colum...

2020-01-28 21:29:32 491

原创 查分前缀和

FJ’s N (1 ≤ N ≤ 10,000) cows conveniently indexed 1…N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,000) of t...

2020-01-27 22:17:55 323

原创 前缀和·

There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbour...

2020-01-27 22:11:05 221

原创 dfs剪枝

Ignatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the labyrinth before the bomb explodes. The initial ...

2020-01-26 20:31:01 196

原创 bfs pot

You are given two pots, having the volume of A and B liters respectively. The following operations can be performed:FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;DROP(i) empty the pot ...

2020-01-26 13:33:56 219

原创 bfs

The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices.— It is a matter of sec...

2020-01-24 21:25:51 193

原创 dfs

On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is mark...

2020-01-24 13:06:50 212

原创 bfs

题目:Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 10...

2020-01-23 22:50:45 190

原创 走马 dfs输出

BackgroundThe knight is getting bored of seeing the same black and white squares again and again and has decided to make a journeyaround the world. Whenever a knight moves, it is two squares in one ...

2020-01-23 21:23:58 250

原创 n皇后问题

在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。你的任务是,对于给定的N,求出有多少种合法的放置方法。Input共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。Output共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。Sample Input18...

2020-01-23 15:31:40 232

原创 并查集复习进阶版

An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the n...

2020-01-22 22:46:46 257

原创 二分二分

It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to make drying faster. But ...

2020-01-22 16:19:15 203

原创 Monthly Expense

Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that h...

2020-01-22 00:39:09 299

原创 二分 搬运石头问题

Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a ro...

2020-01-22 00:06:06 282

原创 string库函数

find函数#include <string>#include <iostream>using namespace std;int main(){ string str1("i am a student"); string str2("student"); string::size_type pos = str1.find(str2); //在字符串st...

2020-01-20 21:28:57 738

原创 迷宫问题 输出路径

定义一个二维数组:int maze[5][5] = {0, 1, 0, 0, 0,0, 1, 0, 1, 0,0, 0, 0, 0, 0,0, 1, 1, 1, 0,0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。Input一个5 × 5的二维数组,表示一个迷...

2020-01-19 21:44:51 356

原创 Agressive cows 二分

#include<stdio.h>#include<iostream>#include<algorithm>#include<stdlib.h>#include<string.h> int n,c;using namespace std;int a[100005];bool check(int m){ int las...

2020-01-19 19:57:11 260

原创 二分 找区间

题目:S1 = 1S2 = 12S3 = 123S4 = 1234…S9 = 123456789S10 = 1234567891S11 = 12345678912…S18 = 123456789123456789…现在我们把所有的串连接起来S = 1121231234…123456789123456789112345678912…那么你能告诉我在S串中的第N个数字是多少...

2020-01-19 14:39:43 309

原创 dfs走迷宫 算迷宫最小路径

输入m行n列的迷宫矩阵 0代表可以走 1代表围墙不能走 输入起点和终点,输出最短路径。#include<stdio.h>int a[51][51],book[51][51];int ex,ey;//终点坐标int min=9999;int m,n;void dfs(int startx,int starty,int step){ int tx,ty,k; int wa...

2020-01-17 22:41:44 434

原创 部分和问题

给定一个数组 里面数的部分和能否达到K#include<stdio.h>int a[100];int n,k;bool dfs(int i,int sum){ if(i==n) { return (sum==k);//如果前n项都计算过了 判断它和K是否相等 } if(dfs(i+1,sum+a[i])) return true;//加上该项的情况 if(df...

2020-01-17 20:27:13 222

原创 POJ 3069

要求数轴上任何一个点的R范围内都要存在一个以上被标记得点,求点的最少数量。#include<stdio.h>#include<algorithm>using namespace std;int n,m,r;int x[1000];//每个点的位置int main(){ int ans=0; int i; int s,t; scanf("%d%d",&amp...

2020-01-17 20:07:56 201

原创 欧几里得算法 算最大公约数

#include<stdio.h>int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b);}int main(){ int a=3,b=10; printf("%d",gcd(a,b));}

2020-01-17 19:48:07 381

原创 字典序最小问题(POJ 3617)

题目给定长度一定的s字符串,将它的头或尾的元素给空字符串T,要求T输出为字典序最小的字符串。#include<stdio.h>#include<string.h>int main(){ int i,j; char c[2005],t[2005]; gets(c); int a=0,b=strlen(c)-1; while(a<=b) { boo...

2020-01-17 19:18:21 353

原创 蓝桥杯 小数第n位

历届试题 小数第n位时间限制:1.0s 内存限制:256.0MB提交此题问题描述  我们知道,整数做除法时,有时得到有限小数,有时得到无限循环小数。  如果我们把有限小数的末尾加上无限多个0,它们就有了统一的形式。本题的任务是:在上面的约定下,求整数除法小数点后的第n位开始的3位数。输入格式  一行三个整数:a b n,用空格分开。a是被除数,b是除数,n是所求的小数后位置(0...

2020-01-16 21:31:18 289

原创 括号配对(stack)

找规律吧 把能消除的{}给消掉 最后在注意一下presentation error的问题。。。题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3351 #include<stdio.h>) #include<stack> #include<string.h> #include<algorithm&gt...

2020-01-15 23:25:38 244

原创 Dijkstra算法

#include<stdio.h>const int inf=1e9;int main(){ int m,n,i,j; int book[10]; int t1,t2,t3; int min; int a[10][10]; int dis[10]; scanf("%d%d",&m,&n);//输入有m个点,n条边 for(i=1;i<=m;i+...

2020-01-15 19:24:04 232

原创 扔盘子

有一口井,井的高度为N,每隔1个单位它的宽度有变化。现在从井口往下面扔圆盘,如果圆盘的宽度大于井在某个高度的宽度,则圆盘被卡住(恰好等于的话会下去)。盘子有几种命运:1、掉到井底。2、被卡住。3、落到别的盘子上方。盘子的高度也是单位高度。给定井的宽度和每个盘子的宽度,求最终落到井内的盘子数量。如图井和盘子信息如下:井:5 6 4 3 6 2 3盘子:2 3 5 2 4最终有4个盘子落在...

2020-01-14 21:31:39 363

原创 字典序的升级版

题目 输入m和n 在1~m中的数选n个数 将选出的数字按照字典序输出 ,输出样例AC代码:#include<stdio.h>#include<algorithm>int m,n; int a[100];void dfs(int sel,int cel){ int i; if(cel==n)//当cel到了n时输出样例 {for(i=0;i<n;i+...

2020-01-14 13:15:30 195

原创 next_permutation

在寻找全排列数时 发现了一种好用的函数框架如下#include<algorithm>using namespace std;int main(){ int a[N];sort(a,a+n);//注意这个函数的使用前提是数组为升序。do{...}while(next_permutation(a,a+length);}例题如下给出一个字符串S(可能有重复的字符),按照...

2020-01-13 22:52:40 222

原创 H - Cakeminator

链接:https://vjudge.net/contest/208467#problem/H题意大概是没有草莓的一行或者一列的蛋糕都能被吃到。用vis关系矩阵把能吃到的变为1。include<stdio.h>#include<algorithm> #include<string.h>int main(){ char a[11][11]; bo...

2020-01-12 23:34:47 247

原创 暴力打表也不是错~

题来自洛谷 P1217 [USACO1.5]回文质数 Prime Palindromes题目:题目描述因为 151 既是一个质数又是一个回文数(从左到右和从右到左是看一样的),所以 151 是回文质数。写一个程序来找出范围 [a,b] (5 \le a < b \le 100,000,000)a,b( 一亿)间的所有回文质数。输入格式第 1 行: 二个整数 a 和 b .输出格式...

2020-01-11 10:24:34 210

空空如也

空空如也

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

TA关注的人

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