【BZOJ】1074: [SCOI2007]折纸origami
http://www.lydsy.com/JudgeOnline/problem.php?id=1074
题意:一开始有一个左上角是(0,100),右下角是(100,0)的纸片,现在可以沿有向直线折n次(n<=8,右边折向左边),折完后,有m个询问(m<=50),每次询问一个点在最终的图形中穿过了几次纸片。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <sstream>
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
inline int getint() { static int r, k; r=0,k=1; static char c; c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } const double eps=1e-6, PI2=acos(-1)*2;
int dcmp(double x) { return abs(x)<eps?0:(x<0?-1:1); }
struct iP { double x, y; iP(double _x=0, double _y=0):x(_x),y(_y){} void rd() { scanf("%lf%lf", &x, &y); } void D() { printf("x=%.2f, y=%.2f\n", x, y); }};
typedef iP iV;
iV operator-(iP a, iP b) { return iV(a.x-b.x, a.y-b.y); }
iV operator*(iV a, double b) { return iV(a.x*b, a.y*b); }
iV operator+(iP a, iV b) { return iP(a.x+b.x, a.y+b.y); }
bool operator==(iP a, iP b) { return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0; }
bool operator<(const iP &a, const iP &b) { return a.x==b.x?a.y<b.y:a.x<b.x; }
double cross(iV a, iV b) { return a.x*b.y-a.y*b.x; }
double dot(iV a, iV b) { return a.x*b.x+a.y*b.y; }
double Length(iV a) { return sqrt(dot(a, a)); }
double angle(iV a, iV b) { return acos(dot(a, b)/Length(a)/Length(b)); }
iV rot(iV v, double ang) { double cs=cos(ang), sn=sin(ang); return iV(v.x*cs-v.y*sn, v.y*cs+v.x*sn); }
struct iL { iP p; iV v; iL(){} iL(iP _p, iV _v):p(_p),v(_v) {} }; bool onL(iP a, iL l) { return dcmp(cross(a-l.p, l.v))<0; }
bool onR(iP a, iL l) { return dcmp(cross(a-l.p, l.v))>0; }
iP rev(iP a, iL l, int flag=1) { return l.p+rot(a-l.p, angle(a-l.p, l.v)*2*flag); } const int Mx=1<<10;
iP h[Mx];
iL line[10];
int n, m, cnt; void dfs(int dep, iP p) {
//if(dcmp(p.x)<=0 || dcmp(p.x-100)>=0 || dcmp(p.y)<=0 || dcmp(p.y-100)>=0) return;
h[cnt++]=p;
if(dep==0) return;
dfs(dep-1, p);
if(onL(p, line[dep])) dfs(dep-1, rev(p, line[dep], -1));
}
iP find(iP p) {
for1(i, 1, n) if(onR(p, line[i])) p=rev(p, line[i]); else if(!onL(p, line[i])) return iP(-1, -1);
return p;
}
bool check(iP &p) { if(dcmp(p.x)<=0 || dcmp(p.x-100)>=0 || dcmp(p.y)<=0 || dcmp(p.y-100)>=0) return false; return true; }
void work(iP &p) {
//if(dcmp(p.x)<=0 || dcmp(p.x-100)>=0 || dcmp(p.y)<=0 || dcmp(p.y-100)>=0) { puts("0"); return; }
int ans=0;
cnt=0;
dfs(n, p);
sort(h, h+cnt);
cnt=unique(h, h+cnt)-h;
rep(i, cnt) if(check(h[i]) && find(h[i])==p) ++ans;
printf("%d\n", ans);
} int main() {
read(n);
for1(i, 1, n) {
iP p1, p2;
p1.rd(); p2.rd();
line[i]=iL(p1, p2-p1);
}
read(m);
for1(i, 1, m) {
iP p; p.rd();
work(p);
}
return 0;
}
这题很神....
看了题解简直惊呆了QAQ逆向思维...
首先我们对于每个点,我们先看看这个点可能由哪些点转移而来(按折纸顺序排序的折纸操作的子集),最多只有$2^8$个这样的点。最后我们再枚举这些点看能否折回原来的点。(注意,如果折的时候正在判定的点在这个直线上,那么这是无解的,因为穿过边界不算。而且永远也不会有正方形的一部分覆盖到这里了)
但是我陷入到了计算几何调试不出来的坑...想个问题似乎想了2h.................................................sb错1:计算向量之间的角我竟让忘记打上acos......调了无数次.... sb错2:输出调试了老半天,浪费大量时间...(难道就不能好好想想吗...
果然状态太差不适合做题
【BZOJ】1074: [SCOI2007]折纸origami的更多相关文章
- 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 ...
- BZOJ1074 [SCOI2007]折纸origami
我们先看每个点可能从哪些点折过来的,2^10枚举对角线是否用到. 然后再模拟折法,查看每个点是否满足要求. 恩,计算几何比较恶心,还好前几天刚写过一道更恶心的计算几何,点类直接拷过来2333. /** ...
- 【题解】折纸 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 */ ...
- POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)
POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...
- CSS3实现文字折纸效果
CSS3实现文字折纸效果 效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html> <head> <title></tit ...
- bzoj 1067: [SCOI2007]降雨量
题目链接: bzoj 1067: [SCOI2007]降雨量 题解: 很简单的一道题,但代码里有许多细节需要注意,切容易出错,调了三个小时OTZ 做一个st表维护区间最大值就 在获得年份在序列中的po ...
随机推荐
- 把sql server 2000的用户表的所有者改成dbo
怎么样把sql server 2000的用户表的所有者,改成dbo,而不是用户名. 推荐使用下面介绍的第二种方法,执行以下查询便可以了.sp_configure 'allow updates','1' ...
- 《ASP.NET MVC4 WEB编程》学习笔记------Web API
本文截取自情缘 1. Web API简单说明 近来很多大型的平台都公开了Web API.比如百度地图 Web API,做过地图相关的人都熟悉.公开服务这种方式可以使它易于与各种各样的设备和客户端平台集 ...
- CheckBoxList1复选框
循环绑定数据的两个方法: List<string> LIColl = new List<string>(); protected void Page_Load(object s ...
- location 、history
location.href= location.reload() history.go() 0 1 -1 history.back() history.forward() history.le ...
- Object-c 控制语句
控制语句: 分支语句 if-else 有控制机制 switch 循环语句 while do-while for 跳转语句 break,continue,goto
- iOS 和 Android 中的后台运行问题
后台机制的不同,算是iOS 和 Android的一大区别了,最近发布的iOS7又对后台处理做了一定的更改,找时间总结一下编码上的区别,先做个记录. 先看看iOS的把,首先需要仔细阅读一下Apple的官 ...
- FZU 2148 moon game (计算几何判断凸包)
Moon Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- myeclipse2013和以后版本破解
当你下到最新版的myeclipse-blue的时候你是否会为注册激活而烦恼呢,别担心,其实激活也就那么点事儿,请遵循我如下做法就可以了: 1.运行jdk下面的cracker.jar文件来打开生成活跃码 ...
- Ubuntu下VIM的安装和基本用法
1.用root账户登录Ubuntu,命令行中输入vim,如果未安装会得到下面的提示: 程序“vim”已包含在下列软件包中: * vim * vim-gnome * vim-tiny * vim ...
- [原]网站跨站点脚本,Sql注入等攻击的处理
从360安全论坛里找到的一段代码,经过整理封装,直接在站点Global.asax文件或写一个HttpModule来拦截恶意请求即可: http://bbs.webscan.360.cn/forum.p ...