- 博客(18)
- 资源 (46)
- 收藏
- 关注
原创 UVa 1152 4Values whose Sum is 0
题意 从4个n元集中各挑出一个数 使它们的和为零有多少种方法直接n^4枚举肯定会超时的 可以把两个集合的元素和放在数组里 然后排序 枚举另外两个集合中两元素和 看数组中是否有其相反数就行了 复杂度为n^2*logn#include #define l(i) lower_bound(s,s+m,i)#define u(i) upper_bound(s,s+m,i)using
2015-01-29 10:49:22 955
原创 UVa 536 Tree Recovery(先序,中序求后序)
题意 给你二叉树的先序序列和中序序列 求它的后序序列先序序列的第一个一定是根 中序序列根左边的都属于根的左子树 右边的都属于右子树 递归建树就行了#include using namespace std;typedef struct TNode{ char data; TNode *lc, *rc;} node, *BTree;void build(B
2015-01-23 20:25:47 889
原创 UVa 439 Knight Moves(BFS应用)
题意 求国际象棋中骑士从一个位置移东到另一个位置所需最少步数基础的BFS应用#include using namespace std;int x[] = { -2, -1, -2, -1, 1, 2, 1, 2};int y[] = { -1, -2, 1, 2, -2, -1, 2, 1};int d[15][15], sx, sy, ex, ey;pair q[105],
2015-01-23 18:20:47 834
原创 UVa 673 Parentheses Balance(括号配对 栈)
题意 判断输入的括号序列是否是配对的栈的基础应用 栈顶元素与输入的字符匹配就出栈咯 注意括号序列可以为空STL栈#include using namespace std;int main(){ int cas; char c; cin >> cas; getchar(); while(cas--) { stac
2015-01-23 16:54:03 1094
原创 UVa 10305 Ordering Tasks(拓扑排序)
题意 输出n个数m组小于关系的一种可能的拓扑排序应用dfs拓扑排序 访问j时 若存在i#include using namespace std;const int N = 105;int n, m, t, v[N], tpo[N], g[N][N];void dfs(int j){ if(v[j]) return; for(int i = 1; i <=
2015-01-23 15:28:42 1016
原创 UVa 210 Concurrency Simulator(双端队列)
题意 模拟程序并行运行 STL队列 双端队列 的应用 用双端队列维护即将执行的程序 再用个队列维护等待变量释放的程序 用lock表示变量锁定状态先将所有程序放到执行队列中 每次取出队首程序运行不超过lim时间 未运行玩又放到执行队列队尾 遇到lock时 若当前锁定状态为false就将锁定状态变为true 否则将当前程序放到等待队列队尾并结束运行 遇到unlock时
2015-01-23 13:16:07 5642 1
原创 UVa 12504 Updating a Dictionary(更新字典)
题意 比较两个字典 按字典序输出所有添加 删除 修改的项 如果没有任何更新 输出 No changesSTL map的应用 对比两个字典 注意开始字符串的处理和字典可以为空#includeusing namespace std;map d[2];map::iterator it;const int N = 105;string s, a, b, t[N];vo
2015-01-22 16:16:49 2112
原创 UVa 12110 Printer Queue(特殊队列)
题意 模拟打印队列 队列中有优先级大于队首的元素 队首元素就排到队尾 否则队首元素出队 输出开始在p位置的元素是第几个出队的直接模拟这个过程就行了#include using namespace std;const int N = 205;int q[N];int main(){ int cas, n, p, cnt, front, rear, i;
2015-01-22 13:15:38 833
原创 UVa 1595 Symmetry(暴力)
题意 给你不超过1000个点的坐标 判断这些点是否是关于一条竖线对称的没想到暴力枚举可以过 如果存在对称轴的话那么对称轴的横坐标一定是最左边的点和最右边的点的中点 为了避免中点是小数 可以将横坐标都乘上2 然后在判断所有点是否有对称点就行了#include using namespace std;const int N = 1005;int x[N], y[N], n
2015-01-22 10:04:16 4218 1
原创 UVa 10391 Compound Words(复合词)
题意 输出所有输入单词中可以由另两个单词的组成的词STL set的应用 枚举每个单词的所有可能拆分情况 看拆开的两个单词是否都存在 都存在的就可以输出了#include using namespace std;string a, b;set s;set::iterator i;int main(){ int l; while(cin >> a) s.i
2015-01-21 17:49:37 1086
原创 UVa 1593 Alignment of Code(字符串)
题意 按要求对齐代码字符串流的应用#include using namespace std;const int N = 1005, M = 200;string s[N][M], line;int cw[M], cn[N];int main(){ int r = 0, c = 0; while(getline(cin, line)) {
2015-01-21 12:49:29 2209
原创 UVa 136 Ugly Numbers(优先队列)
题意 质因数只可能有2,3,5的数称为丑数 输出第1500个丑数STL优队列应用 1是丑数 丑数的2,3,5倍都是丑数 用优先队列模拟就行了#include #include #include #include using namespace std;typedef long long ll;//priority_queue, greater > q;struct
2015-01-20 20:52:48 1349
原创 UVa 540 Team Queue(团队队列)
题意 模拟团队队列的入队和出队STL应用 用一个队列维护团队编号 再用一个队列数组维护个体#include #include #include #include using namespace std;const int N = 1000005;int team[N];int main(){ int cas = 0, n, t, a; char cm
2015-01-20 20:39:29 964
原创 UVa 1589 Xiangqi(模拟 HDU4121)
题意 给你一个黑方被将军的象棋残局 判断红方是否已经把黑方将死模拟题 注意细节就行了 看黑方的将是否四个方向都不能走#include#includeusing namespace std;const int N = 12;char brd[N][N];int dx[] = { -1, 1, 0, 0}, dy[] = {0, 0, -1, 1};int hx[] =
2015-01-20 14:07:37 2595 6
原创 CF 505B Mr. Kitayuta's Colorful Graph(最短路)
题意 求两点之间有多少不同颜色的路径范围比较小 可以直接floyd#include#includeusing namespace std;const int N = 105;int d[N][N][N], ans;int main(){ int a, b, c, n, m, q; while(~scanf("%d%d", &n, &m)) {
2015-01-19 09:06:39 1314
原创 CF 505A Mr. Kitayuta's Gift(暴力)
题意 在一个字符串中插入一个字母使其变成一个回文串 可以的话输出这个回文串 否则NA大水题 插入情况最多就26*11种 可以直接暴力#include#includeusing namespace std;const int N = 20;char s[N], p[N];int l;bool ispal(){ for(int i = 0; i < (l + 1
2015-01-19 09:00:59 1710
原创 UVa 202 Repeating Decimals(模拟)
大水题 模拟在草稿纸上算除法的过程→_→#include#includeusing namespace std;const int N = 3005;int a[N], v[N];int main(){ int n, m, cnt; while(~scanf("%d%d", &n, &m)) { cnt = 0; mems
2015-01-18 10:17:16 1091
原创 UVa 1587 Box
大水题一发 弄清长方体的几个面的关系就行了#include#includeusing namespace std;const int N = 6;struct rec{ int l, w;} r[N];bool cmp(rec a, rec b){ return a.w < b.w || (a.w == b.w && a.l < b.l);}int main()
2015-01-17 21:55:17 3122
(HDUACM201303版_15)筛选法及预处理(附菜鸟的23个经典错误)
2014-08-25
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人