pat
文章平均质量分 69
sjifaasss
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
1012. The Best Rank (25)
1012. The Best Rank (25) To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we enco原创 2016-03-08 12:50:13 · 286 阅读 · 0 评论 -
1022. Digital Library (30)
建立book结构体,关键字排序,不需要高级查找算法就能AC 注意scanf不会吃回车,gets会吃回车 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 4原创 2016-03-11 17:30:51 · 217 阅读 · 0 评论 -
1024. Palindromic Number (25)
回文数,用字符串相加,设置一个进位存储 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include #include char n[200]; int k; bool ispal(char *s原创 2016-03-11 18:15:13 · 196 阅读 · 0 评论 -
1025. PAT Ranking (25)
排序,计算rank,输出,先对成绩进行计数然后计算rank 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #include #i原创 2016-03-11 21:23:41 · 217 阅读 · 0 评论 -
1050. String Subtraction (20)
遍历一遍S1,建立link到next相同的ascii码,从32到126 ASCII码搜索S2,若找到则删除S1中相应的character 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #include #include int first[128],last[12原创 2016-03-11 22:31:58 · 278 阅读 · 0 评论 -
1028. List Sorting (25)
结构体排序 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 #include #include #include int n,c; typedef struct{ char id[7]; char na原创 2016-03-11 22:51:33 · 248 阅读 · 0 评论 -
1033. To Fill or Not to Fill (25)
贪心,如果能到达下一个价格不高于当前的gas station,则买油到该station,否则买最大值 注意:有一个测试点是出发点没有gas station 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40原创 2016-03-12 00:11:06 · 332 阅读 · 0 评论 -
1099. Build A Binary Search Tree (30)
从小到大排序,然后preorder构建BST,然后levelorder 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53原创 2016-03-12 00:46:32 · 245 阅读 · 0 评论 -
1040. Longest Symmetric String (25)
假设s[0..n]的longest symmetric string的max characters已求出,且知道s[start..n]为symmetric string,若想知道加入第n+1个字符后是否改变max值,只需知道s[start-1..n+1]或s[start..n+1]是否是symmetric string,并求出start值使s[start..n+1]为symmetric strin原创 2016-03-12 19:31:12 · 250 阅读 · 0 评论 -
1111. Online Map (30)
dijkstra算法,增加一个判断最短路径条件,即相同距离增加一个时间判断,相同时间增加一个计数cnt判断,只需编写一个dijkstra函数,传递参数即可,每确定一个最短路径,记录该点的上一个位置,最后输出时用栈输出 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30原创 2016-03-13 17:14:56 · 956 阅读 · 0 评论 -
1021. Deepest Root (25)
幷查集和dfs,采用有向图的邻接表存储,邻接表判断adjacent vertex比较方便 由于只有n-1条边,当只有一个连通图时必无回路 在dfs过程中记录当前深度和最大深度 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36原创 2016-03-11 16:17:34 · 246 阅读 · 0 评论 -
1019. General Palindromic Number (20)
回文数判断问题,用int数组存储每个位数的值 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #include int n,b; int d[32]={0}; int digit=0; void trans(int n,int b){ while(n){ d[digit++]=n原创 2016-03-11 12:49:22 · 222 阅读 · 0 评论 -
1106. Lowest Price in Supply Chain (25)
backtracking, 使用binary tree存储,设置child和sibling指针,child=-1表示叶子节点 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 #i原创 2016-03-11 12:01:36 · 256 阅读 · 0 评论 -
1013. Battle Over Cities (25)
1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is vitally important to have all the原创 2016-03-08 16:36:41 · 234 阅读 · 0 评论 -
1014. Waiting in Line (30)
create the queue model with circular queues. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51原创 2016-03-08 19:38:37 · 285 阅读 · 0 评论 -
1015. Reversible Primes (20)
caution: 1 is not a prime 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #include int n,d,m; bool isprime(int k){ if(k==1) return false; for(int i=2;i*i<=k;i++)原创 2016-03-08 20:36:41 · 198 阅读 · 0 评论 -
1016. Phone Bills (25)
关键点: 1. 用qsort进行一次排序,由于qsort是不稳定的,所以不能分时间和名字两次排序 2. 费用计算问题,需考虑dd相等和hh相等的情况 3. total输出判断 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36原创 2016-03-09 00:10:15 · 213 阅读 · 0 评论 -
1086. Tree Traversals Again (25)
构造binary tree,然后后序遍历输出。 构造:记录当前结点p,若读入为Push i,则i为p的child,判断为左还是右child;若读入为Pop,则当前结点没有left child and(or) right child,然后寻找下一个right child未link的结点 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18原创 2016-03-10 16:46:50 · 211 阅读 · 0 评论 -
1103. Integer Factorization (30)
使用backtracking,一定要加入限制条件,否则测试点5会超时。 1.先把power为p的值计算好存放如数组中 2.设置两个栈,其中一个用于存放较大的sequence 3.从可能的最大factor开始dfs,这样就满足题目条件当sum相同时,输出大的sequence 4.计算最大值max,不超过n-k+1,并且调用dfs时传递max值,下一个factor的值从max开始计算 5原创 2016-03-11 00:13:50 · 516 阅读 · 0 评论 -
1104. Sum of Number Segments (20)
1 2 3 4 5 6 7 8 9 10 11 12 13 #include int n; double a,sum=0.0; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%lf",&a); sum+=(double)(n-i+1)*i*a; //转换为double值是必要的 }原创 2016-03-11 01:57:00 · 214 阅读 · 0 评论 -
1105. Spiral Matrix (25)
建个数组记录输出顺序 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40原创 2016-03-11 02:37:31 · 394 阅读 · 0 评论 -
1107. Social Clusters (30)
并查集,cluster[i] 记录hobby为i的人数,在union parent[]的时候把cluster也一同union 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45原创 2016-03-11 10:45:49 · 663 阅读 · 0 评论 -
1045. Favorite Color Stripe (30)
求最大不减子序列长度 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #include int n,m,l; int order[201]; int seq[10001]; int minorder[10001]; int max=0; int m原创 2016-03-13 23:35:05 · 258 阅读 · 0 评论
分享