quadratic equation //逻辑思路 离散数学的p->q条件

quadratic equation

Time Limit: 2000 ms Memory Limit: 131072 KiB
Problem Description

With given integers a,b,c, you are asked to judge whether the following statement is true: "For any x, if a+bx+c=0, then x is an integer."

Input

The first line contains only one integer T(1≤T≤2000), which indicates the number of test cases.
For each test case, there is only one line containing three integers a,b,c(−5≤a,b,c≤5).

Output

or each test case, output “YES” if the statement is true, or “NO” if not.

Sample Input
3
1 4 4
0 0 1
1 3 1
Sample Output
YES
YES
NO
Hint
Source
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)

给出a,b,c,让你判断这个逻辑公式对错;

思路:只要有x在a*x*x+b*x+c==0这个式子成立,那么x一定是整数,即:

p   q    p->q

0   0      1
0   1      1
1   0      0
1   1      1


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
int shu(int a,int b,int c){
    if(a==0)
	{
      if(b==0)
	  {
        if(c==0)
		{
            return 0;
        }else{
            return 1;
        }
      }else{
        /*if(c==0){
          return 1;
        }else{*/
          if(c%b==0){
            return 1;
          }
		  else{
            return 0;
          }
        }
      //}
    }else{
     double s;
     s=b*b-4*a*c;
     if(sqrt(s)>=0){
        double w1=(-b+sqrt(s))/(2*a); //求根公式写错了,改了很多次 
         int w2=(int)w1;
        double r1=(-b-sqrt(s))/(2*a);
         int r2=(int)r1;
         if(w1-w2!=0 || r1-r2!=0){
            return 0;
         }
		 else{
         // if((-1*b-(int)sqrt(s))%(2*a)!=0 ||(-1*b+(int)sqrt(s))%(2*a)!=0){
          //  return 0;
          // }
           //else{
            return 1;
           //}
         }
     }else{
       return 1;
     }
    }

}
int main(){
  int a,b,c;
  int t,x,i;
  int flag;
  scanf("%d",&t);//不要用while读入
    for(i=0;i<t;i++){
        scanf("%d%d%d",&a,&b,&c);
         flag=shu(a,b,c);
         if(flag){
            cout<<"YES"<<endl;
         }else{
            cout<<"NO"<<endl;
         }
    }
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ValueError Traceback (most recent call last) Cell In[52], line 69 67 f = interp1d(B2[0, :], B2[1, :], kind='quadratic') 68 a8 = f(i2) ---> 69 a9 = f(a20) 70 derivative = (a9 - a8) / a7 71 if derivative - a9 > 10e-6: File ~\AppData\Roaming\Python\Python39\site-packages\scipy\interpolate\_polyint.py:80, in _Interpolator1D.__call__(self, x) 59 """ 60 Evaluate the interpolant 61 (...) 77 78 """ 79 x, x_shape = self._prepare_x(x) ---> 80 y = self._evaluate(x) 81 return self._finish_y(y, x_shape) File ~\AppData\Roaming\Python\Python39\site-packages\scipy\interpolate\_interpolate.py:752, in interp1d._evaluate(self, x_new) 750 y_new = self._call(self, x_new) 751 if not self._extrapolate: --> 752 below_bounds, above_bounds = self._check_bounds(x_new) 753 if len(y_new) > 0: 754 # Note fill_value must be broadcast up to the proper size 755 # and flattened to work here 756 y_new[below_bounds] = self._fill_value_below File ~\AppData\Roaming\Python\Python39\site-packages\scipy\interpolate\_interpolate.py:786, in interp1d._check_bounds(self, x_new) 784 if self.bounds_error and above_bounds.any(): 785 above_bounds_value = x_new[np.argmax(above_bounds)] --> 786 raise ValueError("A value ({}) in x_new is above " 787 "the interpolation range's maximum value ({})." 788 .format(above_bounds_value, self.x[-1])) 790 # !! Should we emit a warning if some values are out of bounds? 791 # !! matlab does not. 792 return below_bounds, above_bounds ValueError: A value (0.21347609900000009) in x_new is above the interpolation range's maximum value (0.213476099).该怎么修改,代码怎么写
最新发布
05-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值