HDU 6055 Regular polygon 暴力枚举
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6055
题目描述: 给你n个整数点, 问你有多少个点组成了正多边形?
解题思路: 因为是整数点,所以只能组成正方形,固定两个点, 另外两个点的坐标如图所示
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> using namespace std; int a[500][500]; const int maxn = 205; int main() { int n, x, y; while( ~scanf( "%d", &n ) ) { memset(a, 0, sizeof(a)); for( int i = 0; i < n; i++ ) { scanf( "%d%d", &x, &y ); x += 100; y += 100; a[x][y] = 1; } int res = 0; for( int i = 0; i < maxn; i++ ) { for( int j = 0; j < maxn; j++ ) { if( a[i][j] ) { a[i][j] = 0; for( int p = i; p < maxn; p++ ) { for( int q = j+1; q < maxn; q++ ) { if( a[p][q] ) { int xdif = p - i; int ydif = q - j; if( a[p+ydif][q-xdif] && a[i+ydif][j-xdif] ) { res++; // cout << i << " " << j << endl; // cout << p << " " << q << endl; // cout << p+ydif << " " << q-xdif << endl; // cout << i+ydif << " " << j-xdif << endl; } } } } a[i][j] = 1; } } } printf( "%d\n", res ); } return 0; }
思考: 这是一道计算机和的水题, 昨天第一次知道了高数的重要性, 下个学期应该开始复习数学了
posted on 2017-07-28 11:01 FriskyPuppy 阅读(273) 评论(0) 编辑 收藏 举报