zoukankan      html  css  js  c++  java
  • 湖南大学第十四届ACM程序设计新生杯 Dandan's lunch

    Dandan's lunch

    Description:

    As everyone knows, there are now n people participating in the competition. It was finally lunch time after 3 hours of the competition. Everyone brought a triangular bread. When they were going to eat bread, some people found that they solved more problems than others, but their bread was smaller than others. They thought it was very unfair. In this case, they will forcibly exchange bread with the other party (may be exchanged many times, someone can still exchange with others after being exchanged if the above conditions are satisfied, the other party can not refuse).
    The description of the bread is given by the coordinates of the three vertices of the triangle. The size of the bread is twice the size of the triangle area, ensuring that there are no two breads of the same size, and the number of problems each person makes is different.
    Dandan is also one of the contestants. Now he knows the number of problems solved by each person and the description of the bread they bring. Now he wants to know that after all the exchanges are over (That is, there can be no more exchanges between any two people), The size of the bread he can get.

    Input:

    The first line gives an integer n, which indicates the number of people who participated in the competition.
    Lines 2~n+1, each line gives 7 integers separated by spaces such as:
    num x1 y1 x2 y2 x3 y3
    num represents the number of the ith personal problem solving. (x1, y1) (x2, y2) (x3, y3) represents the coordinates of the three points of the bread of the triangle with the i-th person. ensure that three points are not in the same line.
    Notice that the second line (the first person) represents Dandan's information.
    Data guarantee: 0<n<=1e5,0<=num<1e9, -1e8<x1, x2, x3, y1, y2, y3<1e8.

    Output:

    Outputs an integer representing the size of the bread that DanDan eventually gets.

    Sample Input:

    1
    100000000 0 0 10000 0 0 1000

    Sample Output:

    10000000

    题意:

    给出n个三角形的三个顶点坐标,求第x大的三角形面积的2倍是多少。(详见Description)

    题解:

    就是叉乘求平行四边形面积,注意下绝对值。后面排个序找一下就好了。

    代码如下:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    #include <queue>
    #include <cmath>
    using namespace std;
    typedef long long ll;
    const int N = 1e5+5;
    int n;
    int a[N];
    int main(){
        cin>>n;
        vector <ll> vec;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            int x1,x2,x3,y1,y2,y3;
            scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
            ll vecx1 = x2-x1,vecx2 = x3-x1;
            ll vecy1 = y2-y1,vecy2 = y3-y1;
            vec.push_back(vecx1*vecy2-vecy1*vecx2);
        }
        sort(vec.begin(),vec.end());
        int tmp=a[1];
        sort(a+1,a+n+1);
        for(int i=1;i<=n;i++){
            if(a[i]==tmp){
                cout<<vec[i-1];
                return 0;
            }
        }
        return 0;
    }
  • 相关阅读:
    撒旦撒旦撒
    的释放的是分
    识别真假搜索引擎(搜索蜘蛛)方法(baidu,google,Msn,sogou,soso等)
    [转]Tesseract-OCR (Tesseract的OCR引擎最先由HP实验室于1985年开始研发)
    使用SQLMAP对网站和数据库进行SQL注入攻击
    Kali Linux 安装教程-转
    【教程】如何修改路由表?
    基于comet服务器推送技术(web实时聊天)
    Ghost硬盘对拷
    Web 通信 之 长连接、长轮询(long polling)
  • 原文地址:https://www.cnblogs.com/heyuhhh/p/10229943.html
Copyright © 2011-2022 走看看