UVa
文章平均质量分 67
ACLJW
这个作者很懒,什么都没留下…
展开
-
1593:Alignment of Code
Alignment of Code#include<iostream>#include<cstring>#include<vector>#include<algorithm>#include<sstream>using namespace std;const int maxw = 180 + 5;const int maxl...原创 2018-04-21 01:13:42 · 101 阅读 · 0 评论 -
12657:Boxes in a Line
Boxes in a Line考虑到反转单向链表时间开销太大,所以先用的是双向链表,这样只需要记录反转操作的次数即可,若最后次数为偶数,则从左往右加;若为奇数,则从右往左加。没想到还是超时了。。。version 1(超时):#include<bits/stdc++.h>using namespace std;const int maxn = 100000 + 5;int n,m;...原创 2018-05-23 17:34:44 · 192 阅读 · 0 评论 -
679:Dropping Balls
Dropping Balls直接模拟似乎很简单,但是会超时。。。每个小球都会落在根结点上,因此前两个小球必然是一个在左子树,一个在右子树。一般地,只需看小球编号的奇偶性,就能知道它是最终在哪棵子树中。对于那些落入根结点左子树的小球来说,只需知道该小球是第几个落在根的左子树里的,就可以知道它下一步往左还是往右了。依此类推,直到小球落到叶子上。version 1(Time Limited):#incl...原创 2018-05-28 18:34:13 · 124 阅读 · 0 评论 -
122:Trees on the level
Trees on the level哈哈 这次是一次AC,好开心啊version 1(指针链表版):#include<bits/stdc++.h>using namespace std;const int maxn = 256 + 5;struct node{ int num = -1; struct node* left = NULL; struct n...原创 2018-05-28 23:40:48 · 154 阅读 · 0 评论 -
548:Tree
Tree首先根据中序遍历和后序遍历递归地构造二叉树(后续遍历的最后一个节点为二叉树的根节点),然后前序遍历。输入有点坑,你说你直接告诉多少个节点多好。。。我想的是先用fets读取整个串,然后用atoi转化为数字,本地运行没问题可是一提交就报错,暂时还没找到原因,大概是因为回车符的问题,参考了别人的输入方法过了,比我的想法要好。#include<bits/stdc++.h>using ...原创 2018-05-29 23:22:48 · 147 阅读 · 0 评论 -
839:Not so Mobile
Not so Mobile 我的思路:可以将天平看做一棵二叉树,二叉树的每个节点要记录其父节点。然后其实就是一个建树的过程,遇到 0 节点就向下延伸,每当一个节点的左右子树确定(其重量也随之确定),就计算其是否平衡,然后一直向上追溯,直到该节点尚未平衡,继续建树,直至整棵树建好,是否平衡也随之确定。version 1(40ms):#include<bits/stdc++.h>usin...原创 2018-05-31 00:29:22 · 112 阅读 · 0 评论 -
669:The Falling Leaves
The Falling Leaves这道题还是递归,仿照上道题的思路挺容易的,不过看了看书上的代码个人觉得我的代码更简洁,思路更清晰些哈哈。我的思路:开个负下标数组,记录每个位置的权重之和,用 p 记录当前节点位置,那么其左节点位置为 p - 1,右节点位置为 p + 1,依次递归增加相应位置的权重,同时更新最右和最左边位置。#include<bits/stdc++.h>using ...原创 2018-05-31 13:25:43 · 138 阅读 · 0 评论 -
297:Quadtrees
Quadtrees建树递归,合并也递归。在合并的时候要注意只有两个没有子节点的节点之间才可以合并,可能会遇到三种情况:1. 两个都是最小单元(相对本身),直接合并;2. 其中一个有子节点,依次其将其子节点与另一个节点合并;3. 两个都有子节点,依次将其子节点按顺序进行合并(两者此时子节点面积必定相同,思考一下即可)。其中unit 为最小单元面积,每次划分都变为其本身的1/4,上述过程递归进行即可。...原创 2018-05-31 23:22:02 · 142 阅读 · 0 评论 -
572:Oil Deposits
Oil Deposits#include<bits/stdc++.h>using namespace std;const int maxn = 100 + 5;int m,n,cnt;char graph[maxn][maxn];void dfs(int x,int y){ graph[x][y] = '*'; for(int dx = -1;dx <=...原创 2018-06-01 12:58:50 · 121 阅读 · 0 评论 -
10305:Ordering Tasks
Ordering Tasks这题比较简单,就是拓扑排序,而且肯定是有向无环图,直接DFS即可。注意数据读取,只要 n 和 m 有一个不为0即可。。。不考虑是否存在环:#include<bits/stdc++.h>using namespace std;const int maxn = 100 + 10;int m,n,t;int visited[maxn];...原创 2018-08-05 00:29:29 · 173 阅读 · 0 评论 -
11988:Broken Keyboard (a.k.a. Beiju Text)
Broken Keyboard (a.k.a. Beiju Text)#include<bits/stdc++.h>using namespace std;const int maxn = 100000 + 5;char s[maxn];int last,cur,Next[maxn];//光标在cur右边int main(){ // freopen("data.in"...原创 2018-05-23 11:58:59 · 204 阅读 · 0 评论 -
1103:Ancient Messages
Ancient Messages数一数就能发现,题目表中的6个符号从左到右依次有1,3,5,4,0,2个洞,各不相同。这样,只需要数一数输入的符号有几个“白洞”,就能准确地知道它是哪个符号了。至于具体实现,我的思路是:先确定一个符号,找到该符号的空洞个数然后将该符号“擦除”,继续确定下一个符号。具体而言,每次找到一个黑点,然后DFS,如果其周围点为黑点则递归,若为白点且为封闭块则个数加1,最后再次...原创 2018-06-02 23:52:41 · 347 阅读 · 0 评论 -
1596:Bug Hunt
Bug Hunt我的思路:对于每行code,若无等号,直接初始化数组即可,否则依次检查等号左边和右边的表达式是否正确。对于左边的表达式,只需检查到首个数组之前即可,因为可能要对其初始化;对于右边表达式则要全部检查。对于复合表达式要如何检查呢?我的做法是先找出数字下标,确定其最内层数组,然后依次向外找出外层数组。此外还有一些小细节需要特别注意,这次是一次AC,开心。具体代码如下:#include&l...原创 2018-04-25 12:23:54 · 332 阅读 · 0 评论 -
210:Concurrency Simulator
Concurrency Simulator新鼠标新耳机好舒服啊 好享受这种听着喜欢的歌写着代码的感觉#include<bits/stdc++.h>using namespace std;const int maxn = 1000 + 5;int n,Q,t[5];string Key[] = {"=","print","lock","unlock","end"};int原创 2018-05-03 13:59:58 · 145 阅读 · 0 评论 -
1594:Ducci Sequence
Ducci Sequenceversion 1(130ms):#include<cstdio>using namespace std;const int maxn = 20;int t,n,a[maxn];int main(){ scanf("%d",&t); while(t--){ scanf("%d",&n); ...原创 2018-04-21 22:05:27 · 138 阅读 · 0 评论 -
10935:Throwing cards away I
Throwing cards away I queue#include<cstdio>#include<queue>using namespace std;int n;int main(){ while(scanf("%d",&n) && n){ if(n == 1){ //注意n为1的情况 p...原创 2018-04-21 22:44:45 · 158 阅读 · 0 评论 -
10763:Foreign Exchange
Foreign Exchangeversion 1(100ms):#include<cstdio>#include<map>#include<set>using namespace std;int n;int main(){ while(scanf("%d",&n) && n){ map<int,i...原创 2018-04-21 22:52:20 · 264 阅读 · 0 评论 -
1597:Searching the Web
Searching the Web这道题就 "and" 查询麻烦点,别的还好,但是刚开始超时了。。。version 1(Time limit exceeded):#include<bits/stdc++.h>using namespace std;const int maxn = 100 + 5;typedef pair<int,int> P;vector<s...原创 2018-04-28 21:42:09 · 130 阅读 · 0 评论 -
514:Rails
Rails #include<bits/stdc++.h>using namespace std;const int maxn = 1000 + 5;int main(){ // freopen("data.in","r",stdin); // freopen("data.out","w",stdout); int n,a[maxn]; while...原创 2018-05-19 23:40:52 · 106 阅读 · 0 评论 -
511:Do You Know the Way to San Jose?
Do You Know the Way to San Jose?题目不难,主要就是排序,不过有些细节需要注意。一个很坑的地方是 map 的两个对角点是不确定的,可能是左上和右下,也可能是左下和右上,而且两个点的顺序也不一定是左右。。。害我找了好久的bug。。。还有就是输出的时候注意单词别拼错了,空格别多打了。。因为这个WA了好几发。。AC大概是现在唯一能让我开心的事情了。#in...原创 2018-04-29 23:44:04 · 209 阅读 · 0 评论 -
442:Matrix Chain Multiplication
Matrix Chain Multiplication这道题比较简单,考察栈在表达式求值中的应用,看了书上代码之后才发现我考虑复杂了。。。其实题目中括号中只有个两个矩阵,我以为会有多个矩阵,所以将"("(用(0,0)代替)也压入了堆栈,用来判断什么时候停止合并。那样的话就特别特别简单了。。。输入数据少打了个回车找了半天bug。。。复杂版:#include<bits/stdc++.h>...原创 2018-05-20 22:11:24 · 130 阅读 · 0 评论 -
816:Abbott's Revenge
Abbott's Revenge一些细节要特别注意#include<bits/stdc++.h>using namespace std;const int maxn = 10;const char* dirs = "NESW";const char* turns = "FLR";struct Node{ int r,c,dir; Node(int a...原创 2018-07-31 23:39:16 · 167 阅读 · 0 评论 -
712:S-Trees
S-Trees#include<bits/stdc++.h>using namespace std;const int maxn = 7;int n,m,t,cnt = 0;char s[2];int a[maxn];char b[maxn];char leaf[int(pow(2,maxn))];char simu(){ int i = 0,j = t...原创 2018-08-09 22:11:05 · 141 阅读 · 0 评论 -
439:Knight Moves
Knight MovesBFS即可,字符串数组 size 定义成了 2 导致输入一直错误,应该是无法存入'\0' 引起的,待会儿再深究。#include<bits/stdc++.h>using namespace std;const int maxn = 8;typedef pair<int,int> P;int d[maxn][maxn];char a...原创 2018-08-09 23:10:24 · 93 阅读 · 0 评论 -
10410:Tree Reconstruction
Tree Reconstruction#include<bits/stdc++.h>using namespace std;const int maxn = 1000 + 5;int n,x,root;int pos[maxn];vector<int>A[maxn];int main(){ // freopen("data.in","r",stdi...原创 2018-08-20 23:12:59 · 255 阅读 · 0 评论 -
673:Parentheses Balance
Parentheses Balance之前脑子可能坏掉了。。。简单的栈的应用,要注意的一个地方是一定要用 fgets ,因为如果是空串的话 scanf 会直接读下一行。#include<bits/stdc++.h>using namespace std;const int maxn = 128 + 5;int n;char s[maxn];int main(){...原创 2018-08-21 16:21:32 · 465 阅读 · 0 评论 -
11853:Paintball
Paintball这个题可以看作是图上有很多圆形禁区,如果直接考虑是否可以从左边走到右边似乎有些无从下手,其实可以这样考虑,把整个方形区域看作水面,把禁区看作小岛,如果可以从上边沿着这些小岛走到下边的话,就说明方形区域被禁区整个隔断了,那么就不能从左边走到右边,这样一来DFS即可。(思路来自紫书)至于最北的位置,只需要在DFS的时候计算当前禁区与左右边缘的下交点,不断更新坐标值即可。因为我...原创 2018-08-29 00:32:03 · 161 阅读 · 0 评论 -
1354:Mobile Computing
Mobile Computing枚举二叉树然后计算其宽度即可,每次枚举两个节点构造一个父节点,计算宽度时需要注意的是每棵树的左节点的右边缘可能超过其右子树的左边缘,反之亦然。#include<bits/stdc++.h>using namespace std;const int maxn = 12;int n,s,idx,w[maxn],vis[maxn];doubl...原创 2018-10-26 17:37:09 · 121 阅读 · 0 评论 -
1601:The Morning after Halloween(经典)
The Morning after Halloween直接BFS会超时,题目中提示过墙壁很多,那么可以将所有的空格提取出来做张图,然后记录每个空格周围的邻居,这样就不用每次都判断能不能走了。优化的话可以使用双向BFS,从每次正向(从开始位置搜索)搜索一次,反向(从目标位置搜索)搜索一次,如果有相同状态则找到最短路径。BFS(800ms):#include<bits/stdc++...原创 2018-12-05 22:26:49 · 354 阅读 · 0 评论 -
10603:Fill
Fill#include<bits/stdc++.h>using namespace std;const int maxn = 200 + 5;int T, a, b, c, d;struct node{ int v[3], dist; bool operator < (const node& rhs) const{ retu...原创 2018-12-03 23:32:32 · 154 阅读 · 0 评论 -
225:Golygons
Golygons回溯加剪枝。某个方向可走的条件是此方向上没有障碍物挡道,还有一点容易被忽视的就是不能落到之前到过的点上!!!最重要的剪枝就是每走一步就判断一下剩下的步数是否有可能回到原点,还有就是如果提前到达原点也要剪掉。#include<bits/stdc++.h>using namespace std;const int maxn = 50 + 5;int T, n...原创 2018-12-13 23:34:23 · 110 阅读 · 0 评论 -
211:The Domino Effect
The Domino Effect回溯加剪枝。只需DFS右、下两个方向即可,可以一行一行来。弄完一行之后看下该行所有数字是否都配对了,否则剪枝。还是得细心,两个 cnt 认错了找了大半天 bug 。。。#include<bits/stdc++.h>using namespace std;const int n = 7;int cnt;int dx[] = {1, 0}...原创 2018-12-16 23:41:35 · 258 阅读 · 0 评论 -
208:Firetruck
Firetruck回溯即可,不过要注意先判断是否可以到达着火点,如果到不了那就没必要回溯了,可能给的数据比较坑,到不了的数据比较多,不判断的话会超时。还有就是输出的格式和样例给的竟然不一样,真是醉了。#include<bits/stdc++.h>using namespace std;const int maxn = 25;int t, n, cnt2;int vis...原创 2018-12-11 17:09:21 · 150 阅读 · 0 评论 -
129:Krypton Factor
Krypton Factor注意 && 别写成 & 了。。。#include<bits/stdc++.h>using namespace std;const int maxn = 80 + 5;int n,L,cnt;int A[maxn];int dfs(int cur){ if(cnt++ == n){ cnt =...原创 2018-08-17 00:38:42 · 121 阅读 · 0 评论 -
140:Bandwidth
Bandwidth注意节点不一定是按字母表顺序从前到后用的,也有可能是A C 却没用B,因为这个TLE了好几次。。#include<bits/stdc++.h>using namespace std;const int maxn = 26;int L,w;char s[100];int seq[maxn],vis[maxn],res[maxn],num[maxn],...原创 2018-08-18 22:47:48 · 134 阅读 · 0 评论 -
1600:Patrol Robot
Patrol Robot这个题还是DFS,不过每个状态除了记录位置之外,还要记录剩余穿越次数,这样一来就变成了三维DFS。对于值为1的点如果剩余穿越次数大于0且该状态未遍历过的话也可以访问。像这种四个方向的话用常量数组比较方便,没必要搞个二重循环,容易出bug。#include<bits/stdc++.h>using namespace std;const int max...原创 2018-08-10 00:56:31 · 133 阅读 · 0 评论 -
11059:Maximum Product
Maximum Product#include<bits/stdc++.h>using namespace std;const int maxn = 20;int n;int seq[maxn];int main(){ // freopen("data.in","r",stdin); // freopen("data.out","w",stdout);...原创 2018-08-14 11:49:42 · 128 阅读 · 0 评论 -
10976:Fractions Again?!
Fractions Again?!x 要用 long long。#include<bits/stdc++.h>using namespace std;const int maxk = 10000;int k;long long x[2*maxk];int y[2*maxk];int judge(int y){ long long x = k*y/(y-k...原创 2018-08-14 12:35:18 · 133 阅读 · 0 评论 -
10562:Undraw the Trees
Undraw the Trees这题没啥说的,利用DFS进行先序遍历即可,注意 node 可以不是字母,然后 puts() 默认换行的,太久没用都忘了。。#include<bits/stdc++.h>using namespace std;const int maxn = 200 + 5;int T;char G[maxn][maxn];bool isnode(ch...原创 2018-08-06 23:37:25 · 106 阅读 · 0 评论 -
806:Spatial Structures
Spatial Structures#include<bits/stdc++.h>using namespace std;const int maxn = 64 + 5;int n,len;int seq[maxn*maxn];char img[maxn][maxn];struct node{ char c = 0; int cnt = 4; ...原创 2018-08-11 23:25:48 · 148 阅读 · 0 评论