PAT-A
文章平均质量分 50
a1eafall
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
1113. Integer Set Partition (25)
题目链接这道题本来是考类快速选择的算法的,因为题目数据太弱,导致O(nlogn)的排序算法也能AC。 下面的代码可以以平均O(n)的时间复杂度找到给定数组中第k大(0<=k<n)的元素,同时以该元素将数组左右分开。int Kth_elem(int a[],int low,int high,int k){ swap(a[low],a[(low+high)/2]); int pivot原创 2016-04-08 20:55:23 · 819 阅读 · 0 评论 -
1114. Family Property (25) 并查集
题目地址和前面的1107类似,只是更复杂一些。 使用一个结构体Mem来记录每个人名下的财产(es),地产(area),家庭成员数(num);借助’std::set’的去重功能,使用’set<>’记录所有出现的人的ID;使用map<int,vector<int>>记录集合根节点对应的所有子节点。并将集合中所有人的平均信息存储到该集合中ID最小的人头上,然后将其存入vector<int> final,原创 2016-10-03 21:26:43 · 342 阅读 · 0 评论 -
1107. Social Clusters (30) 并查集
题目地址用vector<int>数组来记录每次输入有这个爱好的人的ID, 用map<int,int>来统计有几个集合,注意最后统计时还要进行路径压缩。// // Created by aleafall on 16-10-3. //#include<iostream> #include<cstdio> #include<algorithm> #include<map> #include<vector原创 2016-10-03 21:12:32 · 552 阅读 · 0 评论 -
1112. Stucked Keyboard (20) hash
题目地址#include<iostream> #include<string> #include<vector>using namespace std; const int maxn = 256; bool hashTable[maxn] = {0}; //标记是否坏键 bool vis[maxn] = {0}; //标记是否输出坏键 struct Key{ char c; i原创 2016-04-08 20:23:42 · 422 阅读 · 0 评论 -
A1080. Graduate Admission (30)
1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is said that in 2转载 2015-08-08 16:26:39 · 552 阅读 · 0 评论 -
1111. Online Map (30) 最短路径、DFS
时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two p原创 2016-04-08 13:38:21 · 604 阅读 · 0 评论 -
1109. Group Photo (25) 排序、模拟
时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following:The原创 2016-04-06 15:14:33 · 610 阅读 · 0 评论 -
1108. Finding Average (20) 字符串处理
时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated原创 2016-04-06 14:55:17 · 1645 阅读 · 0 评论 -
1106. Lowest Price in Supply Chain (25) 树的遍历,DFS
Lowest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– eve原创 2016-04-06 14:48:21 · 355 阅读 · 0 评论 -
1104. Sum of Number Segments (20) 找规律
Sum of Number Segments (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For原创 2016-04-06 14:22:14 · 333 阅读 · 0 评论 -
1115. Counting Nodes in a BST (30) 二叉树
题目地址创建二叉搜索树并输出其最低两层的节点数目,使用先序遍历,注意当树只有一层时的情况。// // Created by aleafall on 16-10-3. //#include<iostream> #include<map>using namespace std; struct Node { int data; Node *lchild, *rchild; } *root;原创 2016-10-03 21:34:09 · 302 阅读 · 0 评论 -
1116. Come on! Let's C (20) 简单模拟
题目地址// // Created by aleafall on 16-9-28. //#include <iostream>using namespace std;bool isPrime(int n){ if (n<=1) return 0; for (int i = 2; i*i <= n; ++i) { if (n%i==0) return 0; }原创 2016-10-03 21:36:36 · 498 阅读 · 0 评论 -
1117. Eddington Number(25) 模拟
题目地址// // Created by aleafall on 16-9-28. //#include <bits/stdc++.h>using namespace std;const int maxn = 100005;bool cmp(int a, int b) { return a > b; }int main() { int n, a[maxn]; cin >> n原创 2016-10-03 21:38:26 · 390 阅读 · 0 评论 -
1105. Spiral Matrix (25) 排序、模拟
Spiral Matrix (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing o原创 2016-04-06 14:39:28 · 1203 阅读 · 0 评论 -
1040. Longest Symmetric String (25)
题目地址 对于给定字符串(0~s.size()),从1到s.size()-1,向它的两边进行扩展, 对于cabad型以及cabbad型都要考虑。// // Created by aleafall on 16-11-25. //#include <iostream> #include <algorithm> #include <string>using namespace std;int main原创 2016-11-25 10:43:31 · 329 阅读 · 0 评论 -
1110. Complete Binary Tree (25) 完全二叉树、树的遍历
时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a tree, you are supposed to tell if it is a complete binary tree.Input Specification:Each input file contains one tes原创 2016-04-06 16:00:49 · 2186 阅读 · 0 评论 -
1120. Friend Numbers (20) 统计友元
题目地址直接统计,用set去重。// // Created by aleafall on 16-12-10. //#include <bits/stdc++.h>using namespace std;int main() { int n, m, x; set<int> st; cin >> n; for (int i = 0; i < n; ++i) {原创 2016-12-10 21:26:18 · 686 阅读 · 0 评论 -
1123. Is It a Complete AVL Tree (30)
题目地址 考了二叉平衡树,完全二叉树的判断,树的遍历,其中二叉平衡树写起来比较麻烦。 创建一个null结点,令所有的叶结点都指向它,这样在通过左右孩子结点更新高度时就不会访问到空指针,因为最底下就是null,而它不为空,它的高度设置为0;同时插入新结点insert(Node *&node,data)是递归插入,会插入到原树的叶结点下面,所以updateHeight()函数是从底向上一层一层更新高原创 2016-12-10 21:50:59 · 754 阅读 · 3 评论 -
1122. Hamiltonian Cycle (25)
题目地址要求给出的路径构成一个简单环(只有一圈),且包含所有结点才满足题目要求。 不满足要求的情况判断:路径不连通不符合要求;路径头尾结点出现次数应为2次,中间的为1次;所有点都必须出现过。// // Created by aleafall on 16-12-10. //#include <bits/stdc++.h>using namespace std;const int maxn = 205原创 2016-12-10 21:37:26 · 671 阅读 · 3 评论 -
1121. Damn Single (25)
题目地址使用map记录couple,当某人和它的另一半同时出现时,才不为single。// // Created by aleafall on 16-12-10. //#include <bits/stdc++.h>using namespace std;const int maxn = 100005; bool vis[maxn] = {0};int main() { int n, x1,原创 2016-12-10 21:30:02 · 594 阅读 · 0 评论 -
1119. Pre- and Post-order Traversals (30) 二叉树
题目地址// // Created by aleafall on 16-10-2. //#include <iostream>using namespace std;const int maxn = 31;int n, index = 0; int pre[maxn], post[maxn]; bool flag = true;struct Node { int data; Node原创 2016-10-03 21:43:13 · 940 阅读 · 0 评论 -
1118. Birds in Forest (25) 并查集
题目地址和1107,1114题类似。// // Created by aleafall on 16-9-28. //#include <iostream> #include <set>using namespace std;const int maxn = 10005;int father[maxn];int findFather(int x) { if (father[x] == x) re原创 2016-10-03 21:41:25 · 334 阅读 · 0 评论 -
A1101. Quick Sort (25)
1101. Quick Sort (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng There is a classical process named partition in原创 2015-09-23 13:12:19 · 397 阅读 · 0 评论 -
A1023. Have Fun with Numbers (20)
1023. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Notice that the number 123456789 is转载 2015-08-23 09:43:41 · 335 阅读 · 0 评论 -
A1038. Recover the Smallest Number (30)
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a collection of number s转载 2015-08-23 11:35:30 · 489 阅读 · 0 评论 -
A1029. Median (25)
#include #include using namespace std; const long long inf = 0x7fffffff; const int maxn = 1000001; long long a[maxn],b[maxn]; //大数组定义在main外 int main(){ int n1,n2; long long max; scanf("%d",&n1);转载 2015-08-11 09:17:23 · 282 阅读 · 0 评论 -
A1044 Shopping in Mars (25)
1044. Shopping in Mars (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shopping in Mars is quite a different exp转载 2015-08-10 15:50:22 · 366 阅读 · 0 评论 -
A1037 Magic Coupon (25)
1037. Magic Coupon (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The magic shop in Mars is offering some magic转载 2015-08-10 09:27:35 · 312 阅读 · 0 评论 -
A1099. Build A Binary Search Tree (30)
definition of a BST. You are supposed to output the level order traversal sequence of that tree. The sample is illustrated by Figure 1 and 2. Input Specification: Each input file contains on原创 2015-08-24 11:51:24 · 432 阅读 · 0 评论 -
A1073. Scientific Notation (20)
1073. Scientific Notation (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming Scientific notation is the way that转载 2015-08-24 10:46:32 · 370 阅读 · 0 评论 -
A1097. Deduplication on a Linked List (25)
1097. Deduplication on a Linked List (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a singly linked list转载 2015-08-24 09:26:41 · 340 阅读 · 0 评论 -
A1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and Rice is the name of a programming co转载 2015-08-23 18:08:38 · 377 阅读 · 0 评论 -
A1070. Mooncake (25)
1070. Mooncake (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mooncake is a Chinese bakery product traditionall转载 2015-08-09 19:56:54 · 353 阅读 · 0 评论 -
A1049. Counting Ones (30)
1049. Counting Ones (30) 时间限制 10 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task is simple: given any positive intege转载 2015-08-23 15:33:39 · 376 阅读 · 0 评论 -
A1069 . The Black Hole of Numbers (20)
#include #include #include //仔细观察,合并 using namespace std; bool cmp(char c1,char c2){ return c1 > c2; } int main(){ int n,n1,n2; char str[5]; scanf("%d",&n); while(1){ sprintf(str,"%04d",n);转载 2015-08-11 10:34:01 · 374 阅读 · 0 评论 -
A1085. Perfect Sequence (25)
#include //两点法,为什么必须去掉下面的判断语句 #include using namespace std; int main(){ long long n,p; scanf("%lld %lld",&n,&p); long long a[n]; for(int i = 0;i < n;i++) scanf("%lld",&a[i]); sort(a,a+n);转载 2015-08-10 20:05:31 · 322 阅读 · 0 评论 -
A1022. Digital Library (30)
1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Digital Library contains millions of bo转载 2015-08-25 14:38:19 · 441 阅读 · 0 评论 -
A1024. Palindromic Number (25)
1024. Palindromic Number (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A number that will be the same when it转载 2015-08-23 09:55:23 · 322 阅读 · 0 评论 -
A1075 . PAT Judge (25)
1075. PAT Judge (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ranklist of PAT is generated from the status转载 2015-08-22 16:15:24 · 360 阅读 · 0 评论 -
A1015. Reversible Primes (20)
1015. Reversible Primes (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A reversible prime in any number system转载 2015-08-22 20:37:35 · 357 阅读 · 0 评论
分享