zoukankan      html  css  js  c++  java
  • 【codeforces 749B】Parallelogram is Back

    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.

    Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.

    Input
    The input consists of three lines, each containing a pair of integer coordinates xi and yi ( - 1000 ≤ xi, yi ≤ 1000). It’s guaranteed that these three points do not lie on the same line and no two of them coincide.

    Output
    First print integer k — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.

    Then print k lines, each containing a pair of integer — possible coordinates of the fourth point.

    Example
    input
    0 0
    1 0
    0 1
    output
    3
    1 -1
    -1 1
    1 1
    Note
    If you need clarification of what parallelogram is, please check Wikipedia page:

    https://en.wikipedia.org/wiki/Parallelogram

    【题目链接】:http://codeforces.com/contest/749/problem/B

    【题解】

    所给的是一个三角形的三个点;
    枚举以哪一条边作为平行四边形的对边就好;
    四边形的对边平分。
    用中点公式就能推出第4个点的坐标;

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%I64d",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    //const int MAXN = x;
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    
    struct abc
    {
        int x,y;
    };
    
    abc a[5];
    abc ans[1000];
    int k = 0;
    
    void tj(int a,int b)
    {
        k++;
        ans[k].x = a;ans[k].y = b;
    }
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        rep1(i,1,3)
            rei(a[i].x),rei(a[i].y);
        int x1 = a[1].x,y1 = a[1].y,x2 = a[2].x,y2 = a[2].y,x3 = a[3].x,y3 = a[3].y;
        int a = x1+x2-x3,b = y1+y2-y3;
        tj(a,b);
        a = x1+x3-x2,b = y1+y3-y2;
        tj(a,b);
        a = x3+x2-x1,b = y2+y3-y1;
        tj(a,b);
        printf("%d
    ",k);
        rep1(i,1,k)
            printf("%d %d
    ",ans[i].x,ans[i].y);
        return 0;
    }
  • 相关阅读:
    【Dart学习】-- Dart之匿名方法 & 回调函数 & 闭包
    【Dart学习】-- Dart之异常处理
    【Dart学习】-- Dart之操作符
    【Dart学习】-- Dart之注释
    【dart学习】-- Dart之元数据
    【Dart学习】-- Dart之泛型
    利用Aspose文档转图片
    结合仓库设计MVC控制器
    分享一个点赞超过100的漂亮ASP.NET MVC蓝色界面框架
    开发日记:接口开发设计
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626791.html
Copyright © 2011-2022 走看看