1 solutions

  • 0
    @ 2023-2-9 20:24:59

    可以得知b的值只有两种情况b和b1,而c的值有无数种情况,分两种情况第一种为c首先被b减和c首先被b1减两种情况,如果c首先被b减去得到一个新的数值c1,那么c1下一次将会由b1来减去得到c2否则得话c2的值会回到c的数值,我们可以得到一个规律每次cn与c(n+2)的数值总是相差abs(2*b-a)的,再加上差值为零的情况那么这道题就解决了。

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n;
    	cin>>n;
    	while(n--){
    		int a,b,c,x;
    		cin>>a>>b>>c>>x;
    		int b1=a-b;
    		int a1=b-c;
    		int a2=b1-a1;
    		int sum1=abs(2*b-a);
    		if(sum1==0){
    			if(b-c==x||c==x){
    				cout<<"Yes"<<endl;
    				continue;
    			}
    		}
    		else if((x-a1)%sum1==0){
    			cout<<"Yes"<<endl;
    			continue;
    		}
    		else if((x-a2)%sum1==0){
    			cout<<"Yes"<<endl;
    			continue;
    		}
    		a1=b1-c;
    		a2=b-a1;
    		if(sum1==0){
    			if(b-c==x||c==x){
    				cout<<"Yes"<<endl;
    				continue;
    			}
    		}
    		else if((x-a1)%sum1==0){
    			cout<<"Yes"<<endl;
    			continue;
    		}
    		else if((x-a2)%sum1==0){
    			cout<<"Yes"<<endl;
    			continue;
    		}
    		cout<<"No"<<endl;
    	}
    }
    

    Information

    ID
    6647
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    8
    Tags
    (None)
    # Submissions
    53
    Accepted
    8
    Uploaded By