Netease's 2017 autumn tricks-elegance

Source: Internet
Author: User

After so many programming questions, I feel that the code implementation is very easy as long as I find the ideas for the questions, because Baidu can be a place where the programming languages are not familiar,

However, there is no way to search for a question, unless it is ready to be searched.

This question is very easy to solve. We use the O (n2) algorithm to traverse and find the coordinate points on the non-X and Y axes + = 4 + = 2 on the x y axis.

It took 3 minutes to think about it and 2 minutes to code it.

package com.net163.question;import org.junit.Test;/** * Created by Administrator on 2016/11/11 0011. */public class CircleElegantPoint {    private int number = 25;    private int  count = 0;    @Test    public void countElegantPoint(){        Integer i = Double.valueOf( Math.sqrt(number)).intValue();        for(int j = 0 ;  j <= i ; j++){            //System.out.println(j);            for(int g = 0 ; g <=i; g++){                if ((Math.pow(j,2)+Math.pow(g,2)) == number){                    if (j==0 || g == 0){                        count +=2;                    }else{                        count +=4;                    }                }            }        }        System.out.println(count);    }}

 

Netease's 2017 autumn tricks-elegance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.