BZOJ1074 [SCOI2007]折纸origami
我们先看每个点可能从哪些点折过来的,2^10枚举对角线是否用到。
然后再模拟折法,查看每个点是否满足要求。
恩,计算几何比较恶心,还好前几天刚写过一道更恶心的计算几何,点类直接拷过来2333。
/**************************************************************
Problem: 1074
User: rausen
Language: C++
Result: Accepted
Time:24 ms
Memory:980 kb
****************************************************************/ #include <cstdio>
#include <cmath>
#include <algorithm> using namespace std;
typedef double lf; const int N = ;
const lf eps = 1e-; int n, cnt; inline lf sqr(lf x) {
return x * x;
} inline int dcmp(lf x) {
return fabs(x) <= eps ? : (x > eps ? : -);
} struct point {
lf x, y;
point() {}
point(lf _x, lf _y) : x(_x), y(_y) {} inline point operator + (point p) {
return point(x + p.x, y + p.y);
}
inline point operator - (point p) {
return point(x - p.x, y - p.y);
}
inline lf operator * (point p) {
return x * p.y - y * p.x;
}
inline lf operator % (point p) {
return x * p.x + y * p.y;
}
inline point operator * (lf a) {
return point(x * a, y * a);
}
inline point operator / (lf a) {
return point(x / a, y / a);
} inline bool operator < (const point &p) const {
return dcmp(x - p.x) == ? dcmp(y - p.y) < : dcmp(x - p.x) < ;
}
inline bool operator != (const point &p) const {
return dcmp(x - p.x) || dcmp(y - p.y);
}
inline bool operator == (const point &p) const {
return !dcmp(x - p.x) && !dcmp(y - p.y);
} inline void read_in() {
scanf("%lf%lf", &x, &y);
}
friend inline lf dis2(point p) {
return sqr(p.x) + sqr(p.y);
}
friend inline lf dis(point p) {
return sqrt(dis2(p));
}
friend inline lf angle(point p, point q) {
return acos(p % q / dis(p) / dis(q));
}
friend inline point rotate(point p, lf A) {
lf s = sin(A), c = cos(A);
return point(p.x * c - p.y * s, p.x * s + p.y * c);
}
} ans[N << ]; struct line {
point p, v;
line() {}
line(point _p, point _v) : p(_p), v(_v){}
} l[N]; inline point reverse(point p, line l, int f) {
return l.p + rotate(p - l.p, angle(p - l.p, l.v) * * f);
} inline bool on_left(point p, line l) {
return dcmp((p - l.p) * l.v) < ;
} inline bool on_right(point p, line l) {
return dcmp((p - l.p) * l.v) > ;
} void dfs(point p, int d) {
ans[++cnt] = p;
if (d == ) return;
dfs(p, d - );
if (on_left(p, l[d])) dfs(reverse(p, l[d], -), d - );
} inline bool check(lf x) {
return dcmp(x) > && dcmp(x - ) < ;
} inline bool check(point p) {
return check(p.x) && check(p.y);
} inline point find(point p) {
int i;
for (i = ; i <= n; ++i)
if (on_right(p, l[i])) p = reverse(p, l[i], );
else if (!on_left(p, l[i])) return point(-, -);
return p;
} int work(point p) {
int res = , i;
cnt = ;
dfs(p, n);
sort(ans + , ans + cnt + );
cnt = unique(ans + , ans + cnt + ) - ans - ;
for (i = ; i <= cnt; ++i)
if (check(ans[i]) && find(ans[i]) == p) ++res;
return res;
} int main() {
int i, Q;
point x, y;
scanf("%d", &n);
for (i = ; i <= n; ++i) {
x.read_in(), y.read_in();
l[i] = line(x, y - x);
}
scanf("%d", &Q);
while (Q--) {
x.read_in();
printf("%d\n", work(x));
}
return ;
}
BZOJ1074 [SCOI2007]折纸origami的更多相关文章
- 【BZOJ】1074: [SCOI2007]折纸origami
http://www.lydsy.com/JudgeOnline/problem.php?id=1074 题意:一开始有一个左上角是(0,100),右下角是(100,0)的纸片,现在可以沿有向直线折n ...
- 1074: [SCOI2007]折纸origami - BZOJ
Description 桌上有一张边界平行于坐标轴的正方形纸片,左下角的坐标为(0,0),右上角的坐标为(100,100).接下来执行n条折纸命令.每条命令用两个不同点P1(x1,y1)和P2(x2, ...
- 1074: [SCOI2007]折纸origami
Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 372 Solved: 229[Submit][Status][Discuss] Descriptio ...
- 【题解】折纸 origami [SCOI2007] [P4468] [Bzoj1074]
[题解]折纸 origami [SCOI2007] [P4468] [Bzoj1074] 传送门:折纸 \(\text{origami [SCOI2007] [P4468]}\) \(\text{[B ...
- CSS3写折纸
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- 折纸问题java实现
/** * 折纸问题 这段代码写的太low了 本人水平有限 哎... 全是字符串了 * @param n * @return * @date 2016-10-7 * @author shaobn */ ...
- CSS3实现文字折纸效果
CSS3实现文字折纸效果 效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html> <head> <title></tit ...
- UVA 177 PaperFolding 折纸痕 (分形,递归)
著名的折纸问题:给你一张很大的纸,对折以后再对折,再对折……每次对折都是从右往左折,因此在折了很多次以后,原先的大纸会变成一个窄窄的纸条.现在把这个纸条沿着折纸的痕迹打开,每次都只打开“一半”,即把每 ...
- ZR#955 折纸
ZR#955 折纸 解法: 可以发现折纸之后被折到上面的部分实际上是没有用的,因为他和下面对应位置一定是一样的,而影响答案的只有每个位置的颜色和最底层的坐标范围.因此,我们只需要考虑最底层即可,即我们 ...
随机推荐
- jquery ztree 刷新后记录折叠、展开状态
ztree :http://www.ztree.me/v3/main.php 项目中用到了这个插件,刚好也有需求 在页面刷新后,保存开始的展开.折叠状态, 其实 dtree: http://www.d ...
- TA-Lib函数对照
Overlap Studies 重叠研究指标 BBANDS Bollinger Bands 布林带 DEMA Double Exponential Moving Average 双指数移动平均线 EM ...
- BBS - 表、登录、文件上传、注册
一.博客系统得表关系 models.py from django.db import models from django.contrib.auth.models import AbstractUse ...
- code sandbox & mlflow
https://codesandbox.io/ https://www.jianshu.com/p/d70b25bf3cf4 https://my.oschina.net/u/2306127/blog ...
- linux IO多路复用POLL机制深入分析
POLL机制的作用这里就不进行介绍,根据linux man手册,解释为在一个文件描述符上等待某个事件.按照抽象一点的理解,当某个事件被触发(条件被满足),文件描述符变为有状态,那么用户空间可以根据此进 ...
- java-mybaits-010-mybatis-spring-使用 SqlSession、注入映射器
一. SqlSession概述 在 MyBatis 中,你可以使用 SqlSessionFactory 来创建 SqlSession.一旦你获得一个 session 之后,你可以使用它来执行映射语句, ...
- Web安全大揭秘
web安全大揭秘,通常会有那些web安全问题呢? 1,xss 2,sql注入 3,ddos攻击
- cocos代码研究(21)Widget子类TextField学习笔记
基础理论 一个接受用户输入的widget. 输入文本的渲染基于TextFieldTTF. 如果你想用系统控制行为,请使用EditBox来替代.继承自 Widget. 代码实践 //与占位符有关void ...
- java之throw和throws
抛出异常有三种形式,一是throw,一个throws,还有一种系统自动抛异常.下面它们之间的异同. 一.系统自动抛异常 当程序语句出现一些逻辑错误.主义错误或类型转换错误时,系统会自动抛出异常:(举个 ...
- fedora修改主目录文件名为英文
在gnome-terminal里面能够显示中文的,但是在文本终端里面中文都是不能显示的,是一个小小的正方形.因此可以只把主目录文件名换成英文的,方便文本终端命令输入,而其他的一些地方还是 ...