码迷,mamicode.com
首页 > 其他好文 > 详细

标题:方格计数

时间:2019-10-25 18:27:06      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:inf   图片   oid   ati   for   ++   http   void   sys   

// x^2+y^2=r^2
    private static int work2(int n) {
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                int d = i * i + j * j;
                if (d <= n * n) {
                    ++ans;//一个象限的个数
                }
            }
        }
        return ans * 4;
    }

    public static void main(String[] args) {
        System.out.println(work2(2));//半径
    }

技术图片

 

 这就需要一点数学知识啦。

标题:方格计数

标签:inf   图片   oid   ati   for   ++   http   void   sys   

原文地址:https://www.cnblogs.com/hardhp74520/p/11739148.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!