1 #include <bits/stdc++.h> 2 #define nmax 510 3 //D=(A×B−C)×A的轉置 最大 求出一個01矩陣A 4 using namespace std; 5 int b[nmax][nmax]; 6 int c[nmax], a[nmax], t[nmax], anst[nmax]; 7 int n, ans=-1e9; 8 9 void upd(){ 10 int newa = 0; 11 for (int i=1; i<=n; i++) t[i] = 0; 12 for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) t[i] += b[j][i]*a[j]; 13 for (int i=1; i<=n; i++) t[i] -= c[i]; 14 for (int i=1; i<=n; i++) newa += t[i]*a[i]; 15 ans = max(newa, ans); 16 } 17 18 int main(){ 19 srand((unsigned)time(NULL)); 20 cin >> n; 21 for (int i=1; i<=n; i++) { 22 for (int j=1; j<=n; j++) { 23 scanf("%d", &b[i][j]); 24 } 25 } 26 for (int i=1; i<=n; i++) scanf("%d", &c[i]); 27 for (int i=1; i<=n; i++) a[i] = 1; 28 upd(); 29 for (int i=0; i<1000; i++) { 30 int p = rand()%n + 1; 31 a[p] = ( !a[p] ); 32 upd(); 33 } 34 cout << ans << endl; 35 return 0; 36 }
1 #include <cstdio> 2 #include <iostream> 3 #include <cstdlib> 4 #include <ctime> 5 6 using namespace std; 7 char out[4]={'U','L','D','R'}; 8 9 int main(){ 10 srand((unsigned)time(NULL)); 11 int n, m, in; 12 cin >> n >> m; 13 for (int i=0; i<n; i++) for (int j=0; j<m; j++) scanf("%d", &in); 14 for (int i=0; i<50000; i++) printf("%c", out[ rand()%4 ] ); 15 return 0; 16 }
1 #include <bits/stdc++.h> 2 #define nmax 1000010 3 4 using namespace std; 5 int n,m; //題目數量和想法的數量 6 int a[nmax],b[nmax],c[nmax],mc[nmax]; 7 double w[nmax]; 8 9 int main(){ 10 srand((unsigned)time(NULL)); 11 cin>>n>>m; 12 int M=200000000/n; 13 for (int i=m+1; i<=n; i++) scanf("%d%d",&a[i],&b[i]); 14 for (int j=0; j<M; j++) { 15 for (int i=1; i<=m; i++) { 16 c[i]=rand(); 17 mc[i]=c[i]; 18 } 19 for (int i=m+1; i<=n; i++) { 20 mc[i]=min(mc[ a[i] ] , mc[ b[i] ]); 21 w[i]+=mc[i]/(M*1.0); 22 } 23 } 24 for (int i=m+1; i<=n; i++) printf("%.0lf\n",RAND_MAX/w[i]-1); 25 return 0; 26 }