链接1:http://acm.hrbust.edu.cn/index.php m=ProblemSet&a=showProblem&problem_id=1164
链接2:http://acm.hrbust.edu.cn/index.php m=ProblemSet&a=showProblem&problem_id=1287
Description:
用计算机随机生成了N个0到910305(包含0和910305)之间的随机整数(N≤100000000),对于其中重复的数字,只保留一个,把其余相同的数去掉。然后再把这些数从小到大排序。
请你完成“去重”与“排序”的工作。
输入有2行,第1行为1个正整数,表示所生成的随机数的个数:
N
第2行有N个用空格隔开的正整数,为所产生的随机数。
输出也是2行,第1行为1个正整数M,表示不相同的随机数的个数。第2行为M个用空格隔开的正整数,为从小到大排好序的不相同的随机数。
Sample Input:
10
20 40 32 67 40 20 89 300 400 15
Sample Output:
8
15 20 32 40 67 89 300 400
The following code :
#include#include #include #define MAXN 100000005 using namespace std; int Kesha[MAXN], Kay[MAXN]; int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int n; while(~scanf("%d", &n)) { for(int i=0; i
Description用计算机随机生成了N个0到1000000000(包含0和1000000000)之间的随机整数(N≤5000000),对于其中重复的数字,只保留一个,把其余相同的数去掉。然后再把这些数从小到大排序。
请你完成“去重”与“排序”的工作Input输入有2行,第1行为1个正整数,表示所生成的随机数的个数:
N
第2行有N个用空格隔开的正整数,为所产生的随机数。Output输出也是2行,第1行为1个正整数M,表示不相同的随机数的个数。第2行为M个用空格隔开的正整数,为从小到大排好序的不相同的随机数。Sample Input10
20 40 32 67 40 20 89 300 400 15Sample Output8
15 20 32 40 67 89 300 400
The following code :
#include#include #include int b[5000001], top; typedef struct Node { int count; struct node *left ; struct node *right; }node,*trie; void init(trie &p) { p = (trie)malloc(sizeof(node)); p->count = -1; p->left = NULL; p->right = NULL; } void add(trie &p, int m) { if(m == p->count) return; if(p->count==-1) { p->count = m; return; } if(m < p->count) { trie q; q = p->left; if(q == NULL) { init(q); p->left = q; } add(q, m); }else { trie q; q = p->right; if(q == NULL) { init(q); p->right = q; } add(q, m); } } void get(trie &p) { if(p) { get(p->left); b[top++] = p->count; get(p->right); } } int main() { int m, n; while(scanf("%d",&n)!=EOF) { trie root; init(root); for(int i=0;i