click me
膜你退火模板题。
大概的思路是:
设定一个初始温度 T T ,每次降温 ×dt × d t ,温度越高,移动幅度越大,可以接受更劣解的概率越大。
#include
using namespace std;
int main()
{
puts("nan nan");
return 0;
}
滑稽
真·Code
/************************************************
* Au: Hany01
* Date: May 28th, 2018
* Prob: [BZOJ3680] 吊打XXX
* Email: [email protected]
************************************************/
#include
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
#define rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define x first
#define y second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define Mod (1000000007)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia
template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
inline int read()
{
register int _, __; register char c_;
for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
return _ * __;
}
const double eps = 1e-15;
const int maxn = 1005, Times = 15;
int n, w[maxn], x[maxn], y[maxn];
double randdec(double T) { return ((rand() + rand()) - RAND_MAX) * 1. / RAND_MAX * T * 1e-2; }
inline double calc(double nx, double ny)
{
double sx = 0, sy = 0, len, dx, dy;
For(i, 1, n)
{
dx = x[i] - nx, dy = y[i] - ny, len = sqrt(dx * dx + dy * dy);
if (fabs(len) < eps) continue;
sx += w[i] * dx / len, sy += w[i] * dy / len;
}
return sqrt(sx * sx + sy * sy);
}
int main()
{
#ifdef hany01
File("bzoj3680");
#endif
//random_device rand;
static double xba, yba, ansx, ansy, tba, ans;
n = read();
For(i, 1, n) xba += x[i] = read(), yba += y[i] = read(), w[i] = read();
ansx = xba /= n, ansy = yba /= n, tba = ans = calc(xba, yba);
for (int Case = Times; Case --; )
{
double nowx = xba, nowy = yba, now = tba, res, newx, newy;
for (double T = 1e6; T >= eps; T *= 0.99)
{
newx = nowx + randdec(T), newy = nowy + randdec(T), res = calc(newx, newy);
if (res < ans) ans = res, ansx = newx, ansy = newy;
if (res < now || exp((now - res) / T) * RAND_MAX < rand())
nowx = newx, nowy = newy, now = res;
}
}
printf("%.3lf %.3lf\n", ansx, ansy);
return 0;
}
//为君持酒劝斜阳,且向花间留晚照。
// -- 宋祁《玉楼春·春景》