开始 2024-10-02 12:31:12

【2024NOIP】模拟赛-11

结束 2024-10-12 00:00:00
Contest is over.
当前 2025-02-23 10:48:52

T4 随机化
#include<bits/stdc++.h>
#define up(i,l,r) for(int i=(l);i<=(r);++i)
#define down(i,l,r) for(int i=(l);i>=(r);--i)
#define pi pair<int,int>
#define p1 first
#define p2 second
#define p_b push_back
#define m_p make_pair
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
inline ll read(){
    ll x=0;short t=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*t;
}
mt19937 rng(0);
int n,a[maxn];
vector<int>v[maxn];
int P[maxn],Q[maxn],vis[maxn];
bool cmp(int x,int y){
    return a[x]<a[y];
}
double calc(){
    up(i,1,n)P[i]=Q[i],vis[i]=0;
    up(i,1,10){
        int x=rng()%n+1,y=rng()%n+1;
        swap(P[x],P[y]);
    }double res=0;
    ll s1=0,s2=0;
    up(i,1,n){
        int x=P[i];
        s1+=a[x],s2+=a[x]*a[x];vis[x]=1;
        bool ok=0;
        up(j,1,i){
            for(int x:v[P[j]]){
                if(!vis[x]){
                    ok=1;break;
                }
            }if(ok)break;
        }
        if(!ok)res=max(res,s1*s1*1.0/s2);
    }return res;
}
void slv(){
    n=read();int m=read();
    up(i,1,n)a[i]=read();
    while(m--){
        int x=read(),y=read();
        v[x].p_b(y);
    }up(i,1,n)Q[i]=i;sort(Q+1,Q+n+1,cmp);
    int tim=200000/(max(1,n/10)+1);double res=0;
    while(tim--)res=max(res,calc());
    printf("%.10lf",res);
}int main(){
    //freopen("sale.in","r",stdin);
    //freopen("sale.out","w",stdout);
    slv();
    //cerr<<clock()*1.0/CLOCKS_PER_SEC<<"s\n";
    fclose(stdin);
    fclose(stdout);
    return 0;
}

admin  •  4个月前

比赛已结束。