QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#1087#691071#7753. Energy Distributionsunnygreenicpc_zhzx034Failed.2024-10-31 09:58:222024-10-31 09:58:23

详细

Extra Test:

Invalid Input

input:

1
0

output:


result:

FAIL Integer parameter [name=n] equals to 1, violates the range [2, 10] (stdin, line 1)

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691071#7753. Energy Distributionicpc_zhzx034AC ✓14ms3956kbC++142.0kb2024-10-31 09:39:512024-10-31 10:31:03

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pr;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
// #define mid ((l+r)>>1)
#define popcnt __builtin_popcountll
const ll mod = 998244353;
inline ll read(){
	ll x=0, f=1; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
	return x*f;
}
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
	ll ans=1, base=a;
	while(b){
		if(b&1) ans=ans*base%mod;
		base=base*base%mod; b>>=1;
	}
	return ans;
}
void init(){ }
ll n,w[15][15]; double p[15];

void adjust(ll x,ll y){
	double sum = p[x] + p[y];
	double F = 0, S = 0;
	for(ll i=1;i<=n;i++){
		if(i==x || i==y) continue;
		F += p[i]*w[i][x] - p[i]*w[i][y];
	}
	F += w[x][y]*sum;
	S -= w[x][y];
	if(w[x][y]){
		p[x] = - F / (2.0 * S);
		if(p[x] < 0) p[x] = 0;
		if(p[x] > sum) p[x] = sum;
		p[y] = sum - p[x];
	}
	else {
		if(F < 0) p[x] = 0, p[y] = sum;
		else if(F > 0) p[x] = sum, p[y] = 0;
		else return;
	}
}
ll s[105];
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
void procedure(){
	n=read();
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++) w[i][j]=read();
	}
	for(ll i=1;i<=n;i++) p[i]=1.0/n;
	ll Q = 100;

	double Ans = 0;
	while(Q--){
		ll sig = 0;
		for(ll i=1;i<=n;i++) {
			s[i] = rnd() % 1000 + 1;
			sig += s[i];
		}
		for(ll i=1;i<=n;i++) p[i] = s[i] * 1.0 / sig;
		ll T = 3000;
		while(T--){
			ll x=rnd()%n+1, y=rnd()%n+1;
			while(x==y) y=rnd()%n+1;
			adjust(x, y);
		}
		double ans = 0;
		for(ll i=1;i<=n;i++){
			for(ll j=i+1;j<=n;j++)
				ans += p[i] * p[j] * w[i][j];
		}
		Ans = max(Ans, ans);
	}
	printf("%.10lf\n", Ans);
}
int main(){
	#ifdef LOCAL
		assert(freopen("input.txt","r",stdin));
		assert(freopen("output.txt","w",stdout));
	#endif
	ll T=1;
	init();
	while(T--) procedure();
	return 0;
}