Pythagorean Theorem II

CodeForces 304A Pythagorean Theorem II 【基础】【暴力】 Description: In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triang 阅读详情

A.Pythagorean Theorem II
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:

In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).

The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:

a2 + b2 = c2

where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.

Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.

Input

The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.

Output

Print a single integer — the answer to the problem.

Sample test(s)
input
5
output
1
input
74
output
35

思路:10^8MLE,二分+枚举n。枚举n是一个好姿势,打表的好姿势。打表的空余时间别找map,or会死的很有节奏。

另外,羽哥的直接开根号其实就是最简单有效的方法。


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <map>
#include <cstdlib>
#include <cstring>
typedef long long ll;
#define	clr(a)		memset((a),0,sizeof (a))
#define	rep(i,a,b)	for(int i=(a);i<(int)(b);i++)
#define	per(i,a,b)	for(int i=((a)-1);i>=(int)(b);i--)
#define	inf	0x7ffffff
#define	eps			1e-6
using namespace std;
int mm[10005];
int num[10005];
/*bool find(int a,int b,int  key){
    int mid=(a+b)/2;  
    if(mm[mid]==key){
       return 1;            
    } 
    if(a==b-1)return 0;//cause I sent the mid ,not the mid-1 or mid+1。 
    if(mm[mid]>key){
      return find(a,mid,key);     
    }    
    else{
      return find(mid,b,key);     
    }
}*/
// the more adequate 'find' function
bool find(int a,int b,int  key){
    if(a>b)return 0;
    int mid=(a+b)/2;  
    if(mm[mid]==key){
       return 1;            
    } 
    if(mm[mid]>key){
      return find(a,mid-1,key);     
    }    
    else{
      return find(mid+1,b,key);     
    }
}
int main(){  
  for(int i=1;i<=10000;i++){
      mm[i]=i*i;    
  }
  for(int i=10000;i>=1;i--){
     for(int j=i-1;j>=1;j--){
        int tt=i*i-j*j;
        if(tt>j*j)break;
        if(find(1,10000,tt)){        
            num[i]++;                   
        }
            
     }        
  }
  int n;
  scanf("%d",&n);
  int sum=0;
  for(int i=1;i<=n;i++){
      sum+=num[i];       
  }
  printf("%d\n",sum); 
  //system("pause");
  return 0;
}




































TC264摄像头循迹进阶:八邻域与逐行遍历在复杂赛道边界提取中的实战对比 本文对比分析了TC264摄像头循迹中八邻域法与逐行遍历法在复杂赛道边界提取中的实战表现。八邻域法在边界连续性方面表现优异,适合处理环岛等复杂元素;逐行遍历法则在计算效率和岔路口识别上更具优势。文章提供了详细的代码实现和优化策略,帮助智能车竞赛选手根据赛道特点选择最佳算法方案。 阅读详情

相关推荐

Verilog——反相器

反相器代码: module inv( A, Y );//A,Y是端口 //定义端口属性 input A; output Y; //定义输入输出关系 assign Y=~A;//Y等于A的反 endmodule //inv是module的名字

weixin_41788560的博客 9500

CF 304A(Pythagorean Theorem II-n内勾股数)

A. Pythagorean Theorem II time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output In mathematics, the Pythagorean t

nike0good |Oier&ACMer | 熟能生巧 1917

Halcon实战:5分钟搞定工业零件中的圆孔检测(附完整代码)

本文详细解析了如何利用Halcon的hough_circle算法在5分钟内高效完成工业零件中的圆孔检测。通过优化图像采集、智能预处理和参数化边缘检测,解决了金属反光、油污干扰等工业场景常见问题,并提供了完整的代码示例和实战案例,显著提升检测精度和效率。

weixin_29061997的博客 239

A. Pythagorean Theorem II

A. Pythagorean Theorem II time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output In mathematics, the Pythagorean t

ecjtu_acm_菜鸟—鱼尾尾 1156

第055篇:陆地观测卫星数据服务平台高级检索方法

检索数据检索到肩膀疼,这谁能信?谁能?

liujinli0712的博客 7823

增益可控放大电路-电路与电子技术课程设计

增益可控放大电路-电路与电子技术课程设计

Yeats_Liao的博客 1万+

coderforce 304a - Pythagorean Theorem II

暴力,枚举a,b的值,判断c的大小。。。。。。。。。。。 但是为什么我的非暴力的代码就是不对呢???? #include #include #include #include #include #include #include #include #include #include #include #include #include usi

journey_fan的专栏 915

如何实现在Go语言中替换程序自身

总结起来,我们可以通过将新的程序二进制文件写入磁盘,并在运行时启动这个新的程序来实现在Go语言中替换程序自身。在Go语言中,有时候我们需要在程序运行时替换程序自身,例如更新程序版本或者进行热重启。本文将介绍一种正确的方式来实现在Go语言中替换程序自身的方法,并提供相应的源代码示例。此外,替换程序自身可能会导致正在运行的程序产生意外行为或终止,请谨慎使用,并确保在合适的时机进行替换操作。实现替换程序自身的关键是将新的程序二进制文件写入到磁盘,并在运行时启动这个新的程序。函数启动新的可执行文件,并在后台运行。

