这个数据是不是有点太弱了
查看原帖
这个数据是不是有点太弱了
805433
zhi_fan楼主2024/1/18 21:35

交上去了一个错误的代码,样例都没过,但是交上去过了。

#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i = j;i <= (k);++ i)
#define ROF(i,j,k) for(int i = j;i >= (k);-- i)
#define PII pair<int,int>
#define int long long
#define ULL unsigned long long
#define PDD pair<double,double>
#define x first
#define y second
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ANS cout << ans << '\n'
#define de(p) cout << #p << ' ' << p << '\n';
#define END (i == n ? '\n' : ' ')
#define debug 1
using namespace std;
const int N = 1e3 + 10,M = 1e6 + 10,mod = 1e9 + 7,INF = 0x3f3f3f3f,P = 13331;

int n,m,k;
int a[N];

void solve()
{
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    sort(a + 1,a + 1 + n,greater());
    vector<PII> p;

    FOR(i,1,n - 1)
    {
        int j = i + 1;
        int t = __gcd(a[i],a[j]);
        if (a[i] != a[j])
        {
            p.emplace_back(a[i] / t,a[j] / t);
        }
    }
    std::sort(p.begin(), p.end(),[](PII a,PII b)
    {
        return (double) a.first / a.second < (double) b.first / b.second;
    });
    p.erase(unique(p.begin(),p.end()),p.end());

    int x = 1e18,y = 1e18;

//    FOR(i,0,p.size() - 1)
//        if (debug) cout << p[i].first << '/' << p[i].second << '\n';

    for(int i = 0;i < p.size() - 1;i ++)
    {
        int t1 = __gcd(p[i].first,p[i + 1].first),t2 = __gcd(p[i].second,p[i + 1].second);
        x = min(x,t1);
        y = min(y,t2);
//        cout << p[i].first << ' ' << p[i + 1].first << '\n';
    }
    if (p.size() == 1) x = p[0].first,y = p[0].second;
    cout << x << '/' << y << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int T = 1;
//    cin >> T;
    while(T --)
    {
        solve();
    }

    return 0;
}
2024/1/18 21:35
加载中...