代码求调
查看原帖
代码求调
781159
Lovely_Elaina楼主2023/10/7 17:07

RT,在学校机房,下课了

#include<iostream>
using namespace std;
const int N = 20005;

int T,n;
int t[N],b[N];

int mi,di;

inline bool check(int s){
    if((b[1]-s*t[1]) % (t[1]+t[n]) != 0){
        return 0;
    }

    int v = (b[1]-s*t[1]) / (t[1]+t[n]);
    for(int i = 2; i <= n; i++){
        if((b[i]-s*t[i]) % (t[i]+t[n-i+1]) != 0
         || (b[i]-s*t[i]) / (t[i]+t[n-i+1] != v))
            return false;
    }

    return true;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> T;
    while(T--){
        mi = 1145141919;

        cin >> n;
        for(int i = 1; i <= n; i++){
            cin >> t[i];
        }
        for(int i = 1; i <= n; i++){
            cin >> b[i];
            di = b[i]/t[i];
            mi = min(mi,di);
        }

        bool d = true;
        int s = 0;
        while(s <= mi){
            if(check(s)){
                d = false;
                break;
            }
            s++;
        }

        if(d) cout << "No" << endl;
    }

    return 0;
}
2023/10/7 17:07
加载中...