Hfut 1288 galaxy 5A Scenic Area [third provincial competition in Anhui Province]

Source: Internet
Author: User

Reprinted please indicate the source, thank youHttp://blog.csdn.net/ACM_cxlove? Viewmode = Contents
By --- cxlove

Question: Give the four points on the ball, and find the coordinates of the ball center.

Http://acm.hfut.edu.cn/OnlineJudge/

It is simulated annealing...

At that time, I had no idea. I had to give up after I had been decisive.

For each vertex, we calculate the error from the center of the target. Variance ???

A random point, and then set an initial step, each time a random 30 direction out, if better than the current position, then update

Until the step size reaches the required precision.

The time limit for this question is 3 s, and the range is 1000. It seems that the precision requirement is still very high, and each step can be reduced by 0.05 times.

In the end, 1 S + is over and the efficiency is not high.

# Include <iostream> # include <fstream> # include <iomanip> # include <cstdio> # include <cstring> # include <algorithm> # include <cstdlib> # include <cmath> # include <set> # include <map> # include <queue> # include <stack> # include <string> # include <vector> # include <sstream> # include <ctime> # include <cassert> # define ll long # define EPS 1e-8 # define INF 999999.0 # define zero () FABS (a) <EPS # define N 20 # define PI ACOs (-1.0) using namesp Ace STD; struct point {Double X, Y, Z; bool check () {If (FABS (x) <500 + EPS & FABS (z) <500 + EPS & FABS (y) <500 + EPS) return true; return false ;}} P [4], cur, central; double dist (point P1, point P2) {return SQRT (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y) + (p1.z-p2.z) * (p1.z-p2.z);} // error between the Current State and the target State; double get_diff (point CEN) {double diff = 0, sum = 0, DIS [4]; for (INT I = 0; I <4; I ++) {dis [I] = dist (CEN, P [I]); sum + = dis [I];} sum /= 4; for (INT I = 0; I <4; I ++) diff + = (DIS [I]-sum) * (DIS [I]-sum ); return diff;} int main () {int T, CAS = 0; scanf ("% d", & T); While (t --) {for (INT I = 0; I <4; I ++) scanf ("% lf", & P [I]. x, & P [I]. y, & P [I]. z); Central. X = Central. y = Central. z = 0; // step size: initial 1000, initial position: 0, 0 double step = 1000, best = get_diff (central); While (Step> 0.001) {for (INT I = 0; I <30; I ++) {// random direction double A = (RAND () % 30000 + 1) /30000.0 * pI * 2; Double B = (RAND () % 30000 + 1 )/30000.0 * pI * 2; cur. X = Central. X + step * sin (a) * Cos (B); cur. y = Central. Y + step * sin (a) * sin (B); cur. z = Central. Z + step * Cos (a); If (! Cur. check () continue; double TMP = get_diff (cur); If (TMP + EPS <best) {best = TMP; Central = cur ;}} step * = 0.95 ;} printf ("case # % d: %. 1f %. 1f %. 1f \ n ", ++ cas, Central. x, Central. y, Central. z);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.