| syhd142 |
|
|||
|
日歷
統計
導航常用鏈接留言簿(2)隨筆檔案(23)文章分類(270)
文章檔案(122)我的豆瓣搜索最新評論
|
園劃過的格子數可以退出公式,在園內的格子數我也推出了公式,但是后來發現錯了,這個要枚舉就行了。 兩行之間要有空行,最后一組數據不需要,害我多WA了一次。 #include <stdio.h>
int ans[151]; int main() { int n, a, b; for(int i = 1; i < 151; i++) { double r = i - 0.5; int sum = 0; for(int x = 1; x <= i; x++) { for(int y = 1; y <= i; y++) { if(x * x + y * y < r * r) sum++; } } ans[i] = 4 * sum; } bool mk = 0; while(~scanf("%d", &n)) { if(mk) printf("\n"); mk = 1; printf("In the case n = %d, %d cells contain segments of the circle.\n", n, 8 * n - 4); printf("There are %d cells completely contained in the circle.\n", ans[n]); } return 0; }
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|
| Copyright © Fucker | Powered by: 博客園 模板提供:滬江博客 |