- 博客(21)
- 收藏
- 关注
原创 NEUOJ 1176 Problem: Easy to improve
There are n numbers in array a and a function f whose code is:ans = 0;for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { ans += pow (a[i]+a[j], 3); ans %= 1000000007; }}return ans;JieBa said, it's easy to improve the time c
2017-05-31 18:50:37 196
原创 11-散列2 Hashing (25分)
The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be H(key)=key%TSizeH(key) = key \% TSizeH(key)=key%TSize where TSizeTSizeT
2017-05-29 22:00:26 673
原创 11-散列1 电话聊天狂人 (25分)
给定大量手机用户通话记录,找出其中通话次数最多的聊天狂人。输入格式:输入首先给出正整数NNN(≤105\le 10^5≤105),为通话记录条数。随后NNN行,每行给出一条通话记录。简单起见,这里只列出拨出方和接收方的11位数字构成的手机号码,其中以空格分隔。输出格式:在一行中给出聊天狂人的手机号码及其通话次数,其间以空格分隔。如果这样的人不唯一,则输出狂人中最小的号码及其通话次数,并且附加给出并列狂人的人数。
2017-05-29 20:38:52 557
原创 10-排序6 Sort with Swap(0, i) (25分)
Given any permutation of the numbers {0, 1, 2,..., N−1N-1N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may apply the swap operations in the fo
2017-05-29 15:13:26 505
原创 10-排序5 PAT Judge (25分)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT.
2017-05-28 21:17:03 252
原创 09-排序2 Insert or Merge (25分)
#include #include void Merge(int a[], int temp[], int ll, int rl, int rh) { int lh = rl-1, length = rh-ll+1, tl = ll; while(ll <= lh && rl <= rh) { if(a[ll] <= a[rl]) temp[tl++] = a
2017-05-28 11:49:53 449
原创 09-排序1 排序 (25分)
//排序#include #include #include #define MAXN 100005void Swap(int *a, int *b) { int t = *a; *a = *b; *b = t;}void Bubble_Sort(int a[], int n) { int i, j, flag; for(i = n; i > 0; i--
2017-05-28 10:58:37 356
原创 08-图9 关键活动 (30分)
/*这题就是拓扑排序找关键路径,按照陈老师所讲的算法,先建立一个正向链接的邻接表,在建立一个反向链接的邻接表来记录出度与入读,注意关键路径是指决不允许延误的活动D = Lt[j] - Et[i] - C*/#include #include #include #define Maxn 1005#define INF -100005#define M 100005//建立邻接表所
2017-05-27 16:40:30 603
原创 08-图7 公路村村通 (30分)
#include #include #include #define Maxn 1005#define INF 100005typedef struct GNode* MGraph;struct GNode { int Nv, Ne; int G[Maxn][Maxn];};typedef struct AdjNode* AdjList;struct AdjNo
2017-05-26 10:39:22 533
原创 07-图6 旅游规划 (25分)
#include #include #include #define MAXN 505#define INF 100005typedef struct ENode* Edge;struct ENode { int v1, v2; int w1, w2;};typedef struct GNode* Graph;struct GNode { int Nv
2017-05-25 21:18:34 1425
原创 07-图5 Saving James Bond - Hard Version (30分)
#include #include #include #define MAXN 105#define R 7.5//记录鳄鱼~~节点坐标struct Node { int x, y;}V[MAXN];int n, d;int cnt = 0, temp;int G[MAXN][MAXN];int D[MAXN], P[MAXN], t[MAXN];int Dis
2017-05-24 21:03:26 436
原创 06-图3 六度空间 (30分)
六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示。图1 六度空间示意图“六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图验证这个理论始终是许多社会学家努力追求的目标。然而
2017-05-23 13:51:06 415
原创 06-图2 Saving James Bond - Easy Version (25分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land
2017-05-22 21:10:23 206
原创 06-图1 列出连通集 (25分)
给定一个有NNN个顶点和EEE条边的无向图,请用DFS和BFS分别列出其所有的连通集。假设顶点从0到N−1N-1N−1编号。进行搜索时,假设我们总是从编号最小的顶点出发,按编号递增的顺序访问邻接点。输入格式:输入第1行给出2个整数NNN(0输出格式:按照"{ v1v_1v1 v2v_2v2 ... vkv_kvk }"的格式,每行输出一个连通集。先输出DF
2017-05-21 11:22:21 265
原创 05-树9 Huffman Codes (30分)
In 1953, David A. Huffman published his paper "A Method for the Construction of Minimum-Redundancy Codes", and hence printed his name in the history of computer science. As a professor who gives the f
2017-05-20 16:00:32 1618 1
原创 05-树8 File Transfer (25分)
05-树8 File Transfer (25分)We have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer to another. Is it possible
2017-05-17 18:13:55 340
原创 05-树7 堆中的路径 (25分)
将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数NNN和MMM(≤1000\le 1000≤1000)NNN个要被插入一个初始为空的小顶堆的整数。最后一行给出MMM个下标。输出格式:对输入中给出的每个下标i,在一行中输出从H[i]到根结点的路径上的数据。数字间以1个空格分隔,行末不得有多
2017-05-16 16:56:33 543
原创 04-树7 二叉搜索树的操作集 (30分)
04-树7 二叉搜索树的操作集 (30分)本题要求实现给定二叉搜索树的5种常用操作。函数接口定义:BinTree Insert( BinTree BST, ElementType X );BinTree Delete( BinTree BST, ElementType X );Position Find( BinTree BST, ElementType X );Po
2017-05-15 13:16:27 498
原创 04-树6 Complete Binary Search Tree (30分)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node's key.The right subtree of a node contains only nodes with keys greater th
2017-05-14 21:20:18 287
原创 04-树5 Root of AVL Tree (25分)
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property. Figures 1-4 illustrate t
2017-05-14 18:34:08 227
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人