SWEA 16910 원 안의 점

Jmnote (토론 | 기여)님의 2023년 10월 31일 (화) 02:31 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

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 }}