lightoj-1109 - False Ordering【思维】

本文提供了一道名为1109-FalseOrdering的编程题的解答思路及实现代码。该题要求根据整数1到1000的除数数量进行特殊排序,并输出第n个数。通过结构体存储除数数量和对应的整数,使用自定义比较函数进行排序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:点击打开链接

1109 - False Ordering

Time Limit: 1 second(s)Memory Limit: 32 MB

We define b is a Divisor of a number a if a is divisible by b. So, the divisors of 12 are 1, 2, 3, 4, 6, 12. So, 12 has 6 divisors.

Now you have to order all the integers from 1 to 1000. x will come before y if

1)                  number of divisors of x is less than number of divisors of y

2)                  number of divisors of x is equal to number of divisors of y and x > y.

Input

Input starts with an integer T (≤ 1005), denoting the number of test cases.

Each case contains an integer n (1 ≤ n ≤ 1000).

Output

For each case, print the case number and the nth number after ordering.

Sample Input

Output for Sample Input

5

1

2

3

4

1000

Case 1: 1

Case 2: 997

Case 3: 991

Case 4: 983

Case 5: 840



题解:刚开始想到结构体,然后不敢写,然后想了其他办法,果断没想到,就回来做了,真ZZ

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n;
struct node
{
	int id,shu;
}a[1000010];
bool cmp(node x,node y)
{
	if(x.id!=y.id)
		return x.id<y.id;
	else
		return x.shu>y.shu;
}
void get()
{
	int num=1;
	memset(a,0,sizeof(a));
	for(int i=1000;i>=1;i--)
	{
		int cnt=0;
		for(int j=1;j*j<=i;j++)
		{
			if(i%j==0)
			{
				cnt=cnt+2;
			}
			if(j*j==i)	cnt--;
		}
		a[num].shu=i;
		a[num++].id=cnt;
	}
	sort(a+1,a+1001,cmp);
//	for(int i=1;i<=100;i++)
//		printf("--%d--%d--\n",a[i].id,a[i].shu);
}
int main()
{
	int t,text=0;
	scanf("%d",&t);
	get();
	while(t--)
	{
		scanf("%d",&n);
		printf("Case %d: %d\n",++text,a[n].shu);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值