pat
文章平均质量分 92
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 · 232 阅读 · 0 评论 -
1022. Digital Library (30)
建立book结构体,关键字排序,不需要高级查找算法就能AC注意scanf不会吃回车,gets会吃回车1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484原创 2016-03-11 17:30:51 · 177 阅读 · 0 评论 -
1024. Palindromic Number (25)
回文数,用字符串相加,设置一个进位存储1234567891011121314151617181920212223242526272829303132333435363738#include #include char n[200];int k;bool ispal(char *s原创 2016-03-11 18:15:13 · 159 阅读 · 0 评论 -
1025. PAT Ranking (25)
排序,计算rank,输出,先对成绩进行计数然后计算rank1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950#include #i原创 2016-03-11 21:23:41 · 175 阅读 · 0 评论 -
1050. String Subtraction (20)
遍历一遍S1,建立link到next相同的ascii码,从32到126 ASCII码搜索S2,若找到则删除S1中相应的character123456789101112131415161718192021222324252627#include #include int first[128],last[12原创 2016-03-11 22:31:58 · 233 阅读 · 0 评论 -
1028. List Sorting (25)
结构体排序123456789101112131415161718192021222324252627282930313233343536#include #include #include int n,c;typedef struct{ char id[7]; char na原创 2016-03-11 22:51:33 · 203 阅读 · 0 评论 -
1033. To Fill or Not to Fill (25)
贪心,如果能到达下一个价格不高于当前的gas station,则买油到该station,否则买最大值注意:有一个测试点是出发点没有gas station12345678910111213141516171819202122232425262728293031323334353637383940原创 2016-03-12 00:11:06 · 280 阅读 · 0 评论 -
1099. Build A Binary Search Tree (30)
从小到大排序,然后preorder构建BST,然后levelorder1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253原创 2016-03-12 00:46:32 · 202 阅读 · 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 · 200 阅读 · 0 评论 -
1111. Online Map (30)
dijkstra算法,增加一个判断最短路径条件,即相同距离增加一个时间判断,相同时间增加一个计数cnt判断,只需编写一个dijkstra函数,传递参数即可,每确定一个最短路径,记录该点的上一个位置,最后输出时用栈输出123456789101112131415161718192021222324252627282930原创 2016-03-13 17:14:56 · 910 阅读 · 0 评论 -
1021. Deepest Root (25)
幷查集和dfs,采用有向图的邻接表存储,邻接表判断adjacent vertex比较方便由于只有n-1条边,当只有一个连通图时必无回路在dfs过程中记录当前深度和最大深度123456789101112131415161718192021222324252627282930313233343536原创 2016-03-11 16:17:34 · 206 阅读 · 0 评论 -
1019. General Palindromic Number (20)
回文数判断问题,用int数组存储每个位数的值1234567891011121314151617181920212223#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 · 181 阅读 · 0 评论 -
1106. Lowest Price in Supply Chain (25)
backtracking,使用binary tree存储,设置child和sibling指针,child=-1表示叶子节点123456789101112131415161718192021222324252627282930313233343536373839404142#i原创 2016-03-11 12:01:36 · 211 阅读 · 0 评论 -
1013. Battle Over Cities (25)
1013. Battle Over Cities (25)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueIt is vitally important to have all the原创 2016-03-08 16:36:41 · 198 阅读 · 0 评论 -
1014. Waiting in Line (30)
create the queue model with circular queues.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051原创 2016-03-08 19:38:37 · 243 阅读 · 0 评论 -
1015. Reversible Primes (20)
caution: 1 is not a prime1234567891011121314151617181920212223#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 · 155 阅读 · 0 评论 -
1016. Phone Bills (25)
关键点:1. 用qsort进行一次排序,由于qsort是不稳定的,所以不能分时间和名字两次排序2. 费用计算问题,需考虑dd相等和hh相等的情况3. total输出判断123456789101112131415161718192021222324252627282930313233343536原创 2016-03-09 00:10:15 · 174 阅读 · 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的结点123456789101112131415161718原创 2016-03-10 16:46:50 · 176 阅读 · 0 评论 -
1103. Integer Factorization (30)
使用backtracking,一定要加入限制条件,否则测试点5会超时。1.先把power为p的值计算好存放如数组中2.设置两个栈,其中一个用于存放较大的sequence3.从可能的最大factor开始dfs,这样就满足题目条件当sum相同时,输出大的sequence4.计算最大值max,不超过n-k+1,并且调用dfs时传递max值,下一个factor的值从max开始计算5原创 2016-03-11 00:13:50 · 465 阅读 · 0 评论 -
1104. Sum of Number Segments (20)
12345678910111213#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 · 173 阅读 · 0 评论 -
1105. Spiral Matrix (25)
建个数组记录输出顺序 12345678910111213141516171819202122232425262728293031323334353637383940原创 2016-03-11 02:37:31 · 357 阅读 · 0 评论 -
1107. Social Clusters (30)
并查集,cluster[i] 记录hobby为i的人数,在union parent[]的时候把cluster也一同union123456789101112131415161718192021222324252627282930313233343536373839404142434445原创 2016-03-11 10:45:49 · 616 阅读 · 0 评论 -
1045. Favorite Color Stripe (30)
求最大不减子序列长度123456789101112131415161718192021222324252627282930#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 · 216 阅读 · 0 评论