Codeforces Round #388 (Div. 2) - B

 

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

题意:给定平行四边形的3个点,输出所有可能的第四个点。

思路:枚举任意两个点形成的直线,然后利用这两个点计算偏移量用第三点求出第四个点。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<time.h>
#include<cmath>
using namespace std;
typedef long long int LL;
int main(){
//#ifdef kirito
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//#endif
//    int start = clock();
    pair<int, int>point[4];
    while (scanf("%d %d", &point[1].first,&point[1].second) != EOF){
        scanf("%d %d", &point[2].first, &point[2].second);
        scanf("%d %d", &point[3].first, &point[3].second);
        set<pair<int, int>>ans;
        for (int i = 1; i <= 3; i++){
            for (int j = i + 1; j <= 3; j++){
                pair<int, int>p4;
                int k = 6 - i - j; //非i,j的点
                int dx = point[i].first - point[j].first;
                int dy = point[i].second - point[j].second;
                p4.first = point[k].first + dx;
                p4.second = point[k].second + dy;
                ans.insert(p4);
                
                p4.first = point[k].first - dx;
                p4.second = point[k].second - dy;
                ans.insert(p4);
            }
        }
        printf("%d\n", ans.size());
        for (set<pair<int,int>>::iterator it=ans.begin(); it!= ans.end(); it++){
            printf("%d %d\n", it->first, it->second);
        }
    }
//#ifdef LOCAL_TIME
//    cout << "[Finished in " << clock() - start << " ms]" << endl;
//#endif
    return 0;
}

 

posted @ 2016-12-22 14:15  キリト  阅读(131)  评论(0编辑  收藏  举报