1103 integer factorization
摘要:dfs+prune AC代码: #include <vector> #include <cstdio> #include <algorithm> #include <cmath> #include <numeric> using namespace std; class sol{ public: v
阅读全文
posted @
2016-03-11 23:15
aldorado
阅读(343)
推荐(0)
1098 insertion or heap sort
摘要:堆排序STL algorithm里有建堆make_heap,出栈 pop_heap(将堆首元素移至容器尾部),入栈push_heap,以及堆排序sort_heap AC代码 #include <vector> #include <cstdio> #include <string> #include
阅读全文
posted @
2016-03-11 11:46
aldorado
阅读(199)
推荐(0)
1091 acute stroke
摘要:三维空间的DFS,挺新颖的一题 AC代码: #include <vector> #include <cstdio> #include <queue> using namespace std; int x[] = {0,0,1,0,-1,0}; int y[] = {0,1,0,-1,0,0}; in
阅读全文
posted @
2016-03-10 22:59
aldorado
阅读(267)
推荐(0)
1090 highest price in supply chain
摘要:p,r用double类型,pat多题如果用float会WA AC代码 #include <vector> #include <cstdio> #include <cmath> using namespace std; int main(){ int n; double p,r; scanf("%d
阅读全文
posted @
2016-03-10 22:24
aldorado
阅读(145)
推荐(0)
1088
摘要:a x b = c 将a,b,c用out统一输出 AC代码: #include <cstdio> #include <string> using namespace std; long long gcd(long long x,long long y){ if(x == 0) return y; i
阅读全文
posted @
2016-03-10 20:52
aldorado
阅读(244)
推荐(0)
1082 read number in chinese
摘要:注意0的情况 AC代码: #include <string> #include <iostream> #include <vector> using namespace std; string number[] = {"ling","yi","er","san","si","wu","liu","q
阅读全文
posted @
2016-03-09 22:49
aldorado
阅读(259)
推荐(0)
1079 total sales of supply chain
摘要:BFS,用递归的话会段错误,改用vector,变量idx记录下一层的起点 AC代码: #include <vector> #include <cstdio> #include <map> using namespace std; /*void bfs(vector<vector<int>>& g,v
阅读全文
posted @
2016-03-09 19:44
aldorado
阅读(359)
推荐(0)
1075 pat judge
摘要:最后一个测试点一直通不过,琢磨了一上午,终于找出bug 主要原因:考生k的第一个成绩是-1的情况,应将这项成绩记下,至于k是否所有提交的成绩都是-1,通过设置成员变量AC来判断,AC为true,写入vector参加后续排序,AC为false,不写入vector不参加后续排序。 AC代码: #incl
阅读全文
posted @
2016-03-09 11:39
aldorado
阅读(147)
推荐(0)
1074 reverse list
摘要:最后一个测试用例很坑,注意给出的n个节点不一定都在以h为头的链表上,这种测试用例在PAT链表相关的问题中多次出现,要予以注意。 AC代码 #include <vector> #include <map> #include <algorithm> #include <cstdio> using nam
阅读全文
posted @
2016-03-09 00:04
aldorado
阅读(146)
推荐(0)
1071 speech pattern
摘要:#include <string> #include <sstream> #include <map> #include <vector> #include <iostream> using namespace std; int main(){ vector<string> v; string tm
阅读全文
posted @
2016-03-08 20:26
aldorado
阅读(263)
推荐(0)
1065 a+b and c(64)
摘要:做得比较乱,修改多次后终于AC #include <string> #include <iostream> #include <algorithm> using namespace std; bool cmp(string a,string b){ if(a == b) return false;
阅读全文
posted @
2016-03-08 10:54
aldorado
阅读(184)
推荐(0)
pop sequence
摘要:两个set维护在stack中和不在stack中的元素,priority_queue维护在stack中的最大元素 AC代码 #include <set> #include <iostream> #include <queue> #include <cstdio> #include <vector> u
阅读全文
posted @
2016-03-03 21:12
aldorado
阅读(195)
推荐(0)
1049 counting ones
摘要:从所有一位数包含的1开始向上递推所有k位数包含的1,递推式: ak = ak-1 * 10 + pow(10,k-1); AC代码: #include <vector> #include <cstdio> using namespace std; int main(){ int n; vector<
阅读全文
posted @
2016-03-03 20:26
aldorado
阅读(190)
推荐(0)
1040 the longest symmetric
摘要:以每个字符为中心,分两种情况向两边扩展。 manacher算法参见http://www.cnblogs.com/houkai/p/3371807.html AC代码: #include <string> #include <cstdio> #include <iostream> using name
阅读全文
posted @
2016-03-02 16:24
aldorado
阅读(152)
推荐(0)
1039 course list for student
摘要:最后一点用string 和cin会超时 将学生名字转换成int用scanf就可以了 AC代码: #include <vector> #include <string> #include <map> #include <set> #include <cstdio> #include <iostream
阅读全文
posted @
2016-03-02 16:03
aldorado
阅读(176)
推荐(0)
1038 recover the smallest number
摘要:注意:最小数为0时,要输出“0” AC代码 #include <string> #include <vector> #include <algorithm> #include <iostream> using namespace std; bool cmp(const string& a,const
阅读全文
posted @
2016-03-02 12:42
aldorado
阅读(123)
推荐(0)
1035 head of a gang
摘要:简单并查集 AC代码 #include <map> #include <string> #include <iostream> #include <cstdio> #include <vector> using namespace std; string find(map<string,string
阅读全文
posted @
2016-03-01 23:40
aldorado
阅读(128)
推荐(0)
1033 to fill or not to fill
摘要:贪心算法 注意两点: 1、sum用double类型 2、第二个测试点是起点没有加油站的情况 AC代码 1 #include <vector> 2 #include <cstdio> 3 #include <algorithm> 4 #include <map> 5 using namespace s
阅读全文
posted @
2016-03-01 22:32
aldorado
阅读(172)
推荐(0)