枚举直线,对于直线的某个点在直线的左端还是右端,能够状压出一个数。用bitset记录。

然后三角形就是3个bitset&一下

#include <cstdio>
#include <cstring>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 101;
const int M = 1005;
bitset<M> b1[N*N], b2[N*N];
int x[N], y[N], px[M], py[M];
bool check(int i, int j, int k) {
if(x[i] != x[j]) {
double yy = (double)(y[i] - y[j]) / (x[i] - x[j]) * (x[k] - x[i]) + y[i];
if(y[k] >= yy) return true;
else return false;
} else {
if(x[k] >= x[i])return true;
else return false;
}
}
void put(bitset<M> x) {
for(int i = 0; i < M; i ++) {
if(x[i]) printf("%d ", i);
}puts("*");
}
int main() {
int n, m, cas = 0;
while(~scanf("%d%d", &n, &m)) {
for(int i = 0; i < n; i ++) {
scanf("%d%d", &x[i], &y[i]);
}
for(int i = 0; i < m; i ++) {
scanf("%d%d", &px[i], &py[i]);
} for(int i = 0; i < n; i ++) {
for(int j = i+1; j < n; j ++) {
for(int k = 0; k < m; k ++) {
// printf("%d %d ", i, j);
if(x[i] != x[j]) {
double yy = (double)(y[i] - y[j]) / (x[i] - x[j]) * (px[k] - x[i]) + y[i];
if(py[k] == yy) {
b1[i*n+j].set(k);
b2[i*n+j].set(k);
}else if(py[k] > yy) {
b1[i*n+j].set(k);
// printf("u1-%d", k);
} else {
b2[i*n+j].set(k);
// printf("d1-%d", k);
}
} else {
if(px[k] == x[i]) {
b1[i*n+j].set(k);
b2[i*n+j].set(k);
}
else if(px[k] > x[i]) {
b1[i*n+j].set(k);
// printf("u2-%d", k);
} else {
b2[i*n+j].set(k);
// printf("d2-%d", k);
}
}
// puts("");
}
// printf(" %d %d %d %d\n", i, j, b1[i*n+j].count(), b2[i*n+j].count());
}
}
bitset<M> tmp(0);
int ans = 0;
for(int i = 0; i < n; i ++) {
for(int j = i+1; j < n; j ++) {
for(int k = j+1; k < n; k ++) {
if(check(i, j, k)) {
tmp = b1[i*n+j];
// printf("UU1 ");
// put(b1[i*n+j]);
}
else {
tmp = b2[i*n+j];
// put(b2[i*n+j]);
} if(check(i, k, j)) {
tmp &= b1[i*n+k];
// printf("UU2 ");
// put(b1[i*n+k]);
}
else {
tmp &= b2[i*n+k];
// put(b2[i*n+k]);
} if(check(j, k, i)) {
tmp &= b1[j*n+k];
// printf("UU3 ");
// put(b1[j*n+k]);
}
else {
tmp &= b2[j*n+k];
// put(b2[j*n+k]);
} // printf("***%d %d %d %d\n", i, j, k, tmp.count());
if(tmp.count() & 1) ans ++;
}
}
}
printf("Case %d: %d\n", ++cas, ans); for(int i = 0; i < n*n; i ++) {
b1[i].reset();
b2[i].reset();
}
}
return 0;
} /*
3 1
0 0
0 100
100 0
0 0 3 1
0 0
0 100
100 0
50 50 3 1
0 0
0 100
100 0
100 0 3 1
0 0
0 100
100 0
0 -1 4 4
0 0
0 100
100 0
-2 50 0 0
0 100
100 0
-1 50 */

HDU 4380 Farmer Greedy 计算几何+bitset的更多相关文章

  1. HDU 4380 Farmer Greedy(叉积和三角形知识的综合应用)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115760#problem/A 题目意思大致为由n个点(n小于100)和m个金矿 ...

  2. HDU 5130 Signal Interference(计算几何 + 模板)

    HDU 5130 Signal Interference(计算几何 + 模板) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5130 Descripti ...

  3. HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)

    Convex Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  4. HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...

  5. hdu 1348:Wall(计算几何,求凸包周长)

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  6. hdu 1174:爆头(计算几何,三维叉积求点到线的距离)

    爆头 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  7. 2017多校第5场 HDU 6085 Rikka with Candies bitset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6085 题意:存在两个长度为n,m的数组A,B.有q个询问,每个询问有一个数字k,可以得到Ai%Bj=k ...

  8. HDU 4920 Matrix multiplication(bitset)

    HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...

  9. hdu 4631Sad Love Story<计算几何>

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4631 题意:依次给你n个点,每次求出当前点中的最近点对,输出所有最近点对的和: 思路:按照x排序,然后用s ...

随机推荐

  1. Swift - 浮点数转换成整数(四舍五入与直接截断)

    1,直接截去小数部分转换成整数 使用强制转换会将浮点部分去除,把整数部分转换为整数. 1 var i = Int(23.50) //23 2,四舍五入转换成整数 lroundf是一个全局函数,作用是将 ...

  2. Java加入背景音乐

    近期有几个师妹找我给她们的Java期末作业加入背景音乐,非常久不琢磨Java的我花费整晚才搞定,羞愧.在博客中记录下来.警示自己.也帮助一下大家. Java中能够通过AudioClip类来实现音乐播放 ...

  3. qt宽字符串中文乱码(codec->toUnicode值得学习)

    乱码原因: QT使用的是utf-8 简体中文版的windows操作系统及其应用软件默认都是ANSI/GBK编码.而且这里应该是宽字符串. 多字节ANISGB 宽字符UNICODE 多字节显示标准字符的 ...

  4. Test oracle db iops

    Today, i need to test one database's iops and do something for oracle db's io test. How to test the ...

  5. POJ 2112 Optimal Milking【网络流+二分+最短路】

    求使所有牛都可以被挤牛奶的条件下牛走的最长距离. Floyd求出两两节点之间的最短路,然后二分距离. 构图: 将每一个milking machine与源点连接,边权为最大值m,每个cow与汇点连接,边 ...

  6. go语言初体验

    go下载地址: http://code.google.com/p/go/downloads/list go官方安装地址: http://golang.org/doc/install 另外收集一些关于g ...

  7. 计算VMT的长度

    function GetVirtualMethodCount(AClass: TClass): Integer; begin Result := (PInteger(Integer(AClass) + ...

  8. ThinkPhp学习08

    原文:ThinkPhp学习08 一.普通查询方式 a.字符串 $arr=$m->where("sex=0 and username='gege'")->find(); ...

  9. Java方法区和运行时常量池溢出问题分析(转)

    运行时常量池是方法区的一部分,方法区用于存放Class的相关信息,如类名.访问修饰符.常量池.字段描述.方法描述等. String.intern()是一个native方法,它的作用是:如果字符串常量池 ...

  10. IOT和HEAP表区别

    Index Organized table by itself is a B-tree index. Index key is the primary key and the rest of colu ...