2017 Russian Code Cup (RCC 17), Elimination Round D - Acute Triangles
思路:
极角排序+点积叉积
在一个三角形中,如果它是直角或者顿角三角形,那么直角和顿角只会出现一次
所以直角和顿角三角形的个数等于直角和顿角的个数
所以锐角三角形的个数等于三元组个数减去直角和顿角的个数
三点共线看成退化的顿角三角形
怎么算直角和顿角个数呢, 先按某个点极角排序,然后暴力过取,用双指针维护到
当前幅角距离为pi/2 到 3*pi/2 的区间, 区间内点的个数就是到当前幅角为直角或顿角的个数
可以用点积和叉积分别判断角度和相对方向
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-(long double)1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 2e3 + ;
struct point {
LL x, y;
point(){}
point(LL x, LL y):x(x), y(y){}
LL dot(point p) {
return x*p.x + y*p.y;
}
LL cross(point p) {
return x*p.y - y*p.x;
}
}p[N], t[N];
bool anglecmp(point a, point b) {
if(a.y <= && b.y > ) return true;
if(a.y > && b.y <= ) return false;
if(!a.y && !b.y) return a.x < b.x;
return a.cross(b) > ;
}
bool acute(point a, point b) {
return a.dot(b) > && a.cross(b) >= ;
}
bool acute2(point a, point b) {
return a.dot(b) > && a.cross(b) < ;
}
int main() {
int T, n;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for (int i = ; i <= n; i++) scanf("%lld %lld", &p[i].x, &p[i].y);
LL ans = 1LL*n*(n-)*(n-)/;
for (int i = ; i <= n; i++) {
int cnt = ;
for (int j = ; j <= n; j++) {
if(j!=i)
t[++cnt] = point(p[j].x - p[i].x, p[j].y - p[i].y);
}
sort(t+, t++cnt, anglecmp);
int l = , r = ;
for (int j = ; j <= cnt; j++) {
while(l <= cnt && acute(t[j], t[l])) l++;
while(r <= cnt && !acute2(t[j], t[r])) r++;
ans -= r-l;
}
}
printf("%lld\n", ans);
}
return ;
}
2017 Russian Code Cup (RCC 17), Elimination Round D - Acute Triangles的更多相关文章
- 2017 Russian Code Cup (RCC 17), Final Round
2017 Russian Code Cup (RCC 17), Final Round A Set Theory 思路:原题转换一下就是找一个b数组,使得b数组任意两个数的差值都和a数组任意两个数的差 ...
- 2016 Russian Code Cup (RCC 16), Final Round B - Cactusophobia
B - Cactusophobia 思路: 点双联通分量+最大流 用tarjan求出每个点双联通分量 对于大小大于1的点双联通分量,它就是个环,那么源点和这个环相连, 容量为环的大小减一,这个环和环上 ...
- [Russian Code Cup 2017 - Finals [Unofficial Mirror]]简要题解
来自FallDream的博客,未经允许,请勿转载,谢谢. Div1难度+ACM赛制 和几个大佬组队逛了逛 A.给一个大小为n的集合ai(1<=ai<=1000000),要求你构造一个大小 ...
- 【CF1146】Forethought Future Cup - Elimination Round
Forethought Future Cup - Elimination Round 窝也不知道这是个啥比赛QwQ A. Love "A" 给你一个串,你可以删去若干个元素,使得最 ...
- CF1146 Forethought Future Cup Elimination Round Tutorial
CF1146 Forethought Future Cup Elimination Round Tutorial 叮,守夜冠军卡 https://codeforces.com/blog/entry/6 ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...
- Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words
Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...
- IntelliJ IDEA 2017.3.5 安装 lombok-plugin-0.17 失败,通过网络下载总是超时
1.问题: IntelliJ IDEA 2017.3.5 安装 lombok-plugin-0.17 失败,通过网络下载总是超时: 2.原因:IntelliJ IDEA 2017.3.5 目前还不支持 ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)
A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...
随机推荐
- UCloud首尔机房整体热迁移是这样炼成的
小结: 1.把两个机房在逻辑上变成一个机房: 2.新老机房的后端服务使用同一套 ZooKeeper,但是配置的却是不同的 IP: 3.UCloud内部服务所使用的数据库服务为MySQL, 内部MySQ ...
- 与HTTP关系密切的三个协议:IP,TCP,DNS
IP(网际协议): 位于网络层 通常易混淆的是“IP”和“IP地址”,单独讲“IP”是指一种协议名称 IP协议的作用是将各种数据包传送给对方.而要保证确实传送到对方那里,则需要满足各类条件. 其中两个 ...
- Django进阶之中间件
中间件简介 django 中的中间件(middleware),在django中,中间件其实就是一个类,在请求到来和结束后,django会根据自己的规则在合适的时机执行中间件中相应的方法. 在djang ...
- Spring框架的第三天
## Spring框架的第三天 ## ---------- **课程回顾:Spring框架第二天** 1. IOC的注解方式 * @Value * @Resource(name="" ...
- JAVA 重写equals和重写hashCode
面试官可能会问你:“你重写过 hashcode 和 equals 么,为什么重写equals时必须重写hashCode方法?” 首先你需要了解: hashCode()的作用是获取哈希码(散列码) 它实 ...
- 2014-2015 ACM-ICPC, Asia Xian Regional Contest GThe Problem to Slow Down You
http://blog.csdn.net/u013368721/article/details/42100363 回文树 建立两棵回文树,然后count处理一遍就可以了,然后顺着这两棵树的边走下去就 ...
- 20175208 《Java程序设计》第四周学习总结
第五章主要学习内容 1.子类的继承性: (1)子类与父类在同一包中的继承性:子类自然地继承了其父类中不是private的成员变量作为自己的成员变量. (2)子类与父类不在同一包中的继承性:子类只继承父 ...
- 改变FileUpload文件上传控件的显示方式,选择文件后自动上传
一.Aspx页面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="File ...
- CentOS 6.5系统中安装配置MySQL数据库
就像Windows server 2003,2008中一般安装的是Sql Server 数据库,在linux系统中一般安装的是mysql数据库,而且Mysql数据库的第一个版本就是发行在Linux系统 ...
- SpringBoot使用HttpClient远程调用
一. Get请求 try { //拼接url url = url+"access_token="+token+"&department_id=1&fetc ...