设为首页 加入收藏

TOP

POJ 3090 Visible Lattice Points
2015-07-20 17:53:37 来源: 作者: 【 】 浏览:1
Tags:POJ 3090 Visible Lattice Points

Description

A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For example, the point (4, 2) is not visible since the line from the origin passes through (2, 1). The figure below shows the points (x, y) with 0 ≤ x, y ≤ 5 with lines from the origin to the visible points.

\

Write a program which, given a value for the size, N, computes the number of visible points (x<??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPjwvZW0+LCA8ZW0+PHN0cm9uZz55PC9zdHJvbmc+PC9lbT4pIHdpdGggMCCh3CA8ZW0+PHN0cm9uZz54PC9zdHJvbmc+PC9lbT4sIDxlbT48c3Ryb25nPnk8L3N0cm9uZz48L2VtPiCh3CA8ZW0+PHN0cm9uZz5OPC9zdHJvbmc+PC9lbT4uPC9wPgoKPHAgY2xhc3M9"pst">Input

The first line of input contains a single integer C (1 ≤ C ≤ 1000) which is the number of datasets that follow.

Each dataset consists of a single line of input containing a single integer N (1 ≤ N ≤ 1000), which is the size.

Output

For each dataset, there is to be one line of output consisting of: the dataset number starting at 1, a single space, the size, a single space and the number of visible points for that size.

Sample Input

4
2
4
5
231

Sample Output

1 2 5
2 4 13
3 5 21
4 231 32549
 
思路:实际上题目在说的时候已经为你提供了思路,那就是比较斜率了。只要是斜率没有出现的点,那么我们就可以加上这些点,我们发现,每多一个数,就意味着要多一个外层,我们只需要加上这些外层上的点就可以了,而且一个外层上的点是对称的!
所以AC代码:
#include
     
      
#include
      
        #include
       
         using namespace std; int a[1005][1005]; //用数组的标号代表x,y坐标,用数组的值表示斜率是否出现过 int b[1005]; //记录有多少个点 int gcd(int a,int b) { if(a
        
         

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++代码注释行和函数个数统计 下一篇block存储区域――如何验证block..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: