首页 > 其他分享 >山东第八届acm大赛F题quadratic equation,山东理工oj 3898

山东第八届acm大赛F题quadratic equation,山东理工oj 3898

时间:2023-06-02 18:35:48浏览次数:41  
标签:oj NO int equation acm else 离散数学 flag test


题目地址:http://www.sdutacm.org/onlinejudge2/index.php/Home/Index/problemdetail/pid/3898.html

quadratic equation


Time Limit: 2000MS  Memory Limit: 131072KB


Submit  Statistic  Discuss


Problem Description


With given integers a,b,c, you are asked to judge whether the following statement is true: "For any x, if a⋅

+b⋅x+c=0, then x

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.

Example Input


31 4 4 0 0 1 1 3 1


Example Output


YESYES NO



心得:

这题在赛场上费尽心机也没A掉,后悔不已。不禁痛恨,算不算大坑,其实是自己离散数学没学好



今天重见此题,终于解心头之恨

分析:

这是一个离散数学中的蕴含命题。对于任意的x,前提是方程有解x ,结果是所有的x都是整数。


只有当前提成立,但结果不成立的时候,这个命题才是假NO。其余情况全部为真YES


知道了这句话,还怕A不掉这题吗?关键是笨脑子想不到这是个离散数学里的蕴含式


代码:

#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,c;
	int n;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d%d",&a,&b,&c);
		int flag;
		int d=b*b-4*a*c;
		if(a==0)
		{
			if(b==0)
			{
				if(c==0)
					flag=0;
				else
					flag=1;
			}
			else if(c%b==0)
				flag=1;
			else
				flag=0;
		}
		else if(d<0)
			flag=1;
		else if(d==0)
		{
			if(b%(2*a)==0)
				flag=1;
			else
				flag=0;
		}
		else 
		{
			if((int)sqrt(d)==sqrt(d))
			{
				if((-b+(int)sqrt(d))%(2*a)==0&&(-b-(int)sqrt(d))%(2*a)==0)
					flag=1;
				else
					flag=0;
			}
			else
				flag=0;
		}
		if(flag)
			puts("YES");
		else 
			puts("NO");
	}
	return 0;
}







标签:oj,NO,int,equation,acm,else,离散数学,flag,test
From: https://blog.51cto.com/u_16125110/6404536

相关文章

  • acm杭电2092-整数解
    ProblemDescription有二个整数,它们加起来等于某个整数,乘起来又等于另一个整数,它们到底是真还是假,也就是这种整数到底存不存在,实在有点吃不准,你能快速回答吗?看来只能通过编程。例如:x+y=9,x*y=15?找不到这样的整数x和y1+4=5,1*4=4,所以,加起来等于5,乘起......
  • POJO简介【pojo模块】
    DTO(DataTransferObject):数据传输对象,用于接收数据和传输数据,属性和请求参数对应。VO(ViewObject):视图对象,返回给客户端展示用的数据,例如分页对象PageResult{total,List}。PO(PersistantObject):持久化对象,对象属性和数据库表中的字段一一对应,一张表对应一个PO。POJO(PlainOrdi......
  • 使用Hutool的@Alias注解和JSONUtil.toJsonStr()的问题记录
    表格如下: 定义类结构如下:  使用fastjson转换后的结果                                使用hutool的JSONUtil转换之后的结果      可以看到JSONUtil类转换之后格式并不是我们需要的类的字......
  • 2023年6月最新全国省市区县和乡镇街道行政区划矢量边界坐标经纬度地图数据 shp geojso
    发现个可以免费下载全国 geojson 数据的网站,推荐一下。支持全国、省级、市级、区/县级、街道/乡镇级以及各级的联动数据,支持导入矢量地图渲染框架中使用,例如:D3、Echarts等geojson数据下载地址:https://geojson.hxkj.vip该项目github地址:https://github.com/TangSY/echarts-m......
  • Typora Emoji
    title:TyporaEmojicategories:-手册目录PeopleNatureObjectsPlacesSymbolsPeople......
  • Git emoji手册
    title:gitemoji手册tags:-手册-gitcategories:-手册emojiemoji代码commit说明......
  • POJ3608(旋转卡壳--求两凸包的最近点对距离)
    题目:BridgeAcrossIslands  考虑如下的算法,算法的输入是两个分别有m和n个顺时针给定顶点的凸多边形P和Q。1.计算P上y坐标值最小的顶点(称为yminP)和Q上y坐标值最大的顶点(称为ymaxQ)。2.为多边形在yminP和ymaxQ处构造两条切线LP和LQ使得他们对应的多边形位于他们的右侧......
  • POJ1151(线段树+扫描线求矩形面积并)
    题目:http://poj.org/problem?id=1151 #include<iostream>#include<string.h>#include<algorithm>#include<stdio.h>usingnamespacestd;constintN=10005;structnode{intl,r;intcov;doublelen;};structline{......
  • POJ2369 置换群
    题目:http://poj.org/problem?id=2369题意:给定一个序列,问需要最少需要置换多少次才能变为有序序列.分析:对于每一位,算出最少的置换到自己应该的数字。每一位都有这样的数字,取最小公倍数就可以。#include<iostream>#include<string.h>#include<stdio.h>usingnamespacestd......
  • POJ3695(矩形切割中等题)
    题目:Rectangles 题意:给N个矩形,他们可能会重叠,然后给M个询问,每个询问给出指定的矩形位置,然后分别计算每个询问中选中的矩形的并。 本题跟求所有矩形的并一个思路,只是再增加一个数组来保存选中矩形的位置,然后直接求并即可。#include<stdio.h>#include<string.h>#include<algor......