- 博客(52)
- 收藏
- 关注
原创 2022蓝桥杯----修建灌木
题目描述爱丽丝要完成一项修剪灌木的工作。有 N 棵灌木整齐的从左到右排成一排。爱丽丝在每天傍晚会修剪一棵灌木,让灌木的高度变为 0 厘米。爱丽丝修剪灌木的顺序是从最左侧的灌木开始,每天向右修剪一棵灌木。当修剪了最右侧的灌木后,她会调转方向,下一天开始向左修剪灌木。直到修剪了最左的灌木后再次调转方向。然后如此循环往复。灌木每天从早上到傍晚会长高 1 厘米,而其余时间不会长高。在第一天的早晨,所有灌木的高度都是 0 厘米。爱丽丝想知道每棵灌木最高长到多高。输入一个正整数 N ,含义如题面所述。对于
2022-04-17 10:12:56
339
原创 HDU----1847
题目链接Good Luck in CET-4 Everybody!代码如下#include<bits/stdc++.h>using namespace std;const int Maxm=1010,Maxn=10;int f[15],sg[Maxm];bool Hash[Maxm];void Getsg(){ f[0]=1; for(int i=1;i<=10;i++) { f[i]=f[i-1]<<1; } for(int i=1;i<
2021-09-01 15:10:01
156
原创 HDU----1846
题目链接Brave Game代码如下#include<bits/stdc++.h>using namespace std;int main(){ int t,n,m,k; cin>>t; while(t--){ cin>>n>>m; if(n%(m+1)==0){ cout<<"second"<<endl; } else cout<<"first"<<endl; }}
2021-09-01 15:06:09
152
原创 HDU----1150(二分分配算法)
题目链接Machine Schedule代码如下#include<bits/stdc++.h>using namespace std;const int M = 510;int k,m,n;int g[M][M],link[M];bool vis[M];bool dfs(int u){ for(int v = 0;v<n;v++) if(g[u][v]&&!vis[v]){ vis[v] = true; if(link[v]==-1||df
2021-08-19 15:26:47
138
原创 HDU----2063(二分匹配算法)
题目链接过山车代码如下#include<bits/stdc++.h>using namespace std;const int M = 502;int k,m,n;int g[2*M][2*M],link[M];bool vis[M];bool dfs(int u){ for(int v = 1;v<=n;v++) if(g[u][v]&&!vis[v]){ vis[v] = true; if(link[v]==-1||dfs(link[v
2021-08-18 16:19:46
95
原创 HDU----1312(dfs)
题目链接Red and Black代码如下#include<bits/stdc++.h>using namespace std;const int M = 22;char Map[M][M];bool vis[M][M];int w,h,ans;int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};void dfs(int si, int sj){ if(si<1||si>w||sj<1||sj>h) retu
2021-08-10 15:14:53
127
原创 HDU----1241(dfs)
题目链接Oil Deposits代码如下#include<bits/stdc++.h>using namespace std;int i,j,n,m;const int M = 105;int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};char a[M][M];void dfs(int si,int sj){ int di,dj; for(int k=0;k<8;k
2021-08-07 09:52:15
74
原创 HDU----1010(dfs)
题目链接Tempter of the Bone代码如下#include<bits/stdc++.h>using namespace std;char Map[9][9];int n,m,t,di,dj;bool escape;int dir[4][2] = {{0,-1},{0,1},{1,0},{-1,0}};void dfs(int si,int sj,int cnt);int main (){ int i,j,si,sj; while(cin>>n&g
2021-08-02 15:27:40
96
原创 HDU----1242(BFS)
题目链接Rescue代码如下#include<bits/stdc++.h>using namespace std;const int M = 205;int dx[] = {1,0,0,-1};int dy[] = {0,1,-1,0};int n,m;int vis[M][M];char mp[M][M];struct dot{ int x,y,time;};bool in(dot gx){ if(gx.x>=0&&gx.x<n&am
2021-08-02 10:27:11
63
原创 HDU----1372(BFS问题)
题目链接Knigth Moves代码如下#include <bits/stdc++.h>using namespace std;int vis[9][9];int ans=999999999;int sx,sy;int ex,ey;int dis[8][2]= {-1,-2,-2,-1,-2,1,-1,2,1,2,2,1,2,-1,1,-2};struct node { int x,y; int step;};int check(int x,int y)
2021-07-28 16:43:31
128
原创 HDU----1495(BFS问题)
题目链接非常可乐代码如下#include<bits/stdc++.h>using namespace std;const int M = 105;int s,n,m;struct cup{ int v[5]; int step;}temp;int vis[M][M][M],v[5];void pour(int a,int b){ int sum = temp.v[a]+temp.v[b]; if(sum>=v[b]) temp.v[b] = v[b]; e
2021-07-25 18:31:12
66
原创 HDU-----2680(最短路径)
题目链接Choose the best route代码如下#include<bits/stdc++.h>using namespace std; const int maxn=10000000;int mp[1000][1000];int vis[1000],le[1000]; int main(void){ int n,m,i,j,a,b,x,st,ed,w; while(~scanf("%d%d%d",&n,&m,&ed)) { me
2021-07-24 20:03:33
106
原创 HDU----2066(最短路径问题)
题目链接一个人的旅行代码如下#include <bits/stdc++.h>#define MAX 1010#define INF 999999999using namespace std;bool s[MAX];int ans[MAX][MAX],dist[MAX];void Dijkstra(int n,int v){ int i,j,u,temp; for(i=1;i<=n;i++) { dist[i]=ans[v][i];
2021-07-22 08:47:29
85
原创 HDU----1874(最短路径问题)
题目链接畅通工程续主要思路关于迪杰斯特拉算法的最短路径问题void shortestPath_Dijkstra(MGraph *g, int start, int end){ int len = g->numV; int visited[len]; int path[len]; int pre[len]; int min, k = 0; for (int i = 0; i < len; ++i) { visited
2021-07-19 16:51:08
104
原创 HDU----2159(背包问题)
题目链接FATE代码如下#include <bits/stdc++.h>using namespace std;int dp[100][100], a[100], b[100];int main(){ int n, m, k, s; while(~scanf("%d%d%d%d", &n, &m, &k, &s)) { memset(dp, 0, sizeof(dp)); for(int i=1; i<=k; i++){ sc
2021-07-19 11:01:57
115
原创 HDU----4508(背包问题)
题目链接湫湫系列故事——减肥记I代码如下#include <bits/stdc++.h>using namespace std;int v[105];int w[105];int dp[100005];int main(){ int n,m; int i,j; while(scanf("%d",&n)!=EOF) { memset(v,0,sizeof(v)); memset(w,0,sizeof(w));
2021-07-18 10:30:58
117
原创 HDU----1248(背包问题)
题目链接寒冰王座代码如下#include <bits/stdc++.h>using namespace std;int dp[10001],a[3]={150,200,350};int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); memset(dp,0,sizeof(a)); for(int i=0;i<
2021-07-18 10:23:56
92
原创 HDU----2191(背包问题)
题目链接悼念512汶川大地震遇难同胞——珍惜现在,感恩生活代码如下#include <bits/stdc++.h>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;int value[1000];//价值int weight[1000];int num[1000];int dp[1000000];int main(){ int t; scanf("%d",&t);
2021-07-15 08:36:38
75
原创 HDU----1114(背包问题1)
杭电OJ—11141.题目分析情况取最小的背包问题2.dp模板for (int i=1; i<=num; i++) for (int j=weight[i]; j<=bag; j++) dp[j]=max(dp[j],dp[j-weight[i]]+value[i]); 3.代码如下#include <bits/stdc++.h>using namespace std;int dp[1000000];int main(){ int t;
2021-07-13 16:24:30
125
原创 HDU----1421(搬寝室)
1421#include <bits/stdc++.h>using namespace std;#define MAX 3000#define INF INT_MAXint n, k, a[MAX], dp[MAX];int main() { int i,j; while (scanf("%d %d",&n,&k)!=EOF) { for(int i = 1; i <= n; i++) scanf("%d", a+i);
2021-05-29 09:23:52
79
原创 HDU----1176(免费馅饼)
免费馅饼#include <bits/stdc++.h>using namespace std;#define MXX 15#define MXT 300000int n, dp[MXT][MXX];int main(){ int T, t, x; while(scanf("%d", &n), n) { T = 0; memset(dp, 0, sizeof dp); for(int
2021-05-24 20:35:15
53
原创 HDU----pill(卡特兰数)
pill#include <bits/stdc++.h>using namespace std;#define MXN 35long long c[MXN] = {1,1};void init(){ for(int i = 1; i < MXN; i++) { c[i] = c[i-1]*4 - c[i-1]*6/(i+1); //递推公式1 }}int main(){ int n; init();
2021-05-20 20:26:41
77
原创 HDU----2084(数塔dp)
题目链接#include<bits/stdc++.h>using namespace std;int main() { int m,n; int ans[200][200]; cin>>m; while(m--) { cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ cin >>
2021-05-16 11:16:30
65
原创 P1044----栈
题目链接https://www.luogu.com.cn/problem/P1044#include<bits/stdc++.h>long long f[19];using namespace std;int main(){ int i,n,j; f[0]=1; f[1]=1; for(i=2;i<19;i++) { for(j=0;j<i;j++) f[i]=f[i]+f[j]*f[i-j-1];//卡特兰数 } while(~scanf("%d"
2021-05-16 09:05:28
64
原创 HDU----小兔的棋盘
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2067#include<bits/stdc++.h>long long f[36];using namespace std;int main(){ int i,n,m=0,j; f[0]=1; f[1]=1; for(i=2;i<36;i++) { for(j=0;j<i;j++) f[i]=f[i]+f[j]*f[i-j-1];//卡特兰数 } wh
2021-05-13 20:27:14
114
原创 HDU----2045
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2045#include<bits/stdc++.h>using namespace std;long long a[80];int main (void){ int n; a[0]=3; a[1]=6; a[2]=6; for(int i=3;i<80;i++) { a[i]=a[i-1]+2*a[i-2]; } while(scanf("%d",&n)!
2021-05-09 16:28:52
107
3
原创 HDU----2047(递推)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2047倒数一位可能为 E F O最后一个可以是E或者F 那么组数就是2*f(n-1) 如果最后一个是O,那么就要倒数第二个是E或者F才符合,所以是2*f(n-2)#include<bits/stdc++.h>using namespace std;long long a[40];int main (void){ int n; a[0]=1; a[1]=3; for(int
2021-05-09 16:09:02
172
4
原创 HDU----2501(递推)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2501这个题目与HDU2190--悼念512汶川大地震遇难同胞—重建希望小学一模一样,都是地板砖有点神奇,复制一下啦,没有改。#include<bits/stdc++.h>using namespace std;long long a[40];int main(void){ int n; int k; a[0]=1; a[1]=3; for(int i=2;i<4
2021-05-09 11:07:21
151
5
原创 HDU----2190(递推)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2190#include<bits/stdc++.h>using namespace std;long long a[40];int main (){ int n; int k; a[0]=1; a[1]=3; for(int i=2;i<40;i++) { a[i]=a[i-1]+a[i-2]*2; //找关系 } while (scanf("%d",&
2021-05-09 10:49:21
103
1
原创 HDU----2050
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2050 f(n)=f(n-1)+4f(n-2)+2-1 当n-1条折线时,区域数为f(n-1)。 为了使增加的区域最多,则折线的两边的线段,要和n-1条折线的边, 2*(n-1)条线段相交,即增加4*(n-1), 射线数为2,且折线本身相邻的两线段只能增加一个区域。 故:f(n)=f(n-1)+4(n-1)+2-1 =f(n-1)+4(n-1)+1
2021-05-05 19:47:01
54
1
原创 HDU----2046(递推)
题目链接·http://acm.hdu.edu.cn/showproblem.php?pid=2046#include<bits/stdc++.h>using namespace std;long long a[80];int main(void){ int n,k; a[0] = 0; a[1] = 1; a[2] = 2; for (int i=3;i<80; i++) { a[i] = a[i-1] + a[
2021-05-05 14:16:26
129
1
原创 HDU----2044(递推)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2044#include<bits/stdc++.h>using namespace std;long long a[80];//必须使用长整型int main(void){ int n,m,k; a[0] = 0; a[1] = 1; a[2] = 2; for (int i=3;i<80; i++) { a[i] =
2021-05-05 12:03:10
74
原创 HDU----2041(递推)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2041#include<bits/stdc++.h>using namespace std;int main(void){ int a[41]; int n,i,k; a[0]=0;//第一阶 a[1]=1; a[2]=2; for(i=3;i<41;i++)//类似斐波那契数列 { a[i]=a[i-1]+a[i-2]; //到达最后的阶梯,可以选择一阶或
2021-05-05 10:14:57
69
原创 HDU----1233(并查集)
#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>using namespace std;struct node{ int a,b,w;}e[10001];int f[101];int cmp(node x,node y){ return x.w<y.w;}int find
2021-05-04 21:24:09
58
原创 HDU----1232(并查集)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1232重要代码{ int find(int x)//find函数查找根节点 return x; return pre[x]=find(pre[x]) ;//pre[]记录前导点 } void join(int x,int y) {//判断 x,y 是否连通 int fx=find(x); int fy=find(y); if((x!=fy)) pre[fx] = fy;
2021-04-26 18:56:51
86
原创 HDU----1872稳定排序
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1872#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct Stu{ char name[55]; int g,id;}a[333],b[333];bool cmp(Stu a,Stu b){ if(a.g!=b.g) return a.g&g
2021-04-17 19:57:32
96
原创 HDU----3183贪心
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=3183#include<stdio.h>int main(){ char a[1100]; int n,len,i,j,f,sum; int min,k,f1; while(scanf("%s%d",a,&n)!=EOF) { len=0; for(i=0; a[i]!='\0'; i+
2021-04-16 21:18:40
107
原创 HDU----1052贪心
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1052#include<stdio.h>#include<algorithm>//此处using namespace std;bool cmp(int a,int b){ return a>b;} int main(){ int n,i,tj1,tj2,gw1,gw2,win,lose; int a[1005],b[1005],sum; while(
2021-04-16 19:56:06
101
原创 HDU----1236(结构体排名)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1236#include<bits/stdc++.h>using namespace std;int grade[11];struct student{ char name[21]; int res;}stu[1005];bool cmp(student a,student b){ if(a.res==b.res) return strcmp(a.name,b.name)&l
2021-04-14 20:00:10
70
1
原创 HDU----2037今年暑假不AC(贪心)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2037#include<bits/stdc++.h>#include<iostream>#include<algorithm>using namespace std;struct Time{ int s; int end;//s,end分别代表开始,结束 }t[130];bool cmp(Time a,Time b){ if(a.s==b.s
2021-04-11 10:00:44
98
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人