1. 程式人生 > >poj 2420

poj 2420

print sign using ace += 就是 sin als sqrt

太虛假了。

我為什麽要手賤點開submission?

這道題兩天之前被一個學弟A了。

我退役了。

其實就是爬山吧。。好像有的題解還分方向什麽的完全沒必要吧。

技術分享圖片
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <stdlib.h>
 5 #define pii pair<int,int>
 6 using namespace std;
 7 typedef double db;
 8 const db INF = 1e100;
9 const db delta = 0.98; 10 const db eps = 1e-8; 11 int sign(db k){ 12 if (k>eps) return 1; else if (k<-eps) return -1; return 0; 13 } 14 int cmp(db k1,db k2){return sign(k1-k2);} 15 struct point { 16 db x,y; 17 point operator - (const point &k1)const { return point{x-k1.x,y-k1.y};};
18 db abs(){ return sqrt(x*x+y*y);} 19 db dis(point k1){ return ((*this)-k1).abs();} 20 }; 21 db random(){ 22 return (rand()&1?1:-1)*rand()*1.0/32767; 23 } 24 int n;point p[105]; 25 point ans[10]; 26 db F(point x){ 27 db res = 0; 28 for(int i=0;i<n;i++){ 29 res+=x.dis(p[i]);
30 } 31 return res; 32 } 33 void SA(){ 34 db t = 100; 35 while (t>eps){ 36 for(int i=0;i<10;i++){ 37 db tmp = F(ans[i]); 38 for(int j=0;j<10;j++){ 39 point _x=point{ans[i].x+random()*t,ans[i].y+random()*t}; 40 db f = F(_x); 41 if(tmp>f) { 42 tmp = f; 43 ans[i]=_x; 44 } 45 } 46 } 47 t*=delta; 48 } 49 db ed = INF; 50 for(int i=0;i<10;i++) 51 ed=min(ed,F(ans[i])); 52 printf("%.0f",ed); 53 } 54 int main(){ 55 ios::sync_with_stdio(false); 56 scanf("%d",&n); 57 for(int i=0;i<n;i++){ 58 scanf("%lf%lf",&p[i].x,&p[i].y); 59 } 60 SA(); 61 }
View Code

poj 2420