Codeforces 474c Captain marmot: Number of times the four vertices and their centers are rotated to a square

Source: Internet
Author: User
Tags cos

Question link: Click the open link

Question:

Given t indicates the number of cases

The following four rows are a case

2 vertices per line, U V

Each u can rotate around V to 90 ° counter-clockwise.

Ask the minimum number of operations to make four U forms a square.

Ideas:

Enumerative determination is feasible




#include <iostream>#include <cmath>#include <algorithm>#include <cstdio>using namespace std;int hah,ijj;int haifei;template <class T>inline bool rd(T &ret) {    char c; int sgn;    if(c=getchar(),c==EOF) return 0;    while(c!='-'&&(c<'0'||c>'9')) c=getchar();    sgn=(c=='-')?-1:1;    ret=(c=='-')?0:(c-'0');    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');    ret*=sgn;    return 1;}template <class T>inline void pt(T x) {    if (x <0) {        putchar('-');        x = -x;    }    if(x>9) pt(x/10);    putchar(x%10+'0');}///////////////////////const double eps = 1e-8;const double pi = acos(-1.0);struct node {    double x, y;};bool dcmp(double i, double j) {    return fabs(i - j) <= eps;}bool eq(const node& i, const node& j) {    return dcmp(i.x, j.x) && dcmp(i.y, j.y);}/*x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ;y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;*/node turn(const node& i, const node& j, double a) {    node re;    re.x= (i.x - j.x)*cos(a) - (i.y - j.y)*sin(a) + j.x;    re.y= (i.x - j.x)*sin(a) + (i.y - j.y)*cos(a) + j.y;    return re;}bool cc(const node& i, const node& j) {    if (!dcmp(i.x, j.x))        return i.x < j.x;    else        return i.y < j.y;}double sqr(double x) {    return x * x;}double D(node i, node j) {    return sqr(i.x-j.x) + sqr(i.y-j.y);}double dis[20];int idx;bool ok(node i, node j, node k, node z) {    node ar[4];    ar[0]=i; ar[1]=j; ar[2]=k; ar[3]=z;    idx = 0;    for (int i = 0; i < 4; ++i)        for (int j = i + 1; j < 4; ++j)            dis[idx++]=D(ar[i],ar[j]);    sort(dis, dis +idx);    if (dcmp(dis[0], dis[3]) && !dcmp(dis[0], 0) && dcmp(dis[4], dis[5]) && dcmp(dis[0] * 2, dis[4])) {        return true;    } else        return false;}int main() {    node a[10], b[10];    int T;    rd(T);    while (T -- > 0) {        for (int i = 0; i < 4; ++i)            scanf("%lf%lf%lf%lf", &a[i].x, &a[i].y, &b[i].x, &b[i].y);        int ans = 100;        for (int i = 0; i < 4; ++i)        for (int j = 0; j < 4; ++j)        for (int k = 0; k < 4; ++k)        for (int l = 0; l < 4; ++l)            if (ok(turn(a[0], b[0], i*pi/2),turn(a[1], b[1], j*pi/2),                   turn(a[2], b[2], k*pi/2),turn(a[3], b[3], l*pi/2))) {                        ans = min(i+j+k+l, ans);                   }        if (ans == 100)            ans = -1;        pt(ans);        putchar('\n');    }    return 0;}


Codeforces 474c Captain marmot: Number of times the four vertices and their centers are rotated to a square

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.