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 - ...
随机推荐
- altera DDR2 IP核之仿真
在生成的IP核文件夹下,有一个testbench文件夹,里面包含了一个example测试激励和DDR2仿真模型. 如下 20 -rw-r--r-- 1 Administrator 197121 171 ...
- Windows和MacOS的比较——不断完善和补充,欢迎吐槽
1. 鼠标滚轮的方向不一样,Windows上滚轮朝下,页面滚动条也会朝下.而Mac上则相反. 2. Windows上有Home和End键,经常可以Ctrl+Home,Ctrl+End,Ctrl+Shi ...
- winform里面的Form1.Designer.cs
Program.cs是程序入口,也就是Main函数.Form1.cs是实现功能的代码,包括你的自定义方法和事件.Form1.Designer.cs是你的画面的设计代码,一般由系统自动生成,也可以手动修 ...
- Java异常处理——如何跟踪异常的传播路径?
当程序中出现异常时,JVM会依据方法调用顺序依次查找有关的错误处理程序. 可使用printStackTrace 和 getMessage方法了解异常发生的情况: printStackTrace:打印方 ...
- [Unity优化]批处理03:静态批处理
原理: 运行时,把需要进行静态批处理的网格合并到一个新的网格中.虽然只进行一次合并操作,但是会占用更多的内存来存储合并后的网格,并且被静态批处理的物体无法移动旋转缩放 要使用静态批处理,需要把Stat ...
- zk hdfs hadoop yarn hive 学习笔记
如图
- 深入理解Java虚拟机读书笔记9----线程完全与锁优化
九 线程完全与锁优化 1 Java语言中的线程完全 ---线程安全:当多个线程访问一个对象时,如果不用考虑这些线程在运行时环境下的调度和交替执行,也不需要进行额外的同步,或者在调用 ...
- Shell 批量修改主机 用户密码
问题:132.121.114 和 132.121.118 网段共 48 台主机未添加基础监控,但是 wh 账户不能登录 需进行批量修改密码操作. 目前情况:op1对上述48台机器设备均能免密登录. 操 ...
- vue源码逐行注释分析+40多m的vue源码程序流程图思维导图 (diff部分待后续更新)
vue源码业余时间差不多看了一年,以前在网上找帖子,发现很多帖子很零散,都是一部分一部分说,断章的很多,所以自己下定决定一行行看,经过自己坚持与努力,现在基本看完了,差ddf那部分,因为考虑到自己要换 ...
- 回溯法 Generate Parentheses,第二次总结
class Solution { public: vector<string> ans; void helper(string& cur, int left, int right, ...