UPC Contest 1748 Little Sub and Triangles

题目描述

Little Sub loves triangles. Now he has a problem for you.
Given n points on the two-dimensional plane, you have to answer many queries. Each query require you to calculate the number of triangles which are formed by three points in the given points set and their area S should satisfy l≤S≤r.
Specially, to simplify the calculation, even if the formed triangle degenerate to a line or a point which S = 0, we still consider it as a legal triangle.

 

输入

The fi rst line contains two integer n, q(1≤n≤250, 1≤q≤100000), indicating the total number of points.
All points will be described in the following n lines by giving two integers x, y(-107≤x, y≤107) as their coordinates.
All queries will be described in the following q lines by giving two integers l, r(0≤l≤r≤1018).

 

输出

Output the answer in one line for each query.

 

样例输入

复制样例数据

4 2
0 1
100 100
0 0
1 0
0 50
0 2

样例输出

3
1

思路:

           暴力,将每个三角形的面积都求出来,然后排序,找到在[l,r]范围内的个数即可。

AC代码

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
#define ll long long
struct point
{
    ll x,y;
}a[900];
ll b[9000000];
int main()
{
    int n,num=0,q;
    ll ans;
    scanf("%d %d",&n,&q);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld %lld",&a[i].x,&a[i].y);
         for(int j=1;j<i;j++){
            for(int k=j+1;k<i;k++){
                ans=abs((a[i].x-a[j].x)*(a[i].y-a[k].y)-(a[i].x-a[k].x)*(a[i].y-a[j].y));
                b[num++]=abs(ans);
            }
        }
    }
    sort(b,b+num);
    for(int i=0;i<q;i++)
    {
        ll l,r;
        scanf("%lld %lld",&l,&r);
        ll count1=(upper_bound(b,b+num,r*2)-b)-(lower_bound(b,b+num,l*2)-b);
        printf("%lld\n",count1);
    }
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, I'd be happy to give you some ideas for organizing a speech contest. Here are some suggestions: 1. Determine the theme and rules: Decide on the theme of the contest and the rules for participants. Will it be an open topic, or will there be a specific theme? What is the maximum length of the speech? Will there be any specific guidelines for language or content? 2. Decide on the judging criteria: Determine how the speeches will be evaluated. Will judges be looking for content, delivery, or both? Will there be a score sheet or rubric that judges will use to score the speeches? 3. Recruit judges: Find people who are qualified to judge the speeches. Ideally, they should have experience in public speaking or have a background in the theme of the contest. 4. Promote the contest: Advertise the contest to potential participants, such as students, professionals, or members of a specific community. Use social media, flyers, and other methods to get the word out. 5. Registration and selection: Set a deadline for registration and selection of participants. Consider having a preliminary round to narrow down the field before the final competition. 6. Prepare the venue: Ensure that the venue is suitable for the contest. Make sure that there is adequate seating, sound equipment, and lighting for the speakers. 7. Hold the contest: Set a date and time for the contest, and make sure that all participants and judges are aware of the schedule. Encourage audience participation and provide refreshments. 8. Award ceremony: After the contest, hold an award ceremony to recognize the winners and participants. Provide certificates or other prizes to the top performers. I hope these ideas help you in organizing a successful speech contest!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值