Sichuan 2017 FSimple Algebra(打表)

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");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值