F. Simple Algebra
Given function f(x, y) = ax2 + bxy + cy2
, check if f(x, y) ≥ 0 holds for all x, y ∈ R.
Input
The input contains zero or more test cases and is terminated by end-of-file.
Each test case contains three integers a, b, c.
• −10 ≤ a, b, c ≤ 10
• The number of tests cases does not exceed 104
.
Output
For each case, output “Yes” if f(x, y) ≥ 0 always holds. Otherwise, output “No”.
Sample Input
1 -2 1
1 -2 0
0 0 0
Sample Output
Yes
No
Yes
题意:对于输入 的a,b,c,是否对于任意的x,y(x,y∈R)均满足f(x,y)>=0,满足输出Yes,否则输出No。
题解:打表,本地check完,将表交上去。
打表主要注意的几点:
1:表一定要打完(即后面要return 0,判断是否打完)
2:每个输出后加一个“,”,方便数组赋值。
3:数组大小要开好,计算方便。
打表:
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=2e5+10;
const int MOD=1e9+7;
const ll INF=1e18;
int read()
{
int x=0;
char ch = getchar();
while('0'>ch||ch>'9')ch=getchar();
while('0'<=ch&&ch<='9')
{
x=(x<<3)+(x<<1)+ch-'0';
ch=getchar();
}
return x;
}
/************************************************************/
int solve(int a,int b,int c)
{
for(int i=-1000;i<=1000;i++)
{
for(int j=-1000;j<=1000;j++)
{
if(a*i*i+b*i*j+c*j*j<0)
{
return 0;
}
}
}
return 1;
}
int main()
{
// freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
for(int a=-10;a<=10;a++)
{
for(int b=-10;b<=10;b++)
{
for(int c=-10;c<=10;c++)
{
if(solve(a,b,c)==1)
printf("1,");
else
printf("0,");
}
}
}
return 0;
}
代码:
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=2e5+10;
const int MOD=1e9+7;
const ll INF=1e18;
int read()
{
int x=0;
char ch = getchar();
while('0'>ch||ch>'9')ch=getchar();
while('0'<=ch&&ch<='9')
{
x=(x<<3)+(x<<1)+ch-'0';
ch=getchar();
}
return x;
}
int x,y,z;
/************************************************************/
int ans[21][21][21]={"将打好的表存到这"};
int main()
{
while(~scanf("%d%d%d",&x,&y,&z))
{
if(ans[x+10][y+10][z+10]==1)
puts("Yes");
else
puts("No");
}
}