hihocoder 八十八 A
2016-03-06 00:18
417 查看
题目1 : Coordinates
时间限制:10000ms单点时限:1000ms
内存限制:256MB
描述
Give you two integers P and Q. Let all divisors of P be X-coordinates. Let all divisors of Q be Y-coordinates.For example, when P=6 and Q=2, we can get the coordinates (1,1) (1,2) (2,1) (2,2) (3,1) (3,2) (6,1) (6,2).
You should print all possible coordinates in the order which is first sorted by X-coordinate when coincides, sorted by Y-coordinate.
输入
One line with two integers P and Q(1 <= P, Q <= 10000).输出
The output may contains several lines , each line with two integers Xi and Yi, denoting the coordinates.样例输入
6 2
样例输出
1 1 1 2 2 1 2 2 3 1 3 2 6 1 6 2
题目大意:找到两个数的约数,然后分组输出;
PS:特别注意变量的存储,要单独存,不能顺着数组,不然不好搜;
AC代码:
#include <iostream> #include <cmath> #include <cstring> #include <algorithm> using namespace std ; int dp[50000],dq[50000]; int main() { int n , m; cin>>n>>m; int pcount,qcount; pcount=qcount=0; for(int i = 1 ; i<=n;i++) { if(n%i==0) { dp[pcount]=i; pcount++; } } for(int i = 1 ; i<=m;i++) { if(m%i==0) { dq[qcount]=i; qcount++; } } for(int i = 0 ;i<pcount;i++) { for(int j=0;j<qcount;j++) { printf("%d %d\n",dp[i],dq[j]); } } }
相关文章推荐
- 接口、抽象类
- 《Pro JavaScript Techniques》中的一些函数
- 判断浏览器类型及版本
- 原生ajax
- 封装toDuble (获取时间对象时的补零处理)
- UIView和CALayer有什么关系
- Nyoj 990 蚂蚁感冒(思维)
- 统计java代码文件的代码行数(空行、注释不能计数)
- 每天一个linux命令(51):lsof命令
- html的textarea用作“使用说明框”真的非常适合
- android平台手电筒开发源代码
- Map.putAll() 使用方法 简单易懂
- try里面抛异常
- 你真的了解AsyncTask?
- Android Studio——Android获取屏幕宽度的4种方法
- 每天一个linux命令(52):ifconfig命令
- vb.net中xml操作实例
- 设计模式——工厂模式
- 什么是method swizzling
- 每天一个linux命令(53):route命令