【BZOJ】1041: [HAOI2008]圆上的整点(几何)
http://www.lydsy.com:808/JudgeOnline/problem.php?id=1041

所谓的神题,我不会,直接题解。。看了半天看懂题解了。详见hzwer博客
这题呢,我只能吸收些思想,即,当我们要找合法解的时候,我们可以深究它的性质,然后用性质来判定是否存在合法解。
此神题直接看题解打码。
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define read(a) a=getnum()
#define print(a) printf("%d", a)
#define debug(a) printf("%lld\n", a)
inline int getnum() { int ret=0; char c; for(c=getchar(); c<'0' || c>'9'; c=getchar()); for(; c>='0' && c<='9'; c=getchar()) ret=ret*10+c-'0'; return ret; }
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a; } inline bool check(ll A, ll B) {
if(((ll)sqrt(B)*(ll)sqrt(B))==B && A!=B)
if(gcd(A, B)==1) return true;
return false;
} int main() {
int ans=0;
ll d, d2, r, r2;
scanf("%lld", &r);
r2=r<<1;
ll m=sqrt(r2);
ll a;
for(d=1; d<=m; ++d) {
if(!(r2%d)) {
d2=d<<1;
for(a=1; a<=(ll)sqrt(r2/d2); ++a)
if(check(a*a, r2/d-a*a)) ++ans;
if(d!=r2/d) {
for(a=1; a<=(ll)sqrt(d/2); ++a)
if(check(a*a, d-a*a)) ++ans;
}
}
}
printf("%lld\n", (ll)(ans*4+4));
return 0;
}
Description
求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数。
Input
r
Output
整点个数
Sample Input
Sample Output
HINT
n<=2000 000 000
Source
【BZOJ】1041: [HAOI2008]圆上的整点(几何)的更多相关文章
- BZOJ 1041: [HAOI2008]圆上的整点
1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3621 Solved: 1605[Submit][Sta ...
- bzoj 1041: [HAOI2008]圆上的整点 数学
1041: [HAOI2008]圆上的整点 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...
- bzoj 1041: [HAOI2008]圆上的整点 本原勾股數組
1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2027 Solved: 853[Submit][Stat ...
- BZOJ 1041: [HAOI2008]圆上的整点【数论,解方程】
1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4210 Solved: 1908[Submit][Sta ...
- BZOJ 1041 [HAOI2008]圆上的整点:数学
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1041 题意: 给定n(n <= 2*10^9),问你在圆x^2 + y^2 = n^ ...
- BZOJ 1041 [HAOI2008]圆上的整点:数学【费马平方和定理】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1041 题意: 给定n(n <= 2*10^9),问你在圆x^2 + y^2 = n^ ...
- BZOJ(2) 1041: [HAOI2008]圆上的整点
1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4966 Solved: 2258[Submit][Sta ...
- 1041: [HAOI2008]圆上的整点
1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4298 Solved: 1944[Submit][Sta ...
- 1041: [HAOI2008]圆上的整点 - BZOJ
Description 求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数.Input rOutput 整点个数Sample Input4Sample Output4HINT n ...
随机推荐
- angular 监听ng-repeat结束时间
有些时候我们想要监听angular js中的 ng-repeat结束事件,从而好初始化一些我们的第三方或者其他需要初始化的js. 我们可以这样处理: js 中这样定义 : //监听事件 是否加载完毕a ...
- HDU1198水管并查集Farm Irrigation
Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot ...
- poj1860 bellman—ford队列优化 Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22123 Accepted: 799 ...
- 【云计算】开源装机自动化系统 CloudBoot OSInstall 介绍
"CloudBoot"(OSinstall) 发布了. 产品更新及特点如下: 新增虚拟化操作系统适配:支持主流操作系统:RedHat.CentOS.SUSE.Ubuntu.Wind ...
- eclipse加速之禁用JS、jsp等文件的语法验证,eclipsejs
eclipse加速之禁用JS.jsp等文件的语法验证 去除eclipse的JS验证:将windows->preference->Java Script->Validator-> ...
- JSON和GSON操作json数据
1,JSON操作json import net.sf.json.JSONArray; import net.sf.json.JSONObject; //json操作数据 public static S ...
- 将Excel文件.xls导入SQL Server 2005
SQL2005 Microsoft SQL Server Management Studio Express管理器里,右键单击一个数据库,指向“任务”,再单击“导入数据”或“导出数据”中没有这个选项, ...
- python文件取MD5
import hashlib def md5sum(filename, blocksize=65536): hash = hashlib.md5() with open(filename, " ...
- Xshell 中文乱码
Xshell对于嵌入式开发来说,是个非常不错的工具.但或许都有过被中文显示为乱码的问题感觉有点不爽.解决方法其实很简单的,即把xshell编码方式改成UTF-8即可. [文件]–>[打开]–&g ...
- Android 图标添加消息提醒
实现方法: 1. 在对应的布局放置TextView或者ImageView. 2. 用Canvas在原来Icon的bitmap基础上进行绘制 3. 利用开源项目ViewBadger进行添加,很方便,而且 ...