湖南大学第十四届ACM程序设计大赛 D Dandan's lunch

链接:https://ac.nowcoder.com/acm/contest/338/D
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 65536K,其他语言131072K
64bit IO Format: %lld

题目描述

    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.   

输入描述:

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.

输出描述:

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

示例1

输入

复制

1
100000000 0 0 10000 0 0 1000

输出

复制

10000000

说明

There's only Dandan alone.

示例2

输入

复制

4
3 0 0 1 0 0 1
1 0 0 2 0 0 2
2 0 0 3 0 0 3
4 0 0 4 0 0 4

输出

复制

9

说明

Dandan solved three problems, ranking second. Ranking first can get the biggest bread, so he can get the second largest bread.

备注:

1e5=100000
1e8=100000000
1e9=1000000000

题目大意:

众所周知,现在有N个人参加了比赛。比赛进行了3个小时后,终于到了吃午饭的时间。每个人都带了一个三角面包。当他们准备吃面包时,一些人发现他们解决的问题比其他人多,但他们的面包比其他人小。他们认为这很不公平。在这种情况下,他们会强行与对方交换面包(可以多次交换,如果满足上述条件,对方不能拒绝,交换后仍可以与他人交换)。
面包的描述由三角形三个顶点的坐标给出。面包的大小是三角形区域的两倍,确保没有两个相同大小的面包,每个人制造的问题数量也不一样。
丹丹也是参赛者之一。现在他知道每个人解决的问题的数量和他们带来的面包的描述。现在他想知道,在所有的交换都结束后(也就是说,任何两个人之间都不能再交换),他能得到的面包的大小。
第一行给出一个整数n,表示参加比赛的人数。
第2行~n+1,每行给出7个整数,用空格分隔,例如:
数字x1 y1 x2 y2 x3 y3
num表示第i次个人问题解决的次数。(x1,y1)(x2,y2)(x3,y3)表示三角形面包的三个点与第i个人的坐标。确保三个点不在同一条线上。
注意,第二行(第一个人)表示丹丹的信息。
数据保证:0<n<1e5,0<num<1e9,-1e8<x1,x2,x3,y1,y2,y3<1e8。
输出一个整数,表示丹丹最终得到的面包大小。

分析:题目说的很详细,那么,做题最多的人一定会得到最大的面包,做题第二多的人一定会得到第二大的面包。。。。做题最少的人一定会得到最小的面包,将每个人的做题数和面包大小进行排序,输出对应的面包大小即可。关键在于如何求面包的大小,题目提供了面包的三个点坐标。还说了面包的大小是三角形区域的两倍,我们就可以联想到用三点求三角形面积后再扩大2倍就是面包的大小。

设A(x1,y1),B(x2,y2),C(x3,y3)
由A-->B-->C-->A 按逆时针方向转。(行列式书写要求)
设三角形的面积为S
则S=(1/2)*(下面行列式)
|x1 y1 1|
|x2 y2 1|
|x3 y3 1|
S=(1/2)*(x1y2*1+x2y3*1+x3y1*1-x1y3*1-x2y1*1-x3y2*1)
即用三角形的三个顶点坐标求其面积的公式为:
S=(1/2)*(x1y2+x2y3+x3y1-x1y3-x2y1-x3y2)

则2S=(x1y2+x2y3+x3y1-x1y3-x2y1-x3y2)

注意求面积的结果是绝对值的形式。

#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll area(ll x1,ll y1,ll x2,ll y2,ll x3,ll y3)//已知三点求三角形面积
{
    return (labs(x1*y2+x2*y3+x3*y1-x1*y3-x2*y1-x3*y2));//注意结果要取绝对值
}
 
int main()
{
    long long x,n[100005],x1,y1,x2,y2,x3,y3,s[100005],k;
    cin>>x;
     
    for(int i=1;i<=x;i++)
    {
        cin>>n[i]>>x1>>y1>>x2>>y2>>x3>>y3;//依次输入每点做题数及三点坐标
        s[i]=area(x1,y1,x2,y2,x3,y3);
    }
    k=n[1];
    sort(n+1,n+x+1);//对做题数进行排序
    sort(s+1,s+x+1);//对面包大小进行排序
    for(int i=1;i<=x;i++)//对于大数据容易超时,建议使用二分查找。
    {
        if(n[i]==k)//如果查找数据做题数相对应
        {
            cout<<s[i]<<endl;//输出对应面包大小
            break;
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
国际程序设计大赛的作品欣赏 1、 先来第一个: 一段纯 3D 的 DOS 动画,据说是获一等奖的作品。虽然它不是最精美的, 但是当你得知它只有 4K 时,会不会立刻疯死掉呢? 附件:3ddemo.com 2、 再来一个: 幽灵古堡 farb-rausche 64.0 KB (65,536 字节) 恰好 65536 字节,显然是参赛作品。它非常漂亮(利用了 Direct3D),更让人惊奇的是只有 64K!而更让人震惊的是,如果不压缩的话它的数据大小是 1.6G!再体会一次“奇迹”! 附件:castle.exe 3、 再来一个: 死亡阴影 64.0 KB (65,536 字节) 附件:death.exe 4、 火域幻境 73.0 KB (74,752 字节) 虽然大小超过了 64K 的限制,但是它的效果可称为程序中的艺术品了! 附件:fire.exe 5、 fr-016 farb-rausche 16 字节 (16 字节) Let's rock hard!一个 DOS 里的小动画。看上去似乎没有什么特别,但是如果看到它的大小(16 字节),什么感觉????? 附件:fr-016.com 6、 第七天堂 Exceed 64.0 KB (65,536 字节) 由于参赛的要求是在 64K 之内即可,不少参赛者未免会有不到 65536 字节就有吃亏的感觉。 这是个 恰好 64K 的作品,可能利用了 DirectX 引擎,效果很好。 附件:heaven7.exe 7、 金属迷城 6.00 KB (6,144 字节) 考虑到它的大小时,你会不会体会到奇迹的含义 附件:metal.exe 8、 我要重点推荐的是这个作品fr-041_debris.exe(177K),效果是这所有作品之中最好的,一般的电脑无法流畅运行,我认为你买电脑时 可以把它带上运行一下作为一款测试工具。 附件:fr-041_debris.exe 9、 这个作品的效果和以上作品比都可名列前矛(64K),效果很好 附件:kkino64.exe 10、 这个就是传说中的25万倍压缩作品,prophecy《彗星撞地球》(63.5K)2000年时的最经典力作!画面看着挺舒服。 附件:prophecy《彗星撞地球》.exe 11、 爱之记忆 12、 3D裸女 13、 卡通 14、 光影 15、 FAiRLiGHT 这是在《三角洲3大地勇士》光碟版中带有的一个DEMO,发行组织FAiRLiGHT完全用原代码写出的自己组织的DEMO演示程序, 竟然才15K大小,画面也还行,对于他们的技术我们只能感到折服!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值