SWEA 16910 원 안의 점

1 개요[ | ]

SWEA 16910 원 안의 점

2 C[ | ]

#include<stdio.h>
    
int countPoint(int n) {
    int x, y;
    int count = 0;
    for(x=1; x<=n; x++) {
        for(y=1; y<=n; y++) {
            if(x*x + y*y <= n*n) {
                count++;
            }
        }
    }
    return 4*count + 4*n + 1;
}
        
int main( ) {
	int T, N;
    scanf("%d", &T);
    for(int testcase=1; testcase<=T; testcase++) {
	    scanf("%d", &N);
        printf("#%d %d\n", testcase, countPoint(N));
    }
}

3 C++[ | ]

#include <cstdio>
using namespace std;
    
int countPoint(int n) {
    int x, y;
    int count = 0;
    for(x=1; x<=n; x++) {
        for(y=1; y<=n; y++) {
            if(x*x + y*y <= n*n) {
                count++;
            }
        }
    }
    return 4*count + 4*n + 1;
}
        
int main( ) {
	int T, N;
    scanf("%d", &T);
    for(int testcase=1; testcase<=T; testcase++) {
	    scanf("%d", &N);
        printf("#%d %d\n", testcase, countPoint(N));
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}