LOJ 1109 - False Ordering (排序)
来源:互联网 发布:淘宝日系男装店铺排行 编辑:程序博客网 时间:2024/04/30 14:13
PDF (English)StatisticsForum
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
题意:将1到1000的所有数按照他的因子个数从小到大排列,如果有相同的因子个数,则最大的那个数排在前面,然呢输出第n个数
思路:结构体排序加打表
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;struct Node{int x,y;int ans;}node[1010];bool cmp(Node a,Node b){if(a.ans == b.ans) return a.x > b.x;else return a.ans < b.ans;}void dabiao(){for(int i = 1 ; i <= 1000 ; i++){node[i].x = i;node[i].y = i;}node[1].ans = 1;for(int i = 2 ; i <= 1000 ; i++){int k = sqrt(i);if(k * k == i) node[i].ans--;for(int j = 1 ; j <= k; j++) { if(node[i].y % j == 0) node[i].ans += 2; } }}int main(){int t,kcase = 1;dabiao();sort(node+1,node+1001,cmp);int n;scanf("%d",&t);while(t--){scanf("%d",&n); printf("Case %d: %d\n",kcase++,node[n].x);}return 0;}
- LOJ 1109 - False Ordering (排序)
- lightoj 1109 - False Ordering 因式分解+排序
- 【LightOJ】1109 - False Ordering(打表)
- 【light-oj】-1109 - False Ordering(数学)
- LightOJ 1109 False Ordering
- LightOJ 1109 False Ordering
- Light OJ 1109 - False Ordering
- lightoj-1109 - False Ordering【思维】
- False Ordering
- LightOJ 1109 - False Ordering (因子数打表排列)
- LIGHT OJ 1109 - False Ordering 【因子个数】
- LightOJ1109 False Ordering 筛法求约数个数+结构体排序
- lightoj1109 - False Ordering
- Ordering Tasks(拓扑排序)
- Lightoj1109——False Ordering(简单数学)
- Lightoj1109——False Ordering(数学+结构体)
- uva 10305 Ordering Tasks(拓扑排序)
- [UVA 10305] Ordering Tasks (拓扑排序)
- Ubuntu 入坑第一天
- 丑数
- 医院门诊管理系统--华为OJ
- HttpServletRequest对象中的常用个的方法
- 1032 挖掘机技术哪家强
- LOJ 1109 - False Ordering (排序)
- Item1 Understand template type deduction
- java servlet的tomcat
- mysql sql语句优化细节
- iconv 文件编码转换
- 1033 旧键盘打字
- Period--KMP,最小循环节
- Android 拖动滑出滑入的布局 自定义ViewDragHelper详解
- 作者(zhang854429783) eclipse通过tomcat热部署web项目