19 SWERC 2022-2023 - Online Mirror (Unrated, ICPC Rules, Teams Preferred)L. Controllers(数学公式+瞎搞)

L. Controllers

思路:
ad6c59561bbebeb38f6e7bc997f62c3.jpg

#include <bits/stdc++.h>

#define int long long
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define fep(i, a, b) for(int i = (a); i >= (b); --i)
#define _for(i, a, b) for(int i=(a); i<(b); ++i)
#define pii pair<int, int>
#define pdd pair<double,double>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
#define vi vector<int>

using namespace std;
const int maxn = 2e5 + 10;

int n,q,k1,k2;
string s;
void solve() {
    cin>>n>>s>>q;
    for(auto c:s){
        if(c=='+')  k1++;
        else    k2++;
    }
//    cout<<k1<<' '<<k2<<endl;
    while(q--){
        int x,y;
        cin>>x>>y;
        int tmp1=(k1-k2)*x;
        int tmp2=(k2-k1)*y;
        int p=x-y;
        if(p==0){
            if(tmp1==0||tmp2==0){
                cout<<"YES"<<endl;
            }else{
                cout<<"NO"<<endl;
            }
        }else{
            if(tmp1%p==0){
              int d=(k1-k2)*x/(x-y);
              if(d>=-k2&&d<=k1){
                  cout<<"YES"<<endl;
              }else{
                  cout<<"NO"<<endl;
              }
            }else{
                cout<<"NO"<<endl;
            }
        }

    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//	freopen("C:\\Users\\24283\\CLionProjects\\untitled2\\1.in", "r", stdin);
    int _;
//    cin >> _;
//    while (_--)
    solve();
    return 0;
}
posted @ 2024-03-04 16:32  cxy8  阅读(11)  评论(0编辑  收藏  举报