![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PAT
文章平均质量分 69
zydtssyx
这个作者很懒,什么都没留下…
展开
-
1028. List Sorting
#include #include #include typedef struct stu { int id; char name[9]; int grade;}stu;int comp1(const void*a, const void*b);int comp2(const void*a, const void*b);int comp3(const void*a, co原创 2017-02-26 00:05:14 · 215 阅读 · 0 评论 -
1102. Invert a Binary Tree
好久没做树的题啦!#include #include typedef struct TreeNode{ int left; int right;}Node;typedef struct Queue { int data[100]; int front; int rear;}Queue;Node T[20];int cnt = 0,n;Queue Q;void Level原创 2017-02-22 22:21:58 · 200 阅读 · 0 评论 -
1105. Spiral Matrix
一开始居然怎么都想不到思路。#include #include #include #define MaxSize 100int comp(const void *a, const void *b);int main(){ int N,m,n,i,j,Matrix[MaxSize][MaxSize]; scanf("%d",&N); int *data = (int*)malloc原创 2017-02-22 19:08:00 · 190 阅读 · 0 评论 -
1110. Complete Binary Tree
所以说,乞丐版队列还是很好用的……原创 2017-02-22 18:58:44 · 220 阅读 · 0 评论 -
1036. Boys vs Girls
#include #include typedef struct Grade { char Name[11]; char ID[11]; char Gender; int grade;}Grade;int main(){ int n,i,FemaleMax=-1,MaleMin=101,FNum,MNum; scanf("%d", &n); Grade *data =原创 2017-01-26 18:30:09 · 160 阅读 · 0 评论 -
1043. Is It a Binary Search Tree
这道题……没想到镜像BST和BST先序怎么转换,直接复制了一下函数。#include #include int IsBST(int Pre[],int begin,int end,int Post[],int PosBegin,int PosEnd);int IsMBST(int Pre[], int begin, int end, int Post[], int PosBegin, in原创 2017-01-25 22:47:50 · 184 阅读 · 0 评论 -
1101. Quick Sort
崩溃啊,第三个测试点格式错误,百度了一下简直拍桌子,没数据的时候要输出两个回车……= =考试的时候遇到这种情况我可能要画圈圈了……控诉一下win10,提交看结果的时候你就断网是不是跟爸爸过不去??#include #include /*快速排序一趟使主元落在最终位置,因此就是排序好的*/int main(){ int n,i,cnt; scanf("%d", &n); long原创 2017-01-24 23:11:50 · 234 阅读 · 0 评论 -
1094. The Largest Generation
把上一题代码稍微改了一下。#include #include typedef struct EdgeNode { int ID; struct EdgeNode* next;}EdgeNode, *PEdgeNode;typedef struct VNode { int UserID; PEdgeNode FirstChild;}VNode;typedef int Posit原创 2017-02-13 23:30:00 · 184 阅读 · 0 评论 -
*1076. Forwards on Weibo
用C写真是吃力= =#include #include typedef struct EdgeNode { int UserID; struct EdgeNode* next;}EdgeNode,*PEdgeNode;typedef struct VNode { int UserID; PEdgeNode FirstForward;}VNode;typedef int P原创 2017-02-13 21:15:35 · 365 阅读 · 0 评论 -
1029. Median
一开始拼命想王道上一道题,好像那是两个序列大小相同的?用了一半的归并。#include #include /*4 1 5 6 83 2 4 8*/int main(){ long n1, n2,i,j,mid,cnt=0,num; scanf("%ld",&n1); long *seq1 = (long*)malloc(sizeof(long)*n1); for (i = 0原创 2017-01-24 16:12:23 · 135 阅读 · 0 评论 -
1051. Pop Sequence
这道题以前mooc上做过,记得是差几个测试点,死活AC不了。这次居然一次过了。要注意吃掉判断no之后的数据。思路是要么往pop栈顶元素,要么放入几个之后pop。#include #include int main(){ int m, n, i, k, num,flag,Pop,Top,Max; scanf("%d %d %d", &m, &n, &k); while (k--) {原创 2017-01-23 21:59:16 · 361 阅读 · 0 评论 -
1089. Insert or Merge
Merge函数写得乱了,听着鞭炮声敲代码= =#include #include int FindStep(int sorted[], int step,int n);void Merge(int sorted[], int step,int NextStep[],int n);int main(){ int n, i = 0, Isinsertion = 1, Pos; scan原创 2017-01-29 00:39:03 · 184 阅读 · 0 评论 -
1117. Eddington Number
希望都是这种题哈哈。#include #include int comp(const void*a, const void*b);int main(){ int n, i,data[100000],e,j; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &data[i]); qsort(data, n, sizeof(原创 2017-02-23 16:08:56 · 191 阅读 · 0 评论 -
1083. List Grades
#include #include typedef struct stu { char name[11]; char id[11]; int grade;}stu;int comp(const void *a, const void*b);int main(){ int n, i,grade1, grade2,flag=0; stu student[1000]; scanf原创 2017-02-25 23:16:41 · 205 阅读 · 0 评论 -
1042. Shuffling Machine
#include void ConvertPrint(int x);int main(){ int k, card[54], next[54],i,pos,times; scanf("%d", &k); for (i = 0; i < 54; i++) scanf("%d", &next[i]); for (i = 0; i < 54; i++) { pos = i;原创 2017-02-25 22:46:51 · 195 阅读 · 0 评论 -
1122. Hamiltonian Cycle
#include int main(){ int G[200][200],i,j,VertexNum,EdgeNum,v1,v2,k,SeqSize,IsHC,visited[200]; int seq[1000]; scanf("%d %d", &VertexNum, &EdgeNum); for (i = 0; i < VertexNum; i++) for (j = 0;原创 2017-02-25 21:59:23 · 223 阅读 · 0 评论 -
1121. Damn Single
#include #define MaxSize 100000typedef struct people { int partner; int IsGuset;}people;int main(){ int n,m,couple1,couple2,guest,cnt,single[MaxSize],i; people data[MaxSize]; for (i = 0; i <原创 2017-02-25 16:33:54 · 372 阅读 · 0 评论 -
1081. Rational Sum
#include #include #include /*能不能不用字符串转化为整数?*/typedef struct Number { long long integer; long long numerator; long long denominator;}Number;long long Convert(char num[], int begin, int end);N原创 2017-02-25 00:01:54 · 245 阅读 · 0 评论 -
1004. Counting Leaves
#include typedef struct node { int first; int next;}node;int main(){ node tree[100]; int n, m,i,ChildNum,ID, ParentID,LeavesNum=0; scanf("%d %d", &n, &m); for (i = 0; i <= n; i++) tree[i].原创 2017-02-24 17:11:59 · 173 阅读 · 0 评论 -
1090. Highest Price in Supply Chain
#include typedef struct tree { int first; int next;}tree;int main(){ tree t[100000]; int n, i, supplier, Q[100000], front = 0, rear = 0, x, first = 0, cnt = 1, last = 1,root,level_num=1; doub原创 2017-02-24 14:54:33 · 155 阅读 · 0 评论 -
1097. Deduplication on a Linked List(测试点1)
L[100000]设为removed的头结点。#include #include typedef struct LinkList { int Key; int Next;}LinkList;int main(){ LinkList L[100001]; int Add, N, FirstAdd,check[10001],i,Removed; scanf("%d %d", &原创 2017-02-15 22:26:06 · 823 阅读 · 2 评论 -
1106. Lowest Price in Supply Chain
一开始犯蠢输出直接p*(1+r/100)*(1+r/100)居然还过了两个测试点拿了15分哈哈,机智地骗分~依旧乞丐版队列+乞丐版层次遍历。#include typedef struct tree { int first; int next;}tree;int main(){ tree t[100000]; int n, i, child_num, ID, Q[100000],原创 2017-02-23 23:10:27 · 168 阅读 · 0 评论 -
1118. Birds in Forest
#include int FindRoot(int Bird[],int bird);int main(){ int n, i, bird_num,first,bird,root,first_root,bird_sum=0,tree_sum=0; int Bird[10001]; for (i = 1; i <= 10000; i++) Bird[i] = 0; Bird[0]原创 2017-02-23 18:14:41 · 206 阅读 · 0 评论 -
1031. Hello World for U
最近只能在这种简单题上找一找自信了……#include #include int main(){ char sentence[81]; int n1, len,i,j,space; scanf("%s", sentence); len = strlen(sentence); n1 = (len + 2) / 3; for (i = 0,j=len-1; i < n1-1; i+原创 2017-01-31 19:01:14 · 305 阅读 · 0 评论 -
1035. Password
#include int main(){ int n,i,j,flag,modified=0,m[2000]; char Password[2000][11]; scanf("%d",&n); for (i = 0; i < 2 * n; i++) { scanf("%s", Password[i]); m[i] = 0; } for (i = 1; i < 2 * n;原创 2017-01-23 16:26:36 · 148 阅读 · 0 评论 -
1024. Palindromic Number
#include #include int IsPalindromic(int num[],int len);int Add(int num[],int num2[], int len);int main(){ int k,len,i,step=0,num[111],reversed[111]; long long n; scanf("%lld %d", &n,&k); f原创 2017-01-20 14:15:34 · 208 阅读 · 0 评论 -
1111. Online Map
#include #define MaxVNum 500#define INF 10000void dj(int l[][MaxVNum],int t[][MaxVNum],int path[], int S,int dist[],int n,int time[]);void dj2(int t[][MaxVNum], int path[], int S, int time[], int原创 2017-02-28 17:11:06 · 504 阅读 · 0 评论 -
1069. The Black Hole of Numbers
#include #include /*递减减递增的*/int main(){ int num, i=0, x[5], y[5], large,small,ans=0,temp,j; scanf("%d",&num); while (ans != 6174) { for (i = 0; i < 4;i++) { temp = num % 10; num /= 10;原创 2017-01-15 23:21:47 · 338 阅读 · 0 评论 -
1073. Scientific Notation
这次写的有点乱= =#include #include int main(){ char Num[10000]; int i, end= 0,exp=0,zero,dot; scanf("%s", Num); while (Num[end] != '\0') end++; end--; i = end; while (Num[i-1]!= 'E') { exp +=(原创 2017-01-15 00:14:09 · 287 阅读 · 0 评论 -
1037. Magic Coupon
#include #include /*从两组数中各选出一个相乘,求和的最大值*/void HeapSort(int a[],int n);void HeapAdjust(int a[], int i, int n);int main(){ int ans=0, nc, np,i,j; scanf("%d", &nc); int *Coupon = (int*)malloc(s原创 2017-02-05 21:20:51 · 204 阅读 · 0 评论 -
1034. Head of a Gang(2、5)
两个测试点2、5过不去嘤嘤嘤先放着回头收拾你。#include #include #define MaxSize 17576typedef struct Set { int time; int root; int total_time;}Set;int FindLoc(char p[]);int FindSet(int loc,Set Gang[]);void Convert原创 2017-02-05 16:09:39 · 643 阅读 · 3 评论 -
1078. Hashing
当d大于等于MSize时仍没有找到位置,就失败了。但这是为啥?#include #include #include int main(){ int MSize, N,flag,i,x; scanf("%d %d", &MSize, &N); if (MSize == 1) MSize = 2; else if (MSize > 2) { if (MSize % 2==原创 2017-01-09 23:11:04 · 188 阅读 · 0 评论 -
1021. Deepest Root
又一道DFS的题,来自于求树的深度的变体,我是这样解的啦,复习了一下邻接表。其他分析都在注释里了> #include #include /*节点由小到大依次求深度,j指示待插入的位置*//*属于稀疏图,不宜用邻接矩阵*/typedef struct ENode {/*边节点*/ int vetex; struct ENode *next;}ENode,*PENode;typed原创 2017-01-13 20:43:38 · 144 阅读 · 0 评论 -
*1033. To Fill or Not to Fill
不加target==n这个条件测试点1会出现超时=皿=没找到原因。很有价值的贪心题目!#include #define INFINITY 10000/*有时候不用加满油,只要加够向终点的油即可*/typedef struct Station { float price; float dist;}Station;Station GasS[501];int FindTarget(i原创 2017-02-04 16:31:17 · 350 阅读 · 0 评论 -
1013. Battle Over Cities
T_T心情超级不好啊啊啊啊。这道题想法挺简单的,DFS也做过好多遍了,想到了并查集但没弄清楚怎么做,留个问号在这里吧。选择的是邻接矩阵T口T,所幸有关图的数据量不大。#include /*t偷个懒用邻接矩阵*/int Graph[1000][1000];int visited[1000];int N;void Initvisted();void DFS(int原创 2017-01-08 21:44:25 · 149 阅读 · 0 评论 -
1104. Sum of Number Segments
注意double类型输入为%ld~其他没什么#include /*4,6,6,4 第i个元素,左边i种组合,右边n-i+1种)*/int main(){ int n; double ans=0,num; scanf("%d", &n); for (int i = 1; i <= n;i++) { scanf("%lf",&num); ans += num*i*(n - i原创 2017-01-04 19:57:16 · 165 阅读 · 0 评论 -
1098. Insertion or Heap Sort
#include #include void HeapAdjust(int a[], int i, int n);/*此处从0开始存放*//*从小到大排用的大根堆,堆顶元素a[0]>a[1]。插入排序a[0]a[1]必定有序,a[0]<a[1]*/int main(){ int n,i=0,Isinsertion=1,Pos; scanf("%d", &n); int *data原创 2017-01-04 17:43:31 · 206 阅读 · 0 评论 -
1085. Perfect Sequence
两天没刷题= =昨天这道题折腾了我一晚上,排序好后一开始用的递归,测试点3就超时了o(╯□╰)o缩小,。百度到一个很巧妙的方法,从最小数开始试探,满足条件则范围扩大一点,不满足则缩小,一直到范围尾端扩大到最大数,中途记录最大范围。#include#includevoid HeapSort(long a[],int size);void HeapAdjust(long a[], int i原创 2017-01-04 14:48:25 · 286 阅读 · 0 评论 -
1032. Sharing
这道题也折磨了好久, 崩溃T_T一开始用的静态链表,二重循环把word1串起来,同样方法串word2,遇到串过的地方就找到了。最后一组大数据超时了。第二次用的链表,最后一组居然内!存!超!过!了!!最后以空间换的时间,反正地址最多十#include typedef struct WordNode { char data; int NextA;}WordNode;WordNode Wor原创 2017-01-11 14:39:21 · 172 阅读 · 0 评论 -
1044. Shopping in Mars
#include #include #define INFINITY 100000int FindClosest(int a[],int m,int n,int e);/*e表示误差哈哈哈哈哈*//*i表示数列的的始端,若和大于给定值,,应放弃i开头的数列,始端向后移,否则尾端向后移*/int main(){ int n,m, i, e; scanf("%d %d", &n, &原创 2017-02-06 22:11:28 · 167 阅读 · 0 评论