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 - ...
随机推荐
- SerialPort项目配置
app的build.gradle下: apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultCon ...
- 再说项目 Dec 27th 2018
其实对于任何项目来说,最难不是开发或者系统等技术的问题,反而是需求的问题,需求一直变,一直定不下来,导致流程变来变去,系统方案层面也确定不下来.而需求的问题,归根结底还是人的问题.项目的关键用户对现有 ...
- (转)Mysql哪些字段适合建立索引
工作中处理数据时,发现某个表的数据达近亿条,所以要为表建索引提高查询性能,以下两篇文章总结的很好,记录一下,以备后用. 数据库建立索引常用的规则如下: 1.表的主键.外键必须有索引: 2.数据量超过3 ...
- postgresql清理工具
1. 每个DB都单独进行了vacuumdb的命令: vacuumdb -d mydb -z -v 2. full vacuum : vacuumdb -a -f -z -v . 自动vacuum ...
- CSS——Flex
任何一个容器都可以指定为Flexbox布局 .flex-container { display: -webkit-flex; /* Safari */ display: flex; } 行内元素可以指 ...
- css修改整个项目的滚动条样式
在项目中,滚动条不可避免的药出现.设置统一规范的滚动条也是必然.用一个独立的css文件即可修改整个项目中的滚动条样式 . scrollBar.css: /* 滚动条有滑块的轨道部分 */ ::-web ...
- oracle入坑日记<六>自增列创建和清除(含序列和触发器的基础用法)
0 前言 用过 SQLserver 和 MySQL 的自增列(auto_increment),然而 Oracle 在建表设置列时却没有自增列. 查阅资料后发现 Oracle 的自增列需要手动编写. ...
- ImportError: No module named managers
代码: import os import cPickle as pickle filename = '../dftest.pkl' if(os.path.exists(filename)): w=op ...
- undefined symbol: PyFPE_jbuf
参考: https://blog.csdn.net/ture_dream/article/details/52733326 报错确实是Python的版本不一致. 但是我又不想删除anaconda. 怎 ...
- 为什么对string调用swap会导致迭代器失效
一般来说,swap操作将容器内容交换不会导致容器的指针.引用.迭代器失效. 但当容器类型为array和string时除外. 原因在于:SSO (Short String Optimization 指 ...