【light-oj】-1109 - False Ordering(数学)
2016-09-16 17:30
316 查看
1109 - False Ordering
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.
Each case contains an integer n (1 ≤ n ≤ 1000).
读懂题意就很好做了!
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
struct node
{
int n,num;
}a[1010];
bool cmp(node x,node y)
{
if(x.num==y.num)
return x.n>y.n;
return x.num<y.num;
}
int main()
{
int u,ca=1;
scanf("%d",&u);
for(int i=1;i<=1000;i++)
a[i].n=i;
for(int i=1;i<=1000;i++)
{
for(int j=1;j<=i;j++)
{
if(a[i].n%j==0)
a[i].num++;
}
}
sort(a+1,a+1001,cmp);
while(u--)
{
int n;
scanf("%d",&n);
printf("Case %d: %d\n",ca++,a
.n);
}
return 0;
}
PDF (English) | Statistics | Forum |
Time Limit: 1 second(s) | Memory Limit: 32 MB |
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 |
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
struct node
{
int n,num;
}a[1010];
bool cmp(node x,node y)
{
if(x.num==y.num)
return x.n>y.n;
return x.num<y.num;
}
int main()
{
int u,ca=1;
scanf("%d",&u);
for(int i=1;i<=1000;i++)
a[i].n=i;
for(int i=1;i<=1000;i++)
{
for(int j=1;j<=i;j++)
{
if(a[i].n%j==0)
a[i].num++;
}
}
sort(a+1,a+1001,cmp);
while(u--)
{
int n;
scanf("%d",&n);
printf("Case %d: %d\n",ca++,a
.n);
}
return 0;
}
相关文章推荐
- 【light-oj】-1104 - Birthday Paradox(数学,概率)
- light--oj--1116--Ekka Dokka(数学问题)
- 【Light-oj】-1138 - Trailing Zeroes (III)(二分,数学)
- light--oj--1294-- Positive Negative Sign(数学规律)
- 【Light-oj】-1043 - Triangle Partitioning(数学)
- Lightoj1109——False Ordering(数学+结构体)
- Light-oj-1282 Leading and Trailing(数学取位)
- 【light-oj】1136 - Division by 3(数学,规律)
- 【light-oj】-1189 - Sum of Factorials(思维,数学)
- Lightoj1109——False Ordering(简单数学)
- 杭电OJ(HDOJ)2036题:改革春风吹满地(几何,数学公式)
- 【HPU-oj】-Triangles(锐角三角形个数,数学,思维)
- 【Light-oj】-1282 - Leading and Trailing(数论,快速幂,log,好)
- 九度oj-1109-连通图
- 杭电oj数学题-1
- 【杭电oj】1568 - Fibonacci(数学)
- hpuoj 【1137】两数的距离【数学】
- light--oj--1078 - Integer Divisibility
- [Swust OJ 838]--最优价值(0-1背包+数学)
- 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】