Positive Con Sequences

来源:互联网 发布:350淘宝装修平台 编辑:程序博客网 时间:2024/04/29 19:01

题意就是:4个等比或等差的数,缺了一个,你要求出那个数。
思路:对每个位置考虑下

#include"iostream"#include"cstdlib"#include"cmath"using namespace std;int main(){  long long  a,b,c,d,t,x;while(cin>>a>>b>>c>>d,a!=-1||b!=-1||c!=-1||d!=-1){     if(a==-1)    {           x=c/b;        t=b/x;        if(t*x==b&&t*x*x==c&&t*x*x*x==d&&t>0&&t<=10000)           cout<<t<<endl;           else            {            x=c-b;            t=b-x;            if(t+x==b&&t+2*x==c&&t+3*x==d&&t>0&&t<=10000)            cout<<t<<endl;            else               cout<<"-1"<<endl;           }    }    if(b==-1)    {         x=d/c;        t=c/x;        if(t/x==a&&t*x==c&&t*x*x==d&&t>0&&t<=10000)           cout<<t<<endl;           else            {            x=d-c;            t=c-x;            if(t-x==a&&t+x==c&&t+2*x==d&&t>0&&t<=10000)            cout<<t<<endl;            else               cout<<"-1"<<endl;           }    }    if(c==-1)    {         x=b/a;        t=d/x;        if(t/x/x==a&&t/x==b&&t*x==d&&t>0&&t<=10000)           cout<<t<<endl;           else            {            x=b-a;            t=b+x;            if(t-2*x==a&&t-x==b&&t+x==d&&t>0&&t<=10000)            cout<<t<<endl;            else               cout<<"-1"<<endl;           }        }        if(d==-1)    {         x=c/b;        t=c*x;        if(t/x/x/x==a&&t/x/x==b&&t/x==c&&t>0&&t<=10000)           cout<<t<<endl;           else            {            x=c-b;            t=c+x;            if(t-3*x==a&&t-2*x==b&&t-x==c&&t>0&&t<=10000)            cout<<t<<endl;            else               cout<<"-1"<<endl;           }    }}    return 0;} 
0 1