【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:输出调试了老半天,浪费大量时间...(难道就不能好好想想吗...

果然状态太差不适合做题

时间: 2024-08-05 14:24:08

【BZOJ】1074: [SCOI2007]折纸origami的相关文章

1074: [SCOI2007]折纸origami

Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 372  Solved: 229[Submit][Status][Discuss] Description 桌上有一张边界平行于坐标轴的正方形纸片,左下角的坐标为(0,0),右上角的坐标为(100,100).接下来执行n条折纸命令.每条命令用两个不同点P1(x1,y1)和P2(x2,y2)来表示,执行时把当前的折纸作品沿着P1P2所在直线折叠,并把有向线段P1P2的右边折向左边(左边的部分保持不变).

BZOJ1074 [SCOI2007]折纸origami

我们先看每个点可能从哪些点折过来的,2^10枚举对角线是否用到. 然后再模拟折法,查看每个点是否满足要求. 恩,计算几何比较恶心,还好前几天刚写过一道更恶心的计算几何,点类直接拷过来2333. 1 /************************************************************** 2 Problem: 1074 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:24 ms 7 Memory

P4468 [SCOI2007]折纸

题意 似乎边界上(折线上.正方形纸片边上)的点认为是\(0\). 由于操作次数很少,因此逆着操作,求出所有可能的点,之后正向模拟一遍判断即可. 求一个点关于一个向量的对称点:用向量旋转求出方向向量即可. code: #include<bits/stdc++.h> using namespace std; const int maxn=10; const double eps=1e-8; const double Pi=acos(-1.0); const double inf=1e9; int

CSS3写折纸

<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>折纸选项卡</title> <style> @-webkit-keyframes open { 0% { -webkit-transform:rotateX(-120deg);

关于折纸的动画

其实关于折纸的重点是在HTML和CSS的布局上主要就是要一个嵌套一个,如果不是的话,会有撑开的宽高从而难以连接在一起.不过折纸还没有写完一些兼容,也是参考视频上作的小练习 <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题</title></head><bo

BZOJ 1073: [SCOI2007]kshort

二次联通门 : BZOJ 1073: [SCOI2007]kshort /* BZOJ 1073: [SCOI2007]kshort A* k短路 但是会爆一个点, 是卡A*的 */ #include <cstdio> #include <iostream> #include <cstring> #include <queue> #include <vector> #include <algorithm> #include <c

折纸问题java实现

1 /** 2 * 折纸问题 这段代码写的太low了 本人水平有限 哎... 全是字符串了 3 * @param n 4 * @return 5 * @date 2016-10-7 6 * @author shaobn 7 */ 8 public static String[] flodpaper(int n){ 9 int length = (int)Math.pow(2,n)-1; 10 int position = (int)Math.pow(2,n-1)-1; 11 String[] s

例题1折纸痕

递归算法的思路,使用 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace 例题1折纸痕 {     

UVA 177 PaperFolding 折纸痕

著名的折纸问题:给你一张很大的纸,对折以后再对折,再对折……每次对折都是从右往左折,因此在折了很多次以后,原先的大纸会变成一个窄窄的纸条.现在把这个纸条沿着折纸的痕迹打开,每次都只打开“一半”,即把每个痕迹做成一个直角,那么从纸的一端沿着和纸面平行的方向看过去,会看到一条美妙的曲线. 就是一个分形,规定一下,纸的朝向,然后不难发现规律.图形输出方面,存下x和y坐标,然后下标排个序,或者用map. 为什么感觉模拟好难写啊... //Rey 2015.8.3 #include<bits/stdc++