TZOJ 2519 Regetni(N个点求三角形面积为整数总数)
描述
Background
Hello Earthling. We're from the planet Regetni and need your help to make lots of money. Maybe we'll even give you some of it.
You
see, the problem is that in our world, everything is about integers.
It's even enforced by law. No other numbers are allowed for anything.
That said, it shouldn't surprise you that we use integer coordinate
systems to plan our cities. So far only axis-aligned rectangular plots
of land have been sold, but our professor Elgnairt recently had the
revolutionary idea to sell triangular plots, too. We believe that the
high society will love this concept and it'll make us rich.
Unfortunately
the professor patented his idea and thus we can't just do it. We need
his permission and since he's a true scientist, he won't give it to us
before we solve some damn riddle. Here's where you come in,because we
heard that you're a genius.
Problem
The professor's riddle
goes like this: Given some possible corners for the triangles, determine
how many triangles with integral size can be built with them.
Degenerated triangles with empty area (i.e. lines) have to be counted,
too, since 0 is an integer. To be more precise, count the number of
triangles which have as corners three different points from the input
set of points. All points in a scenario will be distinct, i.e. there
won't be duplicates. Here are some examples:

Example
a) shows a triangle with integral area (namely 3), b) shows one with
non-integral size, c) shows a degenerated triangle with empty area (i.e.
zero, so count it!), d) shows four points of which you can choose any
three to build an integral area triangle and e) shows four points where
you can't build any integral area triangles at all.
Hint: The area A of a triangle with corners (x1, y1), (x2, y2) and (x3, y3) can be computed like this:
A=|x1y2 - y1x2 + x2y3 - y2x3 + x3y1 - y3x1|/2
Try to make clever use of this formula.
输入
The
first line contains the number of scenarios. For each scenario, there
is one line containing first the number N of distinct points in that
scenario (0 <= N <= 10000) and after that N pairs of integers,
each pair describing one point (xi, yi) with -100000 <= xi, yi <=
100000. All these numbers are separated by single blanks.
输出
Start
the output for every scenario with a line containing "Scenario #i:",
where i is the number of the scenario starting at 1. Then print a single
line containing the number of triangles with integral area whose three
distinct corners are among the points given. Terminate the output for
each scenario with a blank line.
样例输入
6
3 0 0 2 0 1 -3
3 0 0 2 1 1 -3
3 0 0 2 2 3 3
4 0 0 2 0 0 2 2 2
4 0 0 1 0 0 1 1 1
9 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2
样例输出
Scenario #1:
1
Scenario #2:
0
Scenario #3:
1
Scenario #4:
4
Scenario #5:
0
Scenario #6:
48
题意
给你N个点,求三角形面积为整数的总数
题解
A=|x1y2 - y1x2 + x2y3 - y2x3 + x3y1 - y3x1|/2
要使公式为整数,|x1y2 - y1x2 + x2y3 - y2x3 + x3y1 - y3x1|为偶
三个点P(x1,y1),Q(x2,y2),C(x3,y3)
可以发现上面的公式和PQC三点的x和y的奇偶性有关
令0=x偶y偶,1=x偶y奇,2=x奇y偶,3=x奇y奇。
打表完后利用组合数求个和。
代码
#include<bits/stdc++.h>
using namespace std; struct point
{
int p,q,c;
bool operator<(const point &d)const{
if(p<d.p)return true;
else if(p==d.p)
{
if(q<d.q)return true;
else if(q==d.q)
{
if(c<d.c)return true;
}
}
return false;
}
};
set<point>v;
void cs()
{
pair<int,int>po[];
po[]={,};
po[]={,};
po[]={,};
po[]={,};
for(int p=;p<;p++)
for(int q=;q<;q++)
for(int c=;c<;c++)
{
int x1,x2,x3,y1,y2,y3;
x1=po[p].first;y1=po[p].second;
x2=po[q].first;y2=po[q].second;
x3=po[c].first;y3=po[c].second;
if((x1*y2-y1*x2+x2*y3-y2*x3+x3*y1-y3*x1)%==)
{
int d[];
d[]=p;
d[]=q;
d[]=c;
sort(d,d+);
v.insert({d[],d[],d[]});
}
}
}
long long C(int n,int m)
{
if(m>n)return ;
long long sum=;
for(int i=;i<=m;i++)
sum=sum*(n-i+)/i;
return sum;
}
int main()
{
cs();
int t,n,ca=;
scanf("%d",&t);
while(t--)
{
int d[]={};
scanf("%d",&n);
for(int i=;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(x%==&&y%==)d[]++;
if(x%==&&y%!=)d[]++;
if(x%!=&&y%==)d[]++;
if(x%!=&&y%!=)d[]++;
}
long long sum=;
for(auto x:v)
{
int p=x.p;
int q=x.q;
int c=x.c;
printf("%d %d %d\n",p,q,c);
int f[]={};
f[p]++;f[q]++;f[c]++;
sum+=C(d[],f[])*C(d[],f[])*C(d[],f[])*C(d[],f[]);
}
printf("Scenario #%d:\n%lld\n\n",ca++,sum);
}
return ;
}
TZOJ 2519 Regetni(N个点求三角形面积为整数总数)的更多相关文章
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- hdu 4709:Herding(叉积求三角形面积+枚举)
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积
Maximal Area Quadrilateral CodeForces - 340B 三点坐标求三角形面积(可以带正负,表示向量/点的不同相对位置): http://www.cnblogs.com ...
- hdu4709求三角形面积
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- HDU 2036 叉乘求三角形面积
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- golang实现已知三角形三点坐标,求三角形面积
代码如下: func GetTriangleAreaByVector(x vector.Vector3,y vector.Vector3,z vector.Vector3) float64 { //根 ...
- 【C语言】已知三角形三边长,求三角形面积
一. 数学基础: 已知三角形的三边,计算三角形面积,需要用到海伦公式: 即p=(a+b+c)/2 二. 算法: 输入三个边长,套用海伦公式计算面积,并输出. 可以先判断是否可以构成三角形,即任意两边之 ...
- java求三角形面积以及周长---封装
/*时间: 2012-10-08作者: 烟大程序要求: 1.封装一类三角形对象Triangle,该类对象具有三条边的属性, 具有初始化三角形的功能.修改边长的功能.判断三条边能否构成三角形的功能. 求 ...
- POJ 2954 /// 皮克定理+叉积求三角形面积
题目大意: 给定三角形的三点坐标 判断在其内部包含多少个整点 题解及讲解 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 - 1 那么求内部整点就是 in = s + 1 - ...
随机推荐
- 持续更新scrapy的错误,ValueError: Missing scheme in request url:
只需要将 for href in response.xpath('XX').extract(): yield Request(hrefs) 修改为下面,就可以显示出来 for href in resp ...
- 2018-2019-2 20165312《网络攻防技术》Exp2 后门原理与实践
2018-2019-2 20165312<网络攻防技术>Exp2 后门原理与实践 课上知识点梳理总结 1.后门的概述 后门是指不经过正常认证流程而访问系统的通道 两个关键词:未认证.隐通道 ...
- scikit-learn框架学习笔记(一)
sklearn于2006年问世于Google,是使用python语言编写的.基于numpy.scipy和matplotlib的一个机器学习算法库,设计的非常优雅,它让我们能够使用同样的接口来实现所有不 ...
- 常见26种NLP任务的练手项目
经常有人问我:老大让我完成xxx,我不会,他也不会,但是很着急.这个任务怎么实现啊?这个任务需要什么技术啊?这种情况我遇到有100+次了,而且很多时候问得问题跟具体需要的技术简直是驴唇不对马嘴.所以今 ...
- React Native仿京东客户端实现(首页 分类 发现 购物车 我的)五个Tab导航页面
1.首先创建 这几个文件 myths-Mac:JdApp myth$ yarn add react-native-tab-navigator 2.各个文件完整代码 1)CartPage.js imp ...
- 关键字new与malloc函数
做题出bug,OJ说我没有定义new. 纳尼?new还需要定义?不都是直接用的吗,明明在自己的编译器里都可以通过的! 编译器:劳资是C++.... 一番倒腾后发现,我用的C++,但是OJ的编译器是C, ...
- 1. [Vue warn]: Missing required prop: "value"
意思是说数据没有绑定,页面缺少value值.应该v-model进行数据绑定.
- 李清华 201772020113《面向对象程序设计(java)》第十四周学习总结
1.实验目的与要求 (1) 掌握GUI布局管理器用法: (2) 掌握各类Java Swing组件用途及常用API: 2.实验内容和步骤 实验1: 导入第12章示例程序,测试程序并进行组内讨论. 测试程 ...
- 7Linux存储结构和磁盘划分
FHS yum的.repo的配置文件多个的话,是依次生效吗? /boot 开机所需文件—内核.开机菜单以及所需配置文件等/dev 以文件形式存放任何设备与接口/etc 配置文件/home 用户主目录/ ...
- mac安装linux双系统的吐槽
[First day] 尝试安装mac - linux 双系统 首先,尝试的是ubuntu16.06版本,要把双系统安装至电脑硬盘512G SSD中, *** 分盘 1.1 打开实用工具中的磁盘管理工 ...