zoukankan      html  css  js  c++  java
  • 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就是平方数

     1 #pragma comment(linker, "/STACK:1024000000,1024000000")
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<math.h>
     7 #include<algorithm>
     8 #include<queue>
     9 #include<set>
    10 #include<bitset>
    11 #include<map>
    12 #include<vector>
    13 #include<stdlib.h>
    14 using namespace std;
    15 #define ll long long
    16 #define eps 1e-10
    17 #define MOD 1000000007
    18 #define N 1000000
    19 #define inf 1e12
    20 ll a,b,c;
    21 int main()
    22 {
    23     int t;
    24     scanf("%d",&t);
    25     while(t--){
    26         scanf("%I64d%I64d%I64d",&a,&b,&c);
    27         double bet = b*b-4*a*c;
    28         if(bet>eps && (int)(sqrt(bet))==sqrt(bet)){
    29             printf("YES
    ");
    30         }else{
    31             printf("NO
    ");
    32         }
    33     }
    34     return 0;
    35 }
    View Code

    方法二:暴力枚举数据

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<math.h>
     4 using namespace std;
     5 
     6 int a,b,c;
     7 int p[20000],cnt1;//p
     8 int k[20000],cnt2;//k
     9 
    10 bool f(){
    11     cnt1=cnt2=0;
    12 
    13     int sqrt1=(int)sqrt(a);
    14     for(int i=1;i<=sqrt1;++i){
    15         if(a%i==0){
    16             p[cnt1++]=i;
    17             p[cnt1++]=a/i;
    18         }
    19     }
    20     int sqrt2=(int)sqrt(c);
    21     for(int i=1;i<=sqrt2;++i){
    22         if(c%i==0){
    23             k[cnt2++]=i;
    24             k[cnt2++]=c/i;
    25         }
    26     }
    27 
    28     int q,m;
    29     for(int i=0;i<cnt1;++i){
    30         for(int j=0;j<cnt2;++j){
    31             q=a/p[i];
    32             m=c/k[j];
    33             if( q*k[j]+m*p[i]==b ){
    34                 return true;
    35             }
    36         }
    37     }
    38     return false;
    39 }
    40 
    41 int main(){
    42 
    43     int T;
    44 
    45     scanf("%d",&T);
    46 
    47     while(T--){
    48         scanf("%d%d%d",&a,&b,&c);
    49 
    50         if(f()){
    51             printf("YES
    ");
    52         }
    53         else{
    54             printf("NO
    ");
    55         }
    56     }
    57 
    58     return 0;
    59 }
    View Code
  • 相关阅读:
    smarty对网页性能的影响
    php-fpm正在生成页面时,浏览器刷新后,php-fpm会退出吗?
    为什么日志记录到别的目录了?
    一个空格引发的bug
    linux内核--页高速缓存
    radix树
    linux内核--用户态内存管理
    linux内核--内核内存管理
    linux内核--软中断与tasklet
    linux内核--几个上下文(context)
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/5173381.html
Copyright © 2011-2022 走看看