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 [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...
随机推荐
- mongoDB 在windows平台下安装成系统服务
1,用如截图所示命令将mongoDB安装成windows系统服务,byRuiy Tips[Note,logpath and dbpath根据你命令行指导的路径,这些目录一定要已经创建]
- COJ 1059 - Numeric Parity 位操作
非常好玩的一道题.能够熟悉下位操作实现和玩一玩bitset这个容器 Description We define the parity of an integer N as the sum of the ...
- UBUNTU系统root帐号解锁
UBUNTU系统启动时默认以安装系统时输入的用户名进行登录.如:以非root帐号rusky登录系统,当我们做某些操作时系统提示需要输入root密码.但我们并没有设置过root密码.此时,可按如下操作为 ...
- JavaScript 【正则表达式验证数字代码】
可以看到 Ajax 请求多了个 x-requested-with ,可以利用它,request.getHeader("x-requested-with"); 为 null,则为传统 ...
- ASP.NET在实际开发中验证码的用法
在网上有看到很多关于验证码的代码,很多都只是生成一张验证码图片,然而在实际登陆验证模块,验证码要怎么添加进去或者说怎么运用.和实际项目开发中要怎么使用验证码,我自己总结了几点. 一.在实际开发登陆模块 ...
- Windows7中安装内存与可用内存不一致的解决办法
转载:http://blog.sina.com.cn/s/blog_56741a420100h9d1.html 问题现象: 安装完Windows7后,在计算机->属性中,会看到安装内存.但有时在 ...
- java数据导出成 EXCEL
/** * * @param out 输出流 * @param maplist 数据 * @param title 标题 * @param headers 表头 * @param keys 表头对应的 ...
- Android布局控件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...
- Floyd算法(弗洛伊德算法)
算法描述: Floyd算法又称为弗洛伊德算法,插点法,是一种用于寻找给定的加权图中顶点间最短路径的算法.从图的带权邻接矩阵A=[a(i,j)] n×n开始,递归地进行n次更新,即由矩阵D(0)=A,按 ...
- Candy Bags
读懂了题就会发现这是个超级大水题 Description Gerald has n younger brothers and their number happens to be even. One ...