Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem I. Alien Rectangles 数学
2016-08-13 01:53
633 查看
Problem I. Alien Rectangles
题目连接:
http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7022&all_runs=1&action=140Description
The spacecraft hovering above the surface of the faraway planet takes pictures of the landscape underneathfrom time to time. Each photo is a circle centred at the point the spacecraft is orbiting over.
For detailed study of the planet’s surface researchers have chosen a Cartesian coordinate system on the
photos with the origin placed to the circle’s centre. The radius of the circle is R. The following stage of
the research requires selecting a region in the form of a nondegenerate rectangle with sides parallel to the
coordinate axes and with vertices at the points with integer coordinates. The points should lie inside or
on the boundary of the circle.
Please help the researchers and compute the total number of ways to choose a rectangular region. As the
number of ways may be big, output it modulo 109 + 2015.
Input
Input contains the only integer R (1 ≤ R ≤ 1 000 000).Output
Output the only integer: the number of ways to choose a rectangle in the given circle modulo 109 + 2015.Sample Input
2Sample Output
9Hint
题意
有一个中心在原点的圆,然后半径为R,问你里面以及圆上的整点,能够成多少个矩形。题解:
算出每个坐标的点的个数,然后开始推公式就好了。具体看代码。
至于看到只有一个数,就去推O1公式的,基本就走远了……
代码
#include <bits/stdc++.h> using namespace std; const int N=1000100; const int pr=1e9 + 2015; long long ans=0; int main() { int R; scanf("%d",&R); int nx=1; for(int i=1;i<=R;i++) { int x=i*2+1; int y=(int)sqrt(1LL*R*R-1LL*i*i)*2+1; long long t1,t2; t1=1LL*x*(x-1)/2LL,t2=1LL*y*(y-1)/2LL; if(t1>=pr) t1%=pr; if(t2>=pr) t2%=pr; ans+=(t1*t2%pr); if(ans>=pr) ans%=pr; t1=1LL*nx*(nx-1)/2LL,t2=1LL*y*(y-1)/2LL; if(t1>=pr) t1%=pr; if(t2>=pr) t2%=pr; ans-=(t1*t2%pr); if(ans<0) ans+=pr; nx=x; } cout<<ans<<endl; }
相关文章推荐
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem K. UTF-8 Decoder 模拟题
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem A. A + B
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem G. k-palindrome dp
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem C. Cargo Transportation 暴力
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem F. Turning Grille 暴力
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem H. Parallel Worlds 计算几何
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem A. Alien Visit 计算几何
- 2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest A. Advanced 2048
- Codeforces 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest J题(BFS)
- 2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D:Distribution in Metagonia(构造)
- 【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest I】【水题】Lottery 均分气球最小修改数
- D. Data Center(2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest)
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem H. Hometask 水题
- 2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest K. Knights of the Old Republic kruskal
- 2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest —— E. Equal Digits
- F. Friends(2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest )
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest B - Stealing Harry Potter's Precious
- Codeforces 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A题 (String模拟)
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest G题: Garden Gathering [线段树/最小曼哈顿距离生成树]
- Codeforces 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest B题 (排序贪心)