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 折纸 解法: 可以发现折纸之后被折到上面的部分实际上是没有用的,因为他和下面对应位置一定是一样的,而影响答案的只有每个位置的颜色和最底层的坐标范围.因此,我们只需要考虑最底层即可,即我们 ...
随机推荐
- Django - Jsonp、CORS
一.同源策略 https://www.cnblogs.com/yuanchenqi/articles/7638956.html 同源策略(Same origin policy)是一种约定,它是浏览器最 ...
- IDEA安装以及项目初始化
首先安装idea: 如果15.0版本安装不上就安装16.0: 点击安装文件以后,一直点下一步就可以了. 安装完成后设置: 如果没有的话,需要点击SDKs,点击+,然后选择电脑上安装的JDK. 接下来创 ...
- conda
Conda是什么? Conda 是Anaconda下用于包管理和环境管理的命令行工具, Conda下一切都是包,包括Python和conda自己 Conda ≍ pip(包管理) + vitualen ...
- 日志汇总:logging、logger
目录 1.日志输出到文件 2.日志输出到屏幕 3.设置输出等级 4.设置多个日志输出对象 5.日志的配置 6.记录异常 7.设置日志输出样式 1.日志输出到文件basicConfig()提供了非常便捷 ...
- mysql参数安全设置
MySQL安全相关的参数有哪些?该如何配置? 1.MySQL数据安全 innodb_flush_log_at_trx_commit =1 #innodb每次提交事务redo buffer 刷新到red ...
- sql server学习路径地址
联机丛书2005:https://docs.microsoft.com/zh-cn/previous-versions/sql/sql-server-2005/ms130214(v=sql.90) 联 ...
- EdrawSoft Edraw Max 9.1安装破解
1,安装软件[不要运行软件] 2,断网 3,打开Crack文件夹,复制”BaseCore.dll”,”ObjectModule.dll”到软件安装目录下替换原文件 默认的安装路径C:\Program ...
- sql小知识
1:查询某一段落内的几条数据,按时间降序. LIMIT 5,10; //检索记录行6-15 2:创建视图, 查询出某些类别的数据,保存在视图中. || 的优先级高于and ) ); 3: 查询出 ...
- tcp/udp/socket 端口映射,转发小工具
1) 利用 Python 的 Socket 端口转发,用于远程维护 https://github.com/knownsec/rtcp 2) 反向端口转发工具 Reverse TCP Port to U ...
- Python ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。
问题怎么出现的: 电脑是win8 64位,,下载了一个mysqldb 32位,http://sourceforge.net/projects/mysql-python/files/latest/dow ...