HoUnix的博客 288

暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II

题目传送门 1 /* 2 暴力:O (n^2) 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 #include <vector> 9 usin...

weixin_30668887的博客 93

嵌入式面经篇八——进程&线程

记录一些招聘公司在招聘嵌入式软件岗位时的一些问题,此文为第八篇。进程上文:是指进程由用户态切换到内核态时需要保存用户态时CPU寄存器中的值,进程状态以及堆栈上的内容。即保存当前进程的状态,以便再次执行该进程时,能够恢复切换时的状态,继续执行。进程下文:是指切换到内核态后执行的程序,即进程运行在内核空间的部分。中断上文:硬件通过中断触发信号,导致内核调用中断处理程序,进入内核空间。这个过程中,硬件的一些变量和参数也要传递给内核,内核通过这些参数进行中断处理。

明天你好的博客 1854

49、Linux内核内存管理:MGLRU、DAMON与OOM杀手详解

本文详细解析了Linux内核内存管理中的三大核心机制:MGLRU(多代LRU)页面追踪与回收机制、DAMON数据访问监控工具及其在内存优化中的应用,以及OOM(内存不足)杀手的工作原理和触发方式。同时,文章还介绍了VM overcommit_memory策略的设置及其对内存分配的影响,帮助开发者和系统管理员更好地理解Linux内存管理机制,从而优化系统性能和稳定性。

dropout6artist的博客 107

【CodeForces 304A 】Pythagorean Theorem II 高斯素数 高效算法

In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side oppos

待到山花烂漫时 453

TMF8801 ToF激光测距传感器原理图设计,已量产(距离传感器)

这张 TMF8801 小板的外围结构就很有代表性。核心传感器是 U1 TMF8801,但真正构成量产价值的是外围那一圈:U2 把 VCC 整理成 3V,R1/R2/R5 与 R3/R4/R6 两组 10K 电阻稳定默认态,Q2 2N7002 和 U3 SN74LVC2G07DCKR 处理控制链路,传感器边上还有 C1/C4/C5 三颗 100nF 紧贴去耦。

不脱发的程序猿 159

codeforces 304A. Pythagorean Theorem II

题目链接 给你一个n,计算出1 ≤ a ≤ b ≤ c ≤ n.使得由abc构成的三角形满足勾股定理,c为斜边。 没有简单的方法,直接爆力,但是要注意,有些abc满足勾股定理的表达式,但不一定是三角形,所以要判断一下,根据三角形三边的性质,两边之和大于第三边,两边之差小于第三边。 //cf304 A //2013-06-05-18.14 #include <stdio...

199

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

B - Pythagorean Theorem II

n mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:In any right-angled triangle, the area of th...

Mrzhq7的博客 365

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Pythagorean Theorem II CodeForces - 304A 优化

题解: 首先,纯暴力三层循环写,不做任何优化剪枝,AC想都不要想; 然后我就试了下用map写,(因为这是STL集训的一道题)将a,b平方和用map存起来,然后枚举c的值,与其比较;然而,这样的代码连n=1000都要跑好久,n=10000就根本想都不要想。 代码差不多是这样: #include &lt;map&gt; #include &lt;string&gt; #i...

一条菜狗的博客 376

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

CodeForces 304A Pythagorean Theorem II

暑假集训第一天,水题热热身。 这题大意是统计3条边长在n(n<10000)范围内直角三角形个数。直接枚举就可以。#include <iostream> #include<cmath> using namespace std;int main() { int n,ans=0; cin>>n; for(int i = 1 ; i <= n ; i++) {

youthinkwhat 440

cf 304A Pythagorean Theorem II

昨天训练赛的一个题目,看到以后直接谢了一发,然后wa了,加上了LL就可以过了,直接暴力就可以 双重循环 In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas,

ming_514 302

Problem F Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II

A. Pythagorean Theorem II time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output In mathematics, the Pythagorean t

To be what you what to be! 1790

codeforces 183(div2) A. Pythagorean Theorem II 枚举+二分查找

今天和羽哥老汪进行了长沙赛前的最后一场个人赛,还差星期五的一场团体赛,加油吧!少年 题目链接 直接进行暴力枚举,自己先把所有的情况都算出来,再进行二分查找。记录所有的数据。 时间为n*n*lgn 羽哥直接进行的是(a*a+b*b)-ceil(a*a+b*b)来判断是否是小于 eps (eps=1e-10) post code: /**************************

yangshuolll的专栏 1169

Proof of Pythagorean Theorem

The proof of Pythagorean Theorem in mathematics is very important. In a right angle, the square of the hypotenuse is equal to the sum of the squares of the other two sides. States that in a right triangle that, the square of a (a2) plus the square of b (b2

wzq2009的专栏 597

Real-Time Rendering-附录A 线性代数

Appendix A Some Linear Algebra(附录A 部分线性代数知识) A point is that which has no part. A line is a breadthless length. The extremities of a line are points. A straight line is a line which lies eve

3D编程之旅 2586
上一篇: Ivan and Powers of Two
下一篇: POJ1141 Brackets Sequence
muximuxi525
博客等级 码龄15年 134粉丝 294原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值