Loading
NOIP2006普及組 開心的金明
NOIP2004提高組 合併果子

NOIP2006普及組 明明的隨機數

Freddy posted @ 2011年10月08日 03:10 in NOIP with tags NOIP c++ 模擬 , 10246 阅读

【问题描述】
    明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了 N 个 1 到 1000 之间的随机整数( N ≤ 100 ),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从小到大排序,按 照 排好的顺序去找同学做调查。请你协助明明完成“去重”与“排序”的工作。

【输入格式】
     输入文件 random.in 有 2 行,第 1 行为 1 个正整数,表示所生成的随机数的个数:N

     第 2 行有 N 个用空格隔开的正整数,为所产生的随机数。

【输出格式】
     输出文件 random.out 也是 2 行,第 1 行为 1 个正整数 M ,表示不相同的随机数的个数。第 2 行为 M 个用空格隔开的正整数,为从小到大排好序的不相同的随机数。

【输入输出样例】
 
输入:
10
20 40 32 67 40 20 89 300 400 15
 

输出:
8
15 20 32 40 67 89 300 400

【分析】

水題,直接模擬。

//NOIP2006-Junior-Random
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int Compare(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}

int main()
{
	freopen("random.in","r",stdin);
	freopen("random.out","w",stdout);
	int num[101]={0};
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&num[i]);
	int reduce=0;
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			if (num[j]!=1001 && num[i]!=1001 && num[j]==num[i])
				{
					num[j]=1001;
					reduce++;
				}
	qsort(num+1,n,sizeof(int),Compare);
	cout<<n-reduce<<endl;
	for(int i=1;i<=n-reduce;i++)
		cout<<num[i]<<" ";
	cout<<endl;
	return 0;
}

 

正在连接评测机...

 

已连接到评测机

GRID 1
名称 Flitty
系统版本 1.00
备注 COGS 1号评测机 Flitty

正在编译...

编译成功

 

测试点 结果 得分 运行时间 内存使用 退出代码
1 正确 10 0.018 s 273 KB 0
2 正确 10 0.001 s 273 KB 0
3 正确 10 0.001 s 273 KB 0
4 正确 10 0.001 s 273 KB 0
5 正确 10 0.001 s 273 KB 0
6 正确 10 0.001 s 273 KB 0
7 正确 10 0.001 s 273 KB 0
8 正确 10 0.001 s 273 KB 0
9 正确 10 0.001 s 273 KB 0
10 正确 10 0.001 s 273 KB 0

运行完成

运行时间 0.024 s

平均内存使用 273 KB

测试点通过状况 AAAAAAAAAA

得分:100

恭喜你通过了全部测试点!

Amy Abbott 说:
2019年10月20日 19:33

Today it is conceivable to tackle the abnormal, capricious nature of subatomic particles and use them to perform figurings inside a quantum PC. With only a couple of lines of code, we can program a genuine quantum PC to create genuine irregular numbers for us. Something already outlandish utilizing an old style, Turing based PC. Avoid Mental Break Down At University


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter