- 博客(16)
- 收藏
- 关注
原创 Huffman树浅尝
A. POJ-1521 Entropy#include<cstdio>#include<string>#include<queue>#include<iostream>#include<algorithm>using namespace std;int main(){ string s; while(getline(cin,s) && s != "END"){ priority_queue<
2020-05-28 21:18:37 246
原创 贪心类型题小结
A. 最小硬币问题#include<iostream>using namespace std;const int NUM = 3;const int Value[NUM] = {1,2,5};int main(){ int i,money; int ans[NUM] = {0}; cin>>money; for(i = NUM - 1;i >= 0;i--){ ans[i] = money / Value[i]; money -= ans[i] * V
2020-05-28 16:01:43 266
原创 暴力枚举类型题小结
A. P2241 统计方形(数据加强版)#include<bits/stdc++.h>#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);#define ms(a,b) memset(a,b,sizeof(a))#define rush() int T;cin>>T;while(T--)#define ll long long//找规律....... using namespace
2020-05-28 15:51:28 420
原创 地图型DFS 小合集
A-P1219 八皇后问题#include<bits/stdc++.h>#define ms(a,b) memset(a,b,sizeof(a))using namespace std;const int N = 100;//好吧这种方法不太行 必须要把地图存成四个数组 或者一个二维是4的数组才行 //这样能记录 四条对角线的状态 int n,cnt;int table[N][N];int vis[N][N];int ans[N],b[N],c[N],d[N];//a
2020-05-23 21:25:34 343
原创 深度优先搜索
A-P2036 [COCI2008-2009#2] PERKET#include<bits/stdc++.h>using namespace std;const int N = 50;const int INF = 0x3f3f3f3f;int n,ans = INF;int acid[N],sweet[N];void DFS(int i,int x,int y){ if(i > n){ if(x == 1 && y == 0)return;
2020-05-23 21:21:22 320
原创 P1596 [USACO10OCT]Lake Counting S(洛谷 地图型DFS)
#include<bits/stdc++.h>using namespace std;const int N = 200;int n,m,ans;char table[N][N];bool vis[N][N];int dir[][2] = {{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,-1},{-1,1}};int check(int x,int y){ if(x < 1 || x > n)return 0; if(y
2020-05-22 12:33:57 188
原创 P1605 迷宫(洛谷 地图型DFS)
#include<bits/stdc++.h>using namespace std;const int N = 10;int n,m,t,sx,sy,fx,fy,ans = 0;int a,b;int table[N][N];int vis[N][N];int dir[][2] = {{0,1},{1,0},{0,-1},{-1,0}};int check(int x,int y){ if(x < 1 || x > n)return 0; if(y <
2020-05-22 12:33:15 303
原创 P2392 kkksc03考前临时抱佛脚(洛谷 数据型DFS)
#include<bits/stdc++.h>using namespace std;const int N = 50;const int INF = 0x3f3f3f3f;int s1,s2,s3,s4;int l,r,ans,minn;int work[N][5];int s[N];void DFS(int x,int i){ if(x > s[i]){ minn = min(minn,max(l,r)); return; } l += wo
2020-05-22 12:32:29 341
原创 P2404 自然数的拆分问题(洛谷 数据型DFS)
#include<bits/stdc++.h>using namespace std;const int N = 10000;int n;int num[N] = {1};void print(int x){ for(int i = 1;i < x;i++)cout<<num[i]<<"+"; cout<<num[x]<<endl;}int DFS(int x,int sum){ for(int i = num[
2020-05-22 12:31:37 202
原创 P2392 kkksc03考前临时抱佛脚(洛谷 数据型DFS)
#include<bits/stdc++.h>using namespace std;const int N = 50;const int INF = 0x3f3f3f3f;int n,ans = INF;int acid[N],sweet[N];void DFS(int i,int x,int y){ if(i > n){ if(x == 1 && y == 0)return; ans = min(ans,abs(x - y)); ret
2020-05-22 12:30:51 615
原创 P1162 填涂颜色(洛谷 BFS)
#include<bits/stdc++.h>using namespace std;const int N = 200;//一定要注意把 N 开的大一点 血的教训 起码3h浪费这上面 //方法1 找到圈圈里面的一个点 然后就可以染色圈内所有点 AC//方法2 先全部变成2 然后搜索外围变成0 前提是要多围出一圈0 方便搜索 struct Node{ int x; int y;};int dir[][2] = {{0,1},{1,0},{0,-1},{-1,0}};
2020-05-21 12:08:37 193
原创 P1506 拯救oibh总部(洛谷 BFS)
#include<bits/stdc++.h>using namespace std;const int N = 1000;//提前读取 * 的个数 在最外围建立额外 0 圈 方便BFS struct Node{ int x; int y;};int dir[][2] = {{0,1},{1,0},{0,-1},{-1,0}};int n,m,cnt = 0,num_star = 0,ans;int x,y;char table[N][N];int check(No
2020-05-21 12:07:53 384
原创 宽度优先搜索
第一个真正意义上的BFS注意点:方向数组初始化不能用小括号!!!#include<bits/stdc++.h>using namespace std;const int N = 500;int ans[N][N];int n,m,x,y;int dir[][2] = {{1,-2},{2,-1},{2,1},{1,2},{-1,2},{-2,1},{-2,-1},{-1,-2}};//奇怪!!!!!//为什么一定要用中括号括起来 struct node{ int x;
2020-05-20 12:29:11 211
原创 Codeforces Round #642 (Div. 3)(A B C D)
这一场完成了前三题加了分, 收获在于熟悉了优先队列以及运算符的重载(在D题中有所体现)A. Most Unstable Array(数学)#include<bits/stdc++.h>#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);#define ms(a,b) memset(a,b,sizeof(a))#define rush() int T;cin>>T;while(T--)
2020-05-19 12:55:52 245
原创 优先队列小结
#include<bits/stdc++.h>#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);#define ms(a,b) memset(a,b,sizeof(a))#define rush() int T;cin>>T;while(T--)#define ll long longusing namespace std;const int N = 10e5;/*---
2020-05-17 17:01:41 268
原创 Codeforces Round #640 (Div. 4)
CF出div.4了,我的青春结束了.(题解详见注释)A. Sum of Round Numbers#include<bits/stdc++.h>//这一题的题意就是把一个数拆成除第一位以外都是0的数,个位数保留//比如 115 = 100 + 10 + 5, 4142 = 1000 + 100 + 40 + 2 using namespace std;int main(){ int a[100];//存放每一个拆出来的数字 int t,num,s; cin>>
2020-05-10 21:00:58 317
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人