- 博客(40)
- 资源 (2)
- 收藏
- 关注
转载 HDU 1547(Bubble Shooter)
#include <iostream>#include <cstring>#include <queue>using namespace std;const int MAXN = 105;int R, C;char mp[MAXN][MAXN]; //地图int s[MAXN * MAXN];int dir[2][6][2] = //搜索方向{ {{0,-1},{0,1},{-1,0},{1,0},{-1,1},{1,1} }, //偶数行.
2020-05-31 20:30:39 184
原创 HDU 1546(Idiomatic Phrases Game)
使用Dijkstra算法,首先建立有向图,将每个单词作为一个结点,和能直接接在其后的单词连线,然后计算起点到终点的最短距离即可。#include <iostream>#include <cstring>using namespace std;const int MAXN = 1005;const int INF = 0x3f3f3f3f;struct Word //单词{ int time; //查找后续单词所需时间 char first[5], last[.
2020-05-30 15:55:55 166
原创 HDU 1545(01-K Code)
动态规划题,设 dp[i][j][k] 表示长为 i 的子序列中,0 比 1 最多多 j 个,1 比 0 最多多 k 个。如果第 i+1 位填0,则 dp[i + 1][j + 1][max(k - 1, 0)] += dp[i][j][k];如果第 i+1 位填1,则 dp[i + 1][max(j - 1, 0)][k + 1] += dp[i][j][k]。#include <iostream>#include <cstring>#include <al
2020-05-29 10:30:00 282
原创 HDU 1544(Palindromes)
基础题,将原字符串中每一个字符作为回文子串的中心点,按照子串长度为奇数和偶数向两边扩展即可。#include <iostream>#include <string>using namespace std;int main(){ string s; while (cin >> s) { int len = s.size(); int ans = 0; int l, r; for (int i = 0; i < len; i++)
2020-05-28 23:59:58 324
原创 HDU 1543(Paint the Wall)
由于数据量很小,直接将每个矩形离散化,即拆分成小正方形,并记录每个小正方形的颜色,最后扫描一遍全图即可。#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int MAXN = 105;int X[MAXN * 2]; //所有左上角和右下角的X坐标int Y[MAXN * 2]; //所有左上角和右下角的Y坐标int color[MAX
2020-05-27 17:17:16 212
转载 HDU 1542(Atlantis)
#include <iostream>#include <algorithm>#include <iomanip>using namespace std;const int MAXN = 205;struct Line { double x; double y1, y2; int flag;}line[MAXN];double y[MAXN];double wide[MAXN * 4];int num[MAXN * 4];int cmp.
2020-05-26 16:16:16 148
转载 HDU 1541(Stars)
#include <iostream>#include <cstring>using namespace std;const int MAXN = 32005;int tree[MAXN << 2], num[MAXN << 2];int x, y;int level;void insert(int l, int r, int i){ if (l == r) level += tree[i]; else .
2020-05-25 14:44:45 164
转载 HDU 1540(Tunnel Warfare)
#include <iostream>#include <stack>using namespace std;const int MAXN = 50005;int L[4 * MAXN], R[4 * MAXN];int flag;void build(int l, int r, int rt){ L[rt] = R[rt] = r - l + 1; if (l == r) return; int m = (l + r) >> 1; bui.
2020-05-24 14:20:00 276
原创 HDU 1539(Shredding Company)
深搜题。#include <iostream>#include <cstring>using namespace std;const int MAXN = 25;int n; //目标数字char str[MAXN]; //输入带int len; //输入带长度int ans, flag; //满足要求的最大和int tmpPath[MAXN]; //临时路径int tmpIdx;int path[MAXN]; //最终路径int idx;void
2020-05-23 12:19:59 180
转载 HDU 1538(A Puzzle for Pirates)
#include <iostream>#include<cstdio>#include<ctime>#include<cstring>#include<cmath>#include<algorithm>#include<cstdlib>#include<vector>#define C 240#define TIME 10#define inf 1<<25#define.
2020-05-22 12:40:01 148
原创 HDU 1536(S-Nim)
SG函数题,套用标准模板即可。#include <iostream>#include <cstring>using namespace std;int sg[10005], num[105];int k;//计算sg[x]int getSG(int x){ if (sg[x] != -1) return sg[x]; bool vis[105]; memset(vis, 0, sizeof(vis)); for
2020-05-21 18:18:18 142
原创 HDU 1535(Invitation Cards)
使用 Dijkstra算法,首先构造正向图,计算从起点到达其余结点的最短距离;然后将正向图的所有边反向,构造反向图,再计算从起点到达其余结点的最短距离,此距离等于正向图中,从其余结点到达起点的最短距离。将两距离相加,即为从起点到达其余结点再返回起点的最短距离。由于结点数很多,所以采用 vector 结构构造地图,在 Dijkstra 算法中采用优先队列。#include <iostream>#include <vector>#include <cstring>
2020-05-20 16:50:01 184
转载 HDU 1534(Schedule Problem)
#include <iostream>#include <cstring>#include <string>#include<algorithm>#include<cstdio>#include<queue>using namespace std;const int MAXN = 1005;const int INF = 0x3f3f3f3f;struct Edge{ int to, cost, n.
2020-05-19 10:19:59 173
转载 HDU 1533(Going Home)
#include <iostream>#include <cstring>#include <cmath>#include <queue>using namespace std;const int MAXN = 105;const int MAXK = 5005;const int INF = 0x3f3f3f3f;struct Edge{ int y, next; int v, c;}edge[MAXK * MAXK];cha.
2020-05-18 11:30:01 125
原创 HDU 1532(Drainage Ditches)
网络流问题,使用最大流EK算法。#include <iostream>#include <cstring>#include <queue>#include <algorithm>using namespace std;const int MAXN = 205;const int INF = 0x3f3f3f3f;int C[MAXN][MAXN]; //C[i][j]表示结点i到结点j的剩余流量 int V[MAXN]; //V[i]表
2020-05-17 17:00:00 158
转载 HDU 1531(King)
#include <iostream>#include <vector>#include<cstring>#include<queue>#include<cstdio>#include<algorithm>using namespace std;const int MAXN = 105;const int INF = 0x3f3f3f3f;struct Edge //边{ int to; //终点.
2020-05-16 11:20:00 180
原创 HDU 1530(Maximum Clique)
计算最大团的结点数量,套用标准模板即可,详细见注释。#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 55;int n; //图中结点数量int ans; //最大团中结点的数量int mp[MAXN][MAXN]; //结点之间的连接关系int select[MAXN]; //当前最大团中的结点int num
2020-05-15 09:50:00 142
转载 HDU 1529(Cashier Employment)
#include <iostream>#include <cstring>#include <queue>using namespace std;const int MAXN = 30;const int INF = 0x3f3f3f3f;int val[MAXN]; //每个时刻需要的最小人数int num[MAXN]; //每个时刻能开始工作的最大人数int total, head[MAXN];int vis[MAXN], dis[MAXN], .
2020-05-14 23:23:23 138
原创 HDU 1528(Card Game Cheater)
最大二分匹配问题,将 Eve 的牌作为一条边,Adam 的牌作为另一条边,形成二分图,计算最大二分匹配即可。#include <iostream>#include <string>#include <cstring>using namespace std;const int MAXN = 30;int Adam[MAXN], Eve[MAXN]; //Adam的牌,Eve的牌bool mp[MAXN][MAXN]; //二分图bool vis[MAX
2020-05-13 12:49:59 148
转载 HDU 1527(取石子游戏)
#include <iostream>#include <algorithm>#include <cmath>using namespace std;int main(){ int a, b; while (cin >> a >> b) { if (a > b) swap(a, b); int k = b - a; if ((int).
2020-05-12 08:40:00 159
转载 HDU 1526(A Plug for UNIX)
网络流问题,使用最大流EK算法。#include <iostream>#include <map>#include <string>#include <cstring>#include <queue>#include <algorithm>using namespace std;const int MAXN = 2005;const int INF = 0x3f3f3f3f;map<string, int
2020-05-11 21:21:21 129
转载 HDU 1525(Euclid's Game)
#include <iostream>#include <algorithm>using namespace std;int main(){ int a, b; while (cin >> a >> b) { if (a == 0 && b == 0) break; if (a < b) swap(a, b); int flag = 0; while (b) { if (a / b.
2020-05-10 11:11:10 186
转载 HDU 1524(A Chess Game)
#include <iostream>#include <vector> #include <cstring>using namespace std;const int MAXN = 1005;vector<int> edge[MAXN]; //边int sg[MAXN]; //结点的sg值//计算结点x的sg值int getSG(int x){ if (sg[x] != -1) return sg[x]; .
2020-05-09 15:00:01 177
原创 HDU 1523(Decoding Morse Sequences)
动态规划题,设 dp[i] 表示莫斯编码序列前 i 位能组成的单词数,如果第 i 位至第 j 位为一个单词的莫斯编码,则 dp[i+j] += dp[i],注意将单词转换为莫斯编码后长度增加,数组长度需要适应编码后的长度。#include <iostream>#include <cstring>using namespace std;const int MAXN...
2020-05-08 11:40:51 146
原创 HDU 1522(Marriage is Stable)
稳定婚姻问题,首先计算所有男人喜欢的女人的顺序和所有女人喜欢的男人的顺序。然后对于每个男人,按照其喜欢的女人的次序依次和女人匹配,分为两种情况:女人未匹配,则该男人和女人匹配; 女人已匹配,如果相较于目前匹配的男人,该女人更喜欢该男人,则该男人和女人匹配,该女人之前匹配的男人置为未匹配状态。重复上述操作,直到所有男人和女人都匹配。#include <iostream>#...
2020-05-07 11:11:21 277
原创 HDU 1521(排列组合)
母函数题,求排列使用指数型母函数。#include <iostream>#include <cstring>using namespace std;const int MAXN = 15;int fac[MAXN]; //阶乘int num[MAXN];double c1[MAXN], c2[MAXN];void getFac(){ fac[0]...
2020-05-06 10:20:01 142
原创 HDU 1520(Anniversary party)
动态规划题,设dp[i][0] 表示不邀请第 i 个人时快乐值之和的最大值,则 dp[i][0] += max(dp[i.child][0], dp[i.child][1]);dp[i][1] 表示邀请第 i 个人时快乐值之和的最大值,则 dp[i][1] += dp[i.child][0]。#include <iostream>#include <vector>...
2020-05-05 16:40:40 165
转载 HDU 1519(Think Positive)
#include <iostream>using namespace std;int main(){ int T; cin >> T; while (T--) { int n; cin >> n; int sum = 0; while (n--) { int x; cin >> x; sum...
2020-05-04 14:40:00 167
原创 HDU 1518(Square)
深搜题,注意必须恰好用完所有的棍子。#include <iostream>#include <algorithm>#include <functional>using namespace std;const int MAXN = 25;int stick[MAXN]; //每根棍子的长度bool vis[MAXN]; //每根棍子的使用情况...
2020-05-04 13:30:30 143
原创 HDU 1517(A Multiplication Game)
模拟题,[n, +∞) 为必胜态,即先到达该区间的玩家获胜;则 [n/9, n) 为必败态,即先到达该区间的玩家失败,因为对手一定可以一步到达必胜态;则 [n/9/2, n/9) 为必胜态,因为对手一步只能到达必败态;以此类推,如果 1 为必败态,则 Stan 获胜,否则 Ollie 获胜。#include <iostream>#include <cmath>us...
2020-05-04 11:11:13 151
原创 HDU 1516(String Distance and Transform Process)
编辑距离题,套用标准模板即可,注意输出方式。#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 85;char s1[MAXN], s2[MAXN]; //原字符串,目标字符串int len1, len2; ...
2020-05-03 14:00:30 167
原创 HDU 1515(Anagrams by Stack)
深搜题,注意回溯方式,详细见注释。#include <iostream>#include <string>#include <stack>#include <vector>using namespace std;string s1, s2; //原字符串,目标字符串int len; //字符串长度stack<char>...
2020-05-03 10:59:59 248
转载 HDU 1514(Free Candies)
#include <iostream>#include <cstring>using namespace std;const int MAXN = 45;int pile[MAXN][5]; //堆int num[5]; //各堆中堆顶元素位置int dp[MAXN][MAXN][MAXN][MAXN];int n;//深搜,basket表示篮子中糖果...
2020-05-03 10:28:00 146
原创 HDU 1513(Palindrome)
最长公共子序列题,计算输入字符串和自身的逆序的最长公共子序列,用字符串长度减去最长公共子序列的长度即为最少需要添加的位数。(由于字符串过长,所以 dp 数组必须使用滚动数组,否则会内存超出)#include <iostream>#include <cstring>#include <algorithm>using namespace std;c...
2020-05-02 22:30:00 120
原创 HDU 1512(Monkey King)
使用左偏树,套用模板即可。#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 100005;int father[MAXN]; //父结点struct leftTree //左偏树{ int lc...
2020-05-02 21:00:00 132
转载 HDU 1511(Increasing Sequences)
#include <cstdio>#include <cstring>const int MAXN = 85;char num[85];int dp[85];int n;//判断num数组中,从pos1起始,长为len1的数,是否小于,从pos2开始,长为len2的数bool judge(int pos1, int len1, int pos2, int...
2020-05-02 09:49:59 201
原创 HDU 1510(White Rectangles)
动态规划题,首先求出每个格子向上的连续白色格子的数量,然后对于每一行,从左到右依次加上能组合的白色矩形的数量。#include <iostream>#include <cstring>using namespace std;const int MAXN = 105;char mp[MAXN][MAXN]; //棋盘int high[MAXN][MAXN];...
2020-05-01 21:50:49 185
原创 HDU 1509(Windows Message Queue)
模拟题,使用优先队列即可。#include <iostream>#include <string>#include <queue>using namespace std;const int MAXN = 60005;struct message //消息{ string name; //名称 int parameter; //参数 in...
2020-05-01 17:50:01 151
原创 HDU 1508(Alphacode)
动态规划题,由于 0 只能与其前一位结合,所以从后向前搜索。#include <iostream>#include <string>#include <cstring>using namespace std;const int MAXN = 1000005;__int64 dp[MAXN];int num[MAXN];string str;...
2020-05-01 10:40:00 146
原创 HDU 1507(Uncle Tom's Inherited Land*)
二分图的最大匹配问题。每个格子的横坐标和纵坐标之和为奇数或偶数,和为奇数的格子只可能与和为偶数的格子相邻,所以将和为奇数的格子作为二分图的一边,将和为偶数的格子作为二分图的另一边,如果两个空地格子相邻,则在两者之间连线。然后计算二分图的最大匹配数即可。#include <cstdio>#include <cstring>#include <cmath&g...
2020-05-01 09:50:00 144
QT、C++ 米其林自助点餐系统
2016-11-16
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人