結果
| 問題 |
No.8011 品物の並び替え (Extra)
|
| コンテスト | |
| ユーザー |
kurenai3110
|
| 提出日時 | 2017-06-10 03:26:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,003 ms / 5,000 ms |
| コード長 | 2,347 bytes |
| コンパイル時間 | 1,185 ms |
| コンパイル使用メモリ | 73,144 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 22:22:26 |
| 合計ジャッジ時間 | 11,608 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <chrono>
#include <cmath>
using namespace std;
#define LIMIT 1.0
class Timer {
chrono::high_resolution_clock::time_point start, end;
double limit;
public:
Timer() {
start = chrono::high_resolution_clock::now();
}
Timer(double l) {
start = chrono::high_resolution_clock::now();
limit = l;
}
double getTime() {
end = chrono::high_resolution_clock::now();
return chrono::duration<double>(end - start).count();
}
bool Over() {
if (getTime() > limit) {
return true;
}
return false;
}
void setLimit(double l) {
limit = l;
}
void setStart() { start = chrono::high_resolution_clock::now(); }
};
class Xor128 {
unsigned static int x, y, z, w;
public:
Xor128() {
x = 31103110, y = 123456789, z = 521288629, w = 88675123;
}
unsigned int rand()
{
unsigned int t;
t = (x ^ (x << 11)); x = y; y = z; z = w;
return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
};
unsigned int Xor128::x, Xor128::y, Xor128::z, Xor128::w;
int N, M;
int Score[50][50];
int nowScore(vector<int>&items) {
int score = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
score += Score[items[i]][items[j]];
}
}
return score;
}
int main()
{
cin >> N >> M;
for (int i = 0; i < M; i++) {
int a, b, c; cin >> a >> b >> c;
Score[a][b] = c;
}
vector<int>items(N);
for (int i = 0; i < N; i++) {
items[i] = i;
}
int nowscore = nowScore(items);
int maxscore = nowscore;
vector<int>ans(items);
Xor128 xor128;
Timer tmr(LIMIT);
while (!tmr.Over()) {
int p1, p2;
p1 = xor128.rand() % N;
p2 = xor128.rand() % N;
swap(items[p1], items[p2]);
int tmpscore = nowScore(items);
double starttemp = 100;
double endtemp = 10;
double t = tmr.getTime();
double temp = starttemp - (starttemp - endtemp) * t / LIMIT;
cerr << exp((tmpscore - nowscore) / temp) << endl;
if (exp((tmpscore - nowscore) / temp) > (double)xor128.rand() / UINT32_MAX) {
nowscore = tmpscore;
if (nowscore > maxscore) {
maxscore = nowscore;
ans = items;
}
}
else {
swap(items[p1], items[p2]);
}
}
cout << maxscore << endl;
for (int i = 0; i < N; i++) {
if (i)cout << " ";
cout << ans[i];
}
cout << endl;
cout << "多分これが一番良いと思います" << endl;
return 0;
}
kurenai3110