
PTA
ZJU_fish1996
这个作者很懒,什么都没留下…
展开
-
[PTA] Review of Programming Contest Rules
#include#include#includeint min;//记录最小时间int max;//记录最多解题数int time, num, t0;char c[12][22];int visit[12];int t[12];//做出该题时间int d[12];int path[12];int count;int index[12];int size;void原创 2016-05-17 22:45:28 · 2857 阅读 · 0 评论 -
[PTA] List Leaves
#include<stdio.h>typedef struct node Tree;struct node{ int element; int left; int right;};Tree tree[10]; Tree queue[10];int ans[10];int cnt=0;int front,rear;void enqueue(Tree T)...原创 2016-01-06 23:28:51 · 979 阅读 · 1 评论 -
[PTA] Harry Potter's Exam
#include<stdio.h>#include<stdlib.h> #define INF 10000int d[105][105];int visit[105];int m;int flag;int count=0;void floyd(){ int i,j,k; int min,max,index; min=INF; index=...原创 2016-01-10 11:12:44 · 996 阅读 · 0 评论 -
[PTA] Shortest Path [1]
#include <stdio.h>#include <stdlib.h>typedef enum {false, true} bool;#define MaxVertexNum 10 /* maximum number of vertices */typedef int Vertex; /* vertices are numbered from 0...原创 2016-01-06 12:58:23 · 1147 阅读 · 0 评论 -
[PTA] Percolate Up and Down
#include <stdio.h>#include <stdlib.h>typedef int ElementType;#define MinData -1typedef struct HeapStruct *PriorityQueue;struct HeapStruct { ElementType *Elements; int Capa...原创 2016-01-06 12:13:05 · 1707 阅读 · 1 评论 -
[PTA] Topological Sort
#include <stdio.h>#include <stdlib.h>typedef enum {false, true} bool;#define MaxVertexNum 10 /* maximum number of vertices */typedef int Vertex; /* vertices are numbered from 0...原创 2016-01-06 11:38:20 · 1271 阅读 · 0 评论 -
[PTA] Count Connected Components
#include <stdio.h>#include <stdlib.h>typedef enum {false, true} bool;#define MaxVertexNum 10 /* maximum number of vertices */typedef int Vertex; /* vertices are numbered from 0...原创 2016-01-02 22:19:00 · 1553 阅读 · 0 评论 -
[PTA] Find More Coins
此题与整数划分为同一类型的题目,基本方法都是搜索+动态规划。 题意是给定总金额,硬币数值,输出恰好能够凑出总金额的硬币组合方法,由于是多解题,要求按字典序最小输出,处理这个字典序只需实现对数组进行排序,为了方便直接调用了stl::sort,然后在搜索的时候加上一些限定条件。 注意要考虑到重复金额的硬币,并由此作相应的剪枝操作,最后一个测试点估计含有大量无效重复数原创 2016-03-13 14:46:57 · 1502 阅读 · 0 评论 -
[PTA] Strongly Connected Components
算法参考了网上资料(Tarjan算法),嫌麻烦并没有使用给出的函数指针。#include <stdio.h>#include <stdlib.h>#define MaxVertices 10 /* maximum number of vertices */typedef int Vertex; /* vertices are numbered fr...原创 2016-01-02 20:58:22 · 4922 阅读 · 4 评论 -
[PTA] Self-printable B+ Tree
B+树已通过pta测试。原创 2016-03-14 22:18:31 · 6184 阅读 · 0 评论 -
Assignment 4 2-2
We can perform BuildHeap for leftist heaps by considering each element as a one-node leftist heap, placing all these heaps on a queue, and performing the following step: Until only one heap is on the原创 2016-03-27 18:29:29 · 3625 阅读 · 2 评论 -
[PTA] Shortest Path [3]
#include <stdio.h>#include <stdlib.h>typedef enum {false, true} bool;#define INFINITY 1000000#define MaxVertexNum 10 /* maximum number of vertices */typedef int Vertex; /* ver...原创 2015-12-26 15:48:31 · 2179 阅读 · 0 评论 -
[PTA] hashing(hard)
#include<stdio.h>#include<stdlib.h>#include<queue>#define MAX 1000using namespace std;struct node{ int x; int i; bool operator<(const node w)const{ return x>w.x; ...原创 2015-12-18 21:42:16 · 1499 阅读 · 0 评论 -
[PTA] File Transfer
#include<stdio.h>#define MAX 10005int p[MAX];int num[MAX];int find(int x){ int k,j,r; r=x; while(r!=p[r]) r=p[r]; k=x; while(k!= r) ...原创 2015-11-19 09:19:46 · 1010 阅读 · 1 评论 -
[PTA] Sort Three Distinct Keys
#include <stdio.h>#include <stdlib.h>typedef enum { true, false, maybe } Keys;typedef Keys ElementType;void Read( ElementType A[], int N ); /* details omitted */void MySort( Eleme...原创 2015-11-15 10:28:06 · 1429 阅读 · 0 评论 -
Assignment 6 2-4
Which one of the following is the lowest upper bound of T(n)T(n)T(n) for the following recursion T(n)=2T(n)+lognT(n) = 2T(\sqrt{n}) + \log nT(n)=2T(√n)+logn?(4分) 设 m =原创 2016-04-06 14:33:07 · 4857 阅读 · 1 评论 -
[PTA] Favorite Color Stripe
2 2 4 1 5 5 6 3 1 1 5 6 2 1 2 2 2 2 2 2 2 2 2 2 2 3 1 2 2 2 2 2 2 3 3 3 3 3 1 1 2 2 3 3 3 3 3 4 5 5 5 5 1 2 2 3 4 5 5 5 5 5 6 6 6 1 2 2 3 4 5 6 6 6 6 6 7#include#include#inclu原创 2016-04-12 15:17:23 · 1252 阅读 · 3 评论 -
[PTA] Huffman Codes
用C++的东西写,速度比较慢,需要靠运气卡过……如果完全用C编写,速度在50ms以下。 #include#include#include#include#include#include#includeusing namespace std;#define MAX 105int weight;int n;struct character{ char原创 2016-05-03 21:35:10 · 2299 阅读 · 7 评论 -
[PTA] Hashing
#include<stdio.h>#include<stdlib.h>#include<math.h>int a[10010];int ans[10010];int prime[10010];int m,n;void GetPrime(){ int MAX=10010; int i,j; prime[0]=0,prime[1]=0...原创 2016-01-06 18:54:50 · 1049 阅读 · 0 评论