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 折纸 解法: 可以发现折纸之后被折到上面的部分实际上是没有用的,因为他和下面对应位置一定是一样的,而影响答案的只有每个位置的颜色和最底层的坐标范围.因此,我们只需要考虑最底层即可,即我们 ...
随机推荐
- BBS - 文章详细页、点赞、踩灭
一.文章详细页 文章详细页:1.链接:<div><h5><a href="/blog/{{ article.user.username }}/articles/ ...
- 第1章 1.10计算机网络概述--OSI参考模型和TCP_IP协议
传输层负责将大数据文件分段,变成数据段. 网络层负责为小分段加上IP地址,变成数据包. 数据链路层负责将数包加上MAC地址和校验值,变成数据帧. TCP/IP协议是一群协议.不只是2个协议.
- Mysql学习笔记—时间计算、年份差、月份差、天数差(转载)
1.获取当前日期 SELECT NOW(),CURDATE(),CURTIME(); 结果类似: 2. 获取前一天 DAY); 当前日期2018-09-17,结果: 3. 获取后一天 DAY); 当前 ...
- Zabbix设置自定义监控
[zabbix]自定义监控项key值 说明: zabbix自带的默认模版里包括了很多监控项,有时候为了满足业务需求,需要根据自己的监控项目自定义监控项,这里介绍一种自定义监控项的方式. 1,首先编 ...
- NFS-网络文件共享服务
目录 NFS介绍 什么是NFS(Network File System) 搭建NFS服务需要的软件包 极简步骤搭建NFS服务 准备两台机器 配置服务端(nfs-server) 配置客户端(web-cl ...
- 一个简单的3D范例,是在别人基础上面整理的。
一个简单的范例,是在别人基础上面整理的.原来的例子,框图太乱了,没有条理感. http://pan.baidu.com/s/1eQTyGCE
- 常微分方程初值问题:单步方法 [MATLAB]
#先上代码后补笔记# #可以直接复制粘贴调用的MATLAB函数代码!# 1. 朗格-库塔(Runge-Kutta)方法族 目前只实现了四阶Runge-Kutta方法. function [ YMat ...
- Linux 中的 Service
参考: cnblogs.com/xiaofan21 - linux service和daemon cnblogs.com/xuange306 - linux service命令常见使用方法 cnblo ...
- VS2010/MFC编程入门之二十一(常用控件:编辑框Edit Control)
鸡啄米上一节讲了静态文本框,本节要讲的编辑框(Edit Control)同样是一种很常用的控件,我们可以在编辑框中输入并编辑文本.在前面加法计算器的例子中已经演示了编辑框的基本应用.下面具体讲解编辑框 ...
- 使用 log4js UDP 发送数据到 logstash
本文地址 http://www.cnblogs.com/jasonxuli/p/6532723.html 因为 nodejs 一般会部署在多台机器,并且每台机器会起多个进程,因此查看日志时往往要人工区 ...