Pat
andyyang0212
这个作者很懒,什么都没留下…
展开
-
pat 1078 Hashing
知道二次探查的公式就原创 2014-10-05 12:25:43 · 343 阅读 · 0 评论 -
PAT(A) 1027
#includeint main(){ int r,g,b,a[3][2],i,j; scanf("%d%d%d",&r,&g,&b); a[0][0] = r / 13; a[0][1] = r % 13; a[1][0] = g / 13; a[1][1] = g % 13; a[2][0] = b / 13; a[2][1] = b % 13; printf("#");原创 2014-10-24 17:59:13 · 268 阅读 · 0 评论 -
PAT(A) 1029
如果长度为偶数,区中间的两个元素的前一个#include#includeint main(){ int *a,*b,*c; int m,n,mid,i,ap,bp,cp; scanf("%d",&m); a = (int *)malloc(sizeof(int)*m); for(i = 0;i<m;i++) scanf("%d",&a[i]); scanf("%d",&n原创 2014-10-24 22:33:55 · 297 阅读 · 0 评论 -
PAT(A) 1036
#include#include struct Heapstruct; typedef struct Heapstruct *PriorityQueue; #define MinData -1struct Heapstruct{ int capacity; int size; struct grade *a; }; struct grade{原创 2014-10-24 14:43:24 · 296 阅读 · 0 评论 -
PAT(A) 1046
每个数组元素储存到1的距离,否则最后一个点会超时原创 2014-10-24 19:21:47 · 341 阅读 · 0 评论 -
Project 3 Hashing
Given a hash table of size N, we can define a hash function H(x) = x%N. Suppose that the linear probing is used to solve collisions, we can easily obtain the status of the hash table with a given sequ原创 2014-10-25 16:51:19 · 885 阅读 · 2 评论 -
Pat 1055
#include#include#includestruct person{ int age; int worth; char name[9]; } ; int compare(struct person a,struct person b){ if(a.worth==b.worth) if(a.age == b.age) return -strcmp(a.na原创 2014-10-04 16:40:40 · 337 阅读 · 0 评论 -
PAT(A) 1009
#include#include#includeint main(){ double a[2][1001],b[2001]; int i,n,times,sum,j; double an; for(i = 0;i<=1000;i++) a[0][i] = a[1][i] = 0; for(i = 0;i<=2000;i++) b[i] = 0; for(i = 0;i<2原创 2014-10-12 17:57:39 · 255 阅读 · 0 评论 -
Pat(A) 1002
注意,两个多项式相加系数为零的项不能输出,原创 2014-10-12 12:05:40 · 259 阅读 · 0 评论 -
PAT(A) 1005
#include#includeint main(){ char num[101]; int sum,i; int a[3]; scanf("%s",num); i = 0; sum = 0; while(num[i]!='\0'){ sum += num[i] - '0'; i++; } a[2] = sum / 100; a[1] = (sum - a[2]*原创 2014-10-12 14:13:14 · 248 阅读 · 0 评论 -
PAT(A) 1006
#include#include#includeint main(){ int hour,minute,sec,n; int unlock,lock; char name[16]; char unlk[16],lk[16]; scanf("%d",&n); unlock = 24*3600; lock = 0; while(n--){ scanf("%s%d:%d:%d"原创 2014-10-12 14:40:48 · 282 阅读 · 0 评论 -
PAT(A) 1007
一开始以为是输出最大子序列和的起始位置o(╯□╰)o原创 2014-10-12 17:20:24 · 306 阅读 · 0 评论 -
PAT(A) 1008
#include#includeint main(){ int n,last,totaltime,now; scanf("%d",&n); last = 0; totaltime = 0; while(n--){ scanf("%d",&now); if(now>last) totaltime += (now - last)*6 + 5; else if(now<las原创 2014-10-12 17:29:34 · 278 阅读 · 0 评论 -
PAT(A) 1011
#includeint main(){ int a[3]; double odd[3]={0,0,0},num,product; int i,j; for(i = 0;i<3;i++) for(j = 0;j<3;j++){ scanf("%lf",&num); if(num>odd[i]){ odd[i] = num; a[i] = j; } } pro原创 2014-10-13 22:33:28 · 253 阅读 · 0 评论 -
PAT 1003
Dijkstra 算法的变形原创 2014-11-16 20:17:31 · 296 阅读 · 0 评论 -
PAT(A) 1012
#include#include#includestruct stud{ char name[7]; int a[3][2]; double aver; int arank;};void sort(struct stud *p,int flag,int n){ int i,j,min,index; struct stud tmp; if(flag<3){ for(i =原创 2014-10-14 13:20:38 · 307 阅读 · 0 评论 -
PAT(A) 1017
#include#include#define MinPQSize (10)struct HeapStruct; typedef struct HeapStruct *PriorityQueue;typedef struct bank ElementType;struct bank{ int num; int lasttime;} MinData;原创 2014-11-01 17:13:24 · 283 阅读 · 0 评论 -
PAT(A) 1014
#include#includestruct QueueRecord;typedef struct QueueRecord *Queue;struct list{ int custom; int num; int lasttime; int firsttime; Queue q;};struct QueueRecord{ int Capacity; int Fr原创 2014-11-01 15:52:44 · 487 阅读 · 0 评论 -
PAT(A) 1020
题意是已知中序遍历和后序遍历,原创 2014-10-31 20:38:06 · 307 阅读 · 0 评论 -
PAT(A) 1004
1.建立好邻接表2.BFS其中数组level记录每一曾原创 2014-10-19 16:10:51 · 275 阅读 · 0 评论 -
PAT(A) 1025
#include#include#includetypedef struct pat Element;struct pat{ char id[15]; int score; int local; int localrank; int totalrank;} stu[30005];int compare(struct pat a,struct pat b){ if(a.sco原创 2014-11-02 12:39:04 · 383 阅读 · 0 评论 -
PAT(A) 1058
#includeint main(){ int g,s,k,tmp1,tmp2; int a[3]; scanf("%d.%d.%d",&a[0],&a[1],&a[2]); scanf("%d.%d.%d",&g,&s,&k); tmp1 = (a[2] + k)/29; a[2] = (a[2] + k)%29; tmp2 = (tmp1 + a[1] + s)/17; a原创 2014-10-19 18:25:45 · 257 阅读 · 0 评论 -
PAT(A) 1061 (与PAT(B) 1014相同题目)
#includeint main(){char a[4][61],ch;int i,day,flag = 0;;scanf("%s%s%s%s",a[0],a[1],a[2],a[3]);for(i = 0;a[0][i] !='\0'&&a[1][i] != '\0';i++){ if(a[0][i] == a[1][i] &&(a[0][i]>='A'&&a[0][i]<='G原创 2014-10-19 18:25:05 · 269 阅读 · 0 评论 -
PAT(A) 1031
#include#includeint main(){ char str[90]; int len,n1,n2,n3,i,j,k; scanf("%s",str); len = strlen(str); if((len + 2)%3 == 0){ n1 = n2 = n3 = (len + 2)/3; } else if((len +2)%3){ n2 = (len +原创 2014-10-18 11:56:51 · 327 阅读 · 0 评论 -
PAT(A) 1015
输入10进制数,然后判断将它转换成radix进制后原创 2014-10-18 11:31:17 · 348 阅读 · 0 评论 -
PAT(A) 1019
#includeint main(){ int num[1000],i,digit,j,flag; long long n,radix; scanf("%Ld%Ld",&n,&radix); i = 0; while(n){ num[i++] = n % radix; n = n/radix; } digit = i-1; flag =0; for(i = 0,j =原创 2014-10-18 22:42:55 · 514 阅读 · 0 评论 -
PAT(A) 1084
#include#includechar str1[100],str2[100],str3[100];int main(){ int n; scanf("%s%s",str1,str2); int p1,p2,p3; int flag,i; p1 = p2 = p3 = 0; int len1 = strlen(str1); int len2 = strlen(str2);原创 2014-11-22 20:17:23 · 301 阅读 · 0 评论 -
PAT(A) 1023
#include#include void reverse(char *a,int n){ int i,j; char tmp; for(i = 0,j= n-1;i<=j;i++,j--){ tmp = a[i]; a[i] = a[j]; a[j] = tmp; }}void sort(char *a,int n){ int i,j; char tmp; fo原创 2014-10-19 22:43:04 · 277 阅读 · 0 评论 -
PAT(A) 1041 最后两个点超时
#include#includestruct list{ int num; int index;} *stu;void swamp(struct list *a,struct list *b){ struct list tmp; tmp = *a; *a = *b; *b = tmp;}struct list median3(struct list a[],int begi原创 2014-10-26 22:17:13 · 509 阅读 · 0 评论 -
PAT(A) 1086
push的顺序即为先序遍历pop的顺序为后序遍历根据先序遍历和后续原创 2014-11-22 19:31:58 · 311 阅读 · 0 评论 -
PAT(A) 1024
一开始数组开的不够大WA了一次原创 2014-11-01 23:34:04 · 316 阅读 · 0 评论 -
pat 1028
快排超时,让我想一想#include#include#includestruct list{ char id[10]; int grade; char name[15];} stu[1000005];int compare(struct list a,struct list b,int flag){ if(flag == 1) return strcmp(a.id,b.i原创 2014-10-26 11:21:00 · 324 阅读 · 0 评论 -
PAT 1018 (一个点没过)
#include#include#define Infinite 32767struct station{ int car; int send; int back; int distance; int parent; int visit;} vertix[505];int cmax,n,sp;int map[505][505];void Dijkstra(){ int原创 2014-12-21 23:30:06 · 858 阅读 · 0 评论 -
pat 1021
先用一次DFS来判断联通分量的个数(在网上看到很多题解用的是并查集来判断,以后学习一下),同时通过这次DFS找到距离最短的一个点证明之前,先介绍两个概念,一个是直径,树的deepest root到最远叶子的路径我们暂称直径,而deepest root和最远叶子节点则成为端点。 注明关键在于以下两点:从任意一个点dfs得到的最远点都是直径的端点。证明如下:原创 2015-01-31 11:36:13 · 218 阅读 · 0 评论 -
pat 1030
局部变量在debug的时候有些编译器会默认初始值为0,但是执行的时候不这么做,所以导致debug的结果是对的,然而真正执行时结果不对,这个要注意,差点被坑了,简单的Dijkstra的变形#include#include#define INIFINTE 32765int distance[510],path[510],cst[510];struct graph{ int dista原创 2015-01-31 22:57:27 · 264 阅读 · 0 评论 -
pat 1037
先从小到大拍列,负的和负的乘正的和正的乘#include#includeusing namespace std;int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int main(){ int np, nc, i, j; freopen("1.in", "r", stdin); scan原创 2015-02-02 11:23:50 · 237 阅读 · 0 评论 -
pat 1039
hash里存放学生,学生下面有课程构成链表,超时了%>_#include#include#include#include#define SIZE 5000using namespace std;struct list{ int course; struct list *next;};struct table{ char name[5]; struct list* hea原创 2015-02-04 21:46:04 · 338 阅读 · 0 评论 -
PAT 1016(一个点也没有过Σ( ° △ °|||)︴,不知道问题出在哪里)
#include#include#include#include#define MinSize (5)int TimeCost[24];using namespace std;typedef struct HeapStruct *BinaryHeap;typedef struct AVLtree *Node;typedef struct AVLtree *Position;ty原创 2014-12-14 18:25:23 · 360 阅读 · 0 评论 -
Pat 1040
题意是找最长对称子序列,我的算法先将子序列翻转,然后找最长公共连续子序列,同样是用动态规划,和LCS不同的是状态函数 #include<iostream>#include<string.h>using std::cin;using std::cout;using std::endl;char str[1010],rstr[1010];int m[1010][1010];int max(i原创 2015-02-05 21:54:32 · 283 阅读 · 0 评论 -
pat 1042
根据order进行n次排序#include<iostream>using std::cout;using std::cin;using std::endl;struct poke{ char name; int order; int num;} card[54];int order[54];int cmp(const void *a, const void *b){原创 2015-02-06 10:50:20 · 266 阅读 · 0 评论