FZU 2242 - Daxia like acute triangle

 Problem 2242 Daxia like acute triangle

Accept: 26    Submit: 99
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

半径为r的圆上有n个不重复的点,请你帮daxia计算这些点能构成多少个不同的锐角三角形.

 Input

测试包含多组数据,每组数据第一行包含两个整数:n(1<=n<=20000),r(1<=r<=20000).

接下来包含n行,每行包含一个整数x(-r<=x<=r)和一个不等式"y<=0"或"y>=0".

 Output

每组数据输出一行一个整数表示锐角三角形的总个数.

 Sample Input

6 20 y<=01 y<=02 y<=0-2 y>=0-1 y>=00 y>=0

 Sample Output

2

 Hint

最好避开浮点运算

 Source

FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)



POINT:

对每一个点的半圆求直角和钝角的个数,然后取反。要用cout输出,不然wa


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int maxn = 20000+5;
typedef long long LL;
struct node
{
    int x,y;
    node(int xx=0,int yy=0):
    x(xx),y(yy){}
}a[maxn];
char s[4];
bool cmd(node a,node b)
{
    if(a.y!=b.y){
        return a.y<b.y;
    }
    else if(a.y==-1){
        return a.x<b.x;
    }else{
        return a.x>b.x;
    }
}
int main()
{
    int n,r;
    while(~scanf("%d %d",&n,&r)){
        for(int i=1;i<=n;i++){
            int x;scanf("%d %s",&x,s);
            if(s[1]=='<') a[i].y=-1;
            else a[i].y=1;
            a[i].x=x;
        }
        sort(a+1,a+1+n,cmd);
        LL ans=((LL)(n)*(n-1)*(n-2))/6;
        for(int i=1;i<=n;i++){
            if(a[i].y==-1){
                int num=upper_bound(a+1,a+1+n,node(-a[i].x,-a[i].y),cmd)-a-i-1;
                ans-=1LL*num*(num-1)/2;
            }
            else{
                int num=upper_bound(a+1,a+1+n,node(-a[i].x,-a[i].y),cmd)-a-1+(n-i);
                ans-=1LL*num*(num-1)/2;
            }

        }
        cout<<ans<<endl;
    }


}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值