hdu 5615 Jam's math problem(判断是否能合并多项式)

方法一:由十字相乘相关理论我们能知道,如果要有p,k,q,m,那么首先要有解,所以b*b-4*a*c要>0,然而因为p,k,q,m是正整数,所以代表x1,x2都是有理数,有理数是什么鬼呢?就是解不带根号,我们知道有求根公式,其中2*a,-b都保证是自然数了,如果根号下b*b-4*a*c也保证是有理数我们就就能保证解是自然数,那么如何保证根号下b*b-4*a*c是有理数呢?那么b*b-4*a*c就是平方数
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
using namespace std;
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1000000
#define inf 1e12
ll a,b,c;
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%I64d%I64d%I64d",&a,&b,&c);
double bet = b*b-*a*c;
if(bet>eps && (int)(sqrt(bet))==sqrt(bet)){
printf("YES\n");
}else{
printf("NO\n");
}
}
return ;
}
方法二:暴力枚举数据
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std; int a,b,c;
int p[],cnt1;//p
int k[],cnt2;//k bool f(){
cnt1=cnt2=; int sqrt1=(int)sqrt(a);
for(int i=;i<=sqrt1;++i){
if(a%i==){
p[cnt1++]=i;
p[cnt1++]=a/i;
}
}
int sqrt2=(int)sqrt(c);
for(int i=;i<=sqrt2;++i){
if(c%i==){
k[cnt2++]=i;
k[cnt2++]=c/i;
}
} int q,m;
for(int i=;i<cnt1;++i){
for(int j=;j<cnt2;++j){
q=a/p[i];
m=c/k[j];
if( q*k[j]+m*p[i]==b ){
return true;
}
}
}
return false;
} int main(){ int T; scanf("%d",&T); while(T--){
scanf("%d%d%d",&a,&b,&c); if(f()){
printf("YES\n");
}
else{
printf("NO\n");
}
} return ;
}
hdu 5615 Jam's math problem(判断是否能合并多项式)的更多相关文章
- HDU 5615 Jam's math problem
Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...
- hdu 5615 Jam's math problem(十字相乘判定)
d. Jam有道数学题想向你请教一下,他刚刚学会因式分解比如说,x^2+6x+5=(x+1)(x+5) 就好像形如 ax^2+bx+c => pqx^2+(qk+mp)x+km=(px+k)(q ...
- Jam's math problem(思维)
Jam's math problem Submit Status Practice HDU 5615 Description Jam has a math problem. He just lea ...
- BestCoder Round #70 Jam's math problem(hdu 5615)
Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...
- HDU 5055 Bob and math problem(结构体)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...
- HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...
- hdu 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...
- HDU 1757 A Simple Math Problem(矩阵)
A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...
随机推荐
- windows套接字相关函数
windows套接字相关函数 作者:vpoet mail:vpoet_sir@163.com 我们学习TCP/IP协议无非是利用这些协议进行通信开发,然而如果让我们自己来直接根据协议规则和协议格式来进 ...
- 微型 Python Web 框架 Bottle - Heroin blog
微型 Python Web 框架 Bottle - Heroin blog 微型 Python Web 框架 Bottle
- What is NicEdit?
NicEdit - WYSIWYG Content Editor, Inline Rich Text Application What is NicEdit? NicEdit is a Light ...
- hdu 5625 Clarke and chemistry
Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...
- Android 内部存储相关的函数(getCacheDir,getDir, getFileStreamPath,getFilesDir,openFileInput, ...)
为了保证应用程序存储数据的安全性,开发人员在开发应用程序的过程中须要注意使用Android 应用程序的内部存储空间. 依据不同的要求.将相应的数据文件.缓存文件.暂时文件等分别存储在相应的位置. 注意 ...
- 从一段代码看fork()函数及其引发的竞争
首先来看一段从<UNIX环境高级编程>中摘录的一段很有意思的代码.借此我们再来谈谈fork()函数的一些问题. #include "apue.h" static voi ...
- oracle linux 安装过程错误 :Error in invoking target ‘agent nmhs’ of makefile
Problem:When installing 11.2.0.4 on Redhat 7: Error in invoking target 'agent nmhs' of makefile '/u0 ...
- Paxos算法深入分析
在分布式系统设计领域,Paxos可谓是最重要一致性的算法.Google的大牛们称 All working protocols for asynchronous consensus we have ...
- photoswipe
allowUserZoom: 允许用户双击放大/移动方式查看图片. 默认值 = trueautoStartSlideshow: 当PhotoSwipe激活后,自动播放幻灯片. 默认值 = falsea ...
- mysql单表大小的限制
mysql单表大小的限制一.MySQL数据库的MyISAM存储 引擎单表大小限制已经不是有MySQL数据库本身来决定(限制扩大到64pb),而是由所在主机的OS上面的文件系统来决定了.在mysql5. ...