- 博客(9)
- 收藏
- 关注
翻译 关于"树(Tree, UVa548)“的记录
代码是书上的,感觉比较简洁,故放上#include#include#includeusing namespace std;const int maxs = 100;int post_order[maxs], in_order[maxs], rch[maxs], lch[maxs];int index;bool read_list(int* a){ string s; int t
2015-09-27 17:43:14
403
原创 关于”图书管理系统(Borrowers,ACM/ICPC World Finals 1994, UVa230)"的讨论
利用sort函数的属性,写cmp函数#include#include#includeusing namespace std;const int maxn = 100;struct Gov{ string title; string author;} goven[maxn];bool cmp1(Gov gv1, Gov gv2){ return gv1.author < gv
2015-09-25 11:35:21
808
原创 关于“打印队列 Printer Queue, ACM/ICPC NWERC 2006, UVa 12100)"的讨论
打印队列有两个属性,一个是优先级一个是位置,可以写一个结构体存储这些信息再利用queue的特性完成本题#include#include#includeusing namespace std;const int maxn = 100;struct Coor{ int priority; int position;} co[maxn];queue line;void main
2015-09-25 11:32:32
976
原创 关于"对称轴 (Symmetry, ACM/ICPC Seoul 2004, UVa1595"的讨论
要找对称,可以以对称轴为中心,找匹配点,可以用map容器,考虑到坐标是二维的,可以用二维map#include#include#includeusing namespace std;map > m;const int maxn = 100;int ato[maxn][2];void main(){ int n; int a, b; int sum = 0; cin >
2015-09-24 23:23:28
962
原创 复合词(Compound Words, UVa 10391)
原题是给出一个词典,找出所有的复合词,即恰好有两个单词连接而成的单词,按照字典序输出。使用的用法是set和substr这两个办法。#include#include#include#includeusing namespace std;const int maxs = 100;set voca;set outvoca;string sts[maxs];void main(){
2015-09-24 16:32:46
655
原创 关于“交换学生(Foreign Exchange, UVa 10391)”的讨论
这道题的问题就是统计从A到B和想从B到A的人数是否一致,首先可以想到的是遍历,但是需要O(n^2)的时间,花费时间太多,可以发现本题可以处理为一个排序的问题,可以采用二分搜索法,使得复杂度为O(nlgn)。由于近期学习STL,map容器提供非常便捷的搜索和查找服务,但是如果是一维的map,很显然是办不到的,我们需要的是两个数的的匹配,其实也可以造一个很大的数组,让输入的数作为其下标,不过用map更
2015-09-24 13:12:26
513
原创 关于题目“DATAbase, ACM/ICPC NEERC 2009, UVa1592”的一个小问题探讨
题目主要用map匹配减少枚举次数来降低运行时间,首先是枚举两列,再从上到下对行进行扫描,要对进行比较的两个字符串进行预处理,用map映射成整数,然后再扫描过程中,合成一个整数,可以把第一个整数乘以一个很大的数再加后面的数来实现,然后题目要求是判断是否存在,则如果map不到,则对map编号依照当前行。只要找到第一个就可以输出了。#include#include#include#include
2015-09-23 21:11:27
1144
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人