QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#256062#7750. Revenge on My Bossucup-team073#WA 529ms3700kbC++141.8kb2023-11-18 17:47:482023-11-18 17:47:49

Judging History

你现在查看的是最新测评结果

  • [2023-11-18 17:47:49]
  • 评测
  • 测评结果:WA
  • 用时:529ms
  • 内存:3700kb
  • [2023-11-18 17:47:48]
  • 提交

answer

#include <bits/stdc++.h>
#define mk make_pair 
using namespace std;

int n;
double a[12][12];
struct node{
	double t[12],adp;
	inline void getadp() {
		adp=0;
		for (int i=1;i<=n;i++)
			for (int j=i+1;j<=n;j++)
				adp+=a[i][j]*t[i]*t[j];
	}
	inline void init() {
		double sum=0;
		for (int i=1;i<=n;i++)
			t[i]=rand(),sum+=t[i];
		for (int i=1;i<=n;i++)
			t[i]=t[i]/sum;
		getadp();
	}
	bool operator < (node y) {
		return adp<y.adp;
	}
	bool operator > (node y) {
		return adp>y.adp;
	}
	pair<node,node> crossover(node y) {
		node nw1,nw2;
		for (int i=1;i<=n;i++)
			nw1.t[i]=t[i]/4.0*3.0+y.t[i]/4.0;
		for (int i=1;i<=n;i++)
			nw2.t[i]=t[i]/4.0+y.t[i]/4.0*3.0;
		nw1.getadp(),nw2.getadp();
		return mk(nw1,nw2);
	}
	void mutation() {
		double x=double(rand())/RAND_MAX;
		if (x<=0.1) {
			double x1=double(rand())/RAND_MAX,x2=double(rand())/RAND_MAX;
			int w1=rand()%n+1,w2=rand()%n+1;
			t[w1]=x1,t[w2]=x2;
			double sum=0;
			for (int i=1;i<=n;i++) sum+=t[i];
			for (int i=1;i<=n;i++) t[i]=t[i]/sum;
			getadp();
		}
	}
}d[110];
bool cmp(node x,node y){
	return x.adp>y.adp;
}

int main() {
	srand(time(NULL));cin>>n;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			cin>>a[i][j];
	for (int i=1;i<=50;i++)
		d[i].init();
	sort(d+1,d+50+1,cmp);
	int T=300000;double ans=d[1].adp;
	while (T--) {
		for (int i=1,j=2;j<=50;i+=2,j+=2) {
			pair<node,node> nw=d[i].crossover(d[j]);
			d[50+i]=nw.first,d[50+j]=nw.second;
			d[50+i].mutation(),d[50+j].mutation();
		}
		sort(d+1,d+101,cmp);
		ans=max(ans,d[1].adp);
	//	cout<<ans<<endl;
	//	if (T%10==0) system("pause");
	}
	cout<<ans;
}
/*
10
0 1 4 5 3 4 5 2 6 7
0 0 5 5 2 5 5 8 6 9
0 0 0 7 2 3 6 4 1 3
0 0 0 0 4 7 5 9 2 4
0 0 0 0 0 7 2 6 3 8
0 0 0 0 0 0 7 5 2 1
0 0 0 0 0 0 0 7 8 4
0 0 0 0 0 0 0 0 3 7
0 0 0 0 0 0 0 0 0 2
0 0 0 0 0 0 0 0 0 0
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 529ms
memory: 3700kb

input:

2
4
1 1 4
5 1 5
1 9 1
9 8 1
9
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9
3 2 3
8 4 6
2 6 8
3 2 7

output:

0.25

result:

wrong output format Expected integer, but "0.25" found