1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#include <iostream> #include <math.h> #include <stdio.h> using namespace std; int main() { double n,m,d1,d2; int cnt,n_cnt,c=0; while(cin>>n) { m=(n-0.5)*(n-0.5); cnt=0; n_cnt=0; for(int i=0;i<=n;i++) { for(int j=0;j<=n;j++) { d1=i*i+j*j; d2=(i+1)*(i+1)+(j+1)*(j+1); if(d1<m && d2<=m) { //cout<<i<<" "<<j<<" "<<i+1<<" "<<j+1<<"\n"; cnt++; } else if(d1<m && d2>m) n_cnt++; } } if(c) cout<<"\n"; c=1; cout<<"In the case n = "<<n<<", "<<4*n_cnt<<" cells contain segments of the circle.\n"; cout<<"There are "<<4*cnt<<" cells completely contained in the circle.\n"; } return 0; } |