Advertisement
a53

points1

a53
Jul 22nd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. FILE *f=fopen("points.in","r");
  8. FILE *g=fopen("points.out","w");
  9. long long n=0;
  10. int r,x0,y0,x1,y1,x;
  11. fscanf(f,"%d",&r);
  12. for(x0=0,y0=r,x1=0,y1=r;x0!=r;x0=x1,y0=y1)
  13. {
  14. int circ=0,yCirc=y0,line=0,yLine=y0;
  15. /// gasim urmatorul punct (x1, y1) pe cerc, mentinand
  16. /// limita inferiosara din cerc
  17. do
  18. {
  19. circ +=2*x1+1,++x1;
  20. while(circ>0)
  21. circ-=2*y1-1,--y1;
  22. } while(circ);
  23. /// adaugam contributia pentru punctele (x, *) cu x0 <= x < x1
  24. /// acest lucru poate fi calculat usor prin mentinerea limitei inferioare
  25. /// pentru cerc si linia (x0, y0) <-> (x1, y1)
  26. for(x=x0;x<x1;++x)
  27. {
  28. circ+=2*x+1;
  29. while(circ>0)
  30. circ-=2*yCirc-1,--yCirc;
  31. line-=y1-y0;
  32. while(line>0)
  33. line-=x1-x0,--yLine;
  34. n+=yCirc-yLine;
  35. }
  36. }
  37. fprintf(g,"%lld",4*n);
  38. fclose(f);
  39. fclose(g);
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement