
UVa
stdwal
天演在化,功成在学。知海无涯,见花问道。
展开
-
UVa11292-Dragon of Loowater
用两个优先队列维护龙头的直径和骑士的高度,不断从队列中抛出元素,第一个满足条件的即为最小的。#include <cstdio>#include <queue>using namespace std;int main(int argc, char const *argv[]) { int n, m; while (scanf("%d%d", &n, &m) == 2 && n + m原创 2016-09-18 22:48:01 · 323 阅读 · 0 评论 -
UVa11792-Commando War
需要b分钟给士兵指派任务,j分钟士兵执行任务,问用时最少。 将任务按照执行时间从大到小排序,贪心即可。#include <cstdio>#include <algorithm>using namespace std;const int maxn = 10000 + 10;struct soldier { int b, j;};soldier tm[maxn];bool comp(con原创 2016-09-19 16:23:20 · 295 阅读 · 0 评论 -
UVa10881-Piotr's Ants
所有的蚂蚁都可以看作对穿而过且相对位置不变。#include <cstdio>#include <algorithm>const int maxn = 10000 + 10;struct ant { int id, pos, dir;};ant begin[maxn], end[maxn];int order[maxn];bool comp(const ant &a, const ant原创 2016-09-20 15:37:06 · 384 阅读 · 0 评论 -
UVa11464-Even Parity
类似于反转问题,枚举第一行即可。#include <cstdio>#include <cstring>#include <algorithm>const int maxn = 20;const int inf = 400;int dx[4] = {-1, 0, 1, 0};int dy[4] = {0, -1, 0, 1};int grid[maxn][maxn];int flip[max原创 2016-09-20 18:15:25 · 303 阅读 · 0 评论 -
UVa11384-Help is needed for Dexter
思维题,每次第一步操作先取出一半,序列变为1, 2, 3, … , n / 2, 0, 1, 2, 3, … , (n-1)/2 其中0, 1, 2, 3, … , (n-1)/2等价于1, 2, 3, … , n / 2,因此f(n) = f(n/2)+1.#include <cstdio>int f(int n) { return n == 1 ? 1 : f(n/2) + 1;}i原创 2016-09-24 10:14:20 · 363 阅读 · 0 评论 -
UVA10585-Center of symmetry
计算几何入门,将所有的点排序遍历即可。//UVA10585#include <cstdio>#include <map>#include <algorithm>using namespace std;const int maxn = 10000 + 10;typedef pair<int, int> P;P point[maxn];int main(int argc, char const *原创 2016-09-01 21:01:51 · 325 阅读 · 0 评论 -
UVa839-Not So Mobile
使用递归直接处理信息并建树,同时判断是否满足杠杆定理//UVa 839#include <cstdio>bool flag;int build() { int wl, dl, wr, dr; scanf("%d%d%d%d", &wl, &dl, &wr, &dr); if (wl == 0) { wl = build(); } if (wr原创 2016-09-08 20:41:32 · 297 阅读 · 0 评论 -
UVa11520-Fill the Square
给定一个n*n的方阵要求往里面填充字符使得字典序最小。 暴力搜索,从上到下从左至右选择最小的字符填充即可。#include <cstdio>char grid[12][12];int dx[4] = {-1, 0, 1, 0};int dy[4] = {0, 1, 0, -1};int n;void Dfs(int x, int y) { if (y >= n) { Df原创 2016-09-28 19:36:25 · 320 阅读 · 0 评论 -
Uva514-Rails
有n辆火车入栈出栈,判断出栈顺序是否合法 用a,b两个变量标记,将a入栈直到找到第一个t[a] == b的数,然后判断栈内的数与t[b]是否匹配。#include <cstdio>#include <stack>using namespace std;int t[1005];int main(int argc, char const *argv[]) { int n; while原创 2016-11-13 19:19:14 · 440 阅读 · 0 评论