TYVJ计算几何
今天讲了计算几何,发几道水水的tyvj上的题解...
计算几何好难啊!@Mrs.General....怎么办....
这几道题都是在省选之前做的,所以前面的Point运算啊,dcmp啊,什么什么的,基本上没用,每次都把上次的main()函数删了接着继续写....
原谅我曾经丑出翔的代码...
虽然现在也很丑...
TYVJ 1150 绳子围点
题解:
凸包 + 凸包面积 + 皮克定理
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll; const int MAXN = + ; char cj;
int n, m; struct Point{//{{{
ll x, y; friend bool operator < (const Point& A, const Point& B){
return A.x < B.x || (A.x == B.x && A.y < B.y);
}
} p[MAXN], ch[MAXN * ];//}}} inline ll xmult(Point a, Point b, Point c){//{{{
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
} inline void AndrweScan(){
sort(p, p + n);
m = , ch[] = p[], ch[] = p[];
for (int i = ; i < n; i ++){
while (m >= && xmult(ch[m], ch[m - ], p[i]) > )
m --;
ch[++ m] = p[i];
} for (int i = n - ; i >= ; i --){
while (m >= && xmult(ch[m], ch[m - ], p[i]) > )
m --;
ch[++ m] = p[i];
}
}//}}} inline ll nextLL(){
bool flag = false;
do {
cj = getchar();
if (cj == '-')
flag = true;
} while (!( <= cj && cj <= )); ll ret = ;
do {
ret = ret * + cj - ;
cj = getchar();
} while ( <= cj && cj <= ); return flag ? -ret : ret;
} inline int nextInt(){
do
cj = getchar();
while (!( <= cj && cj <= )); int ret = ;
do {
ret = ret * + cj - ;
cj = getchar();
} while ( <= cj && cj <= ); return ret;
} inline ll Plot(){
ll ret = ;
for (int i = ; i < m; i ++)
ret += xmult(ch[], ch[i - ], ch[i]);
return ret;
} inline ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
} inline ll Cal(int i){
int j = (i == m - ) ? : i + ,
dx = ch[i].x - ch[j].x, dy = ch[i].y - ch[j].y;
return gcd(abs(dx), abs(dy));
} inline void Pick(){
ll dS = Plot(), b = , a;
for (int i = ; i < m; i++)
b += Cal(i);
a = (dS - b + ) / ;
printf("%lld\n", a + b);
} int main(){
n = nextInt();
for (int i = ; i < n; i++)
p[i].x = nextLL(), p[i].y = nextLL();
AndrweScan();
Pick();
}
TYVJ 1543 房间最短路
题解:
Floyd,dp[i][j]表示到第i面墙的第j个点的最短路,注意在更新最小值的时候判断两个点的连通
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define INF 100000000
#define eps 1e-9 const int MAXN = ; int n;
double dp[MAXN][MAXN]; struct Point{
double x, y; friend Point operator + (const Point A, const Point B){
return (Point){A.x+B.x, A.y+B.y};
} friend Point operator - (const Point A, const Point B){
return (Point){A.x-B.x, A.y-B.y};
} friend Point operator * (const Point A, const Point B){
return (Point){A.x*B.x, A.y*B.y};
} friend Point operator / (const Point A, const Point B){
return (Point){A.x/B.x, A.y/B.y};
}
}p[MAXN][MAXN]; inline Point make_Point(double X, double Y){
return (Point){X, Y};
} inline double len(Point A){
return sqrt(A.x*A.x+A.y*A.y);
} inline bool In_region(double eg, double l, double r){
if (l>r) swap(l, r);
return (l-eps<=eg && eg<=r+eps);
} inline bool Connected(int I1, int I2, int I3, int I4){
if (I1>I3) swap(I1, I3);
if ((I1==I3 && I2==I4) || I3-I1==) return true;
double k = (p[I1][I2].y-p[I3][I4].y)/(p[I1][I2].x-p[I3][I4].x), b = p[I1][I2].y-p[I1][I2].x*k, bn;
for (int i=I1+; i<I3; i++){
bn = p[i][].x*k+b;
if (!In_region(bn, p[i][].y, p[i][].y) && !In_region(bn, p[i][].y, p[i][].y)) return false;
}
return true;
} int main(){
scanf("%d", &n); p[][] = p[][] = p[][] = p[][] = make_Point(, );
p[n+][] = p[n+][] = p[n+][] = p[n+][] = make_Point(, ); double x, in, apl;
for (int i=; i<=n; i++){
scanf("%lf", &x);
for (int j=; j<; j++)
scanf("%lf", &in), p[i][j] = make_Point(x, in);
} //init
for (int i=; i<; i++)
dp[][i] = 0.0;
for (int i=; i<=n+; i++)
for (int j=; j<; j++)
dp[i][j] = Connected(, , i, j) ? len(p[i][j]-p[][]) : INF; for (int i=; i<=n+; i++)
for (int j=; j<; j++)
for (int k=; k<i; k++)
for (int l=; l<; l++)
if (Connected(k, l, i, j)) dp[i][j] = min(dp[i][j], dp[k][l]+len(p[i][j]-p[k][l]));
apl = INF;
for (int i=; i<; i++)
apl = min(apl, dp[n+][i]);
printf("%.2lf\n",apl);
return ;
}
TYVJ 1462 凸多边形
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define eps 1e-12
using namespace std; const int MAXN = +; int n; struct Point{
long double x, y; friend Point operator - (const Point& A, const Point& B){
return (Point){A.x-B.x, A.y-B.y};
} friend long double operator * (const Point& A, const Point& B){//cross
return A.x*B.y-A.y*B.x;
} friend bool operator < (const Point& A, const Point& B){
return (A.x!=B.x) ? A.x<B.x : A.y<B.y;
} inline void print(){
cout<<setiosflags(ios::fixed)<<setprecision()<<x<<" "<<setiosflags(ios::fixed)<<setprecision()<<y<<"\n";
}
}p[MAXN], ch[MAXN]; inline int dcmp(long double eg){
if (eg>eps) return ; //>0
if (eg<-eps) return -;//<0
else return ;
} inline void GrahamScan(){
int tot, t;
sort(p, p+n); ch[] = p[], ch[] = p[], tot = ;
for (int i=; i<n; i++){
while (tot> && dcmp((ch[tot]-ch[tot-])*(p[i]-ch[tot-]))!=-) tot--;
ch[++tot] = p[i];
} t = tot, ch[++tot] = p[n-];
for (int i=n-; i>=; i--){
while (tot>t && dcmp((ch[tot]-ch[tot-])*(p[i]-ch[tot-]))!=-) tot--;
ch[++tot] = p[i];
} for (int i=; i<tot; i++)
ch[i].print();
} int main(){
scanf("%d", &n);
for (int i=; i<n; i++)
cin>>p[i].x>>p[i].y; GrahamScan();
return ;
}
TYVJ 1523 神秘大三角
题解:
这道题考的是读入...面积随便整一下就好了
#include <cstdio>
#include <cmath>
#include <algorithm>
#define eps 1e-9
using namespace std; const int MAXL = ; struct Point{
double x,y; inline void in(){
char s[MAXL];
scanf("%s",s);
int i;
x = ,y = ;
for (i=;;i++){
if (s[i]==',') break;
x *= ,x += s[i]-;
}
for (i+=;;i++){
if (s[i]==')') break;
y *= ,y += s[i]-;
} } inline void out(){
printf("%.2lf %.2lf\n",x,y);
} inline bool is_zero(){
return (y== && x==);
} inline double len(){
return sqrt(x*x-y*y);
} friend Point operator + (const Point A,const Point B){
return (Point){A.x+B.x,A.y+B.y};
} friend Point operator - (const Point A,const Point B){
return (Point){A.x-B.x,A.y-B.y};
} friend Point operator * (const Point A,const double B){
return (Point){A.x*B,A.y*B};
} friend Point operator / (const Point A,const double B){
return (Point){A.x/B,A.y/B};
} friend bool operator == (const Point A,const Point B){
return (A.x==B.x && A.y==B.y);
}
}A,B,C,D; inline double area(Point p1,Point p2,Point p3){
return abs(0.5*(p1.x*p2.y+p2.x*p3.y+p3.x*p1.y-p1.y*p2.x-p2.y*p3.x-p3.y*p1.x));
} inline bool on(Point Aa,Point Ba,Point q){
double MX = max(Aa.x,Ba.x);
double mx = min(Aa.x,Ba.x);
double MY = max(Aa.y,Ba.y);
double my = min(Aa.y,Ba.y);
return ((mx<q.x && q.x<MX) && (my<q.y && q.y<MY)) ? true : false;
} inline bool zero(double eg){
return (eg>-eps && eg<eps);
} inline int appleeeeeeee(){
A.in();B.in();C.in();D.in();
if (A==D || B==D || C==D) return ;//顶点上
double s1,s2,s3,s;
s = area(A,B,C);
s1 = area(A,B,D);
s2 = area(A,C,D);
s3 = area(B,C,D); if (zero(s1) && on(A,B,D)) return ;
if (zero(s2) && on(A,C,D)) return ;
if (zero(s3) && on(B,C,D)) return ;//边上 if ((s1+s2+s3-s)<eps && (s1+s2+s3-s)>-eps) return ;
else return ;
} int main(){
printf("%d",appleeeeeeee());
return ;
}
TYVJ 1544 角平分线
题解:
推个公式就好了
#include <cstdio>
#include <cmath> struct Point{
double x,y; inline void in(){
scanf("%lf%lf",&x,&y);
} inline void out(){
printf("%.2lf %.2lf",x,y);
} friend Point operator + (const Point A,const Point B){
return (Point){A.x+B.x,A.y+B.y};
} friend Point operator - (const Point A,const Point B){
return (Point){A.x-B.x,A.y-B.y};
} friend Point operator * (const Point A,const double B){
return (Point){A.x*B,A.y*B};
} friend Point operator / (const Point A,const double B){
return (Point){A.x/B,A.y/B};
}
}a,b,c,d; inline double len(Point eg){
return sqrt(eg.x*eg.x+eg.y*eg.y);
} int main(){
a.in();b.in();c.in();
b = b-a,c = c-a;
double AB = len(b),AC = len(c);
double cj = (AB*AC)/(AB+AC);
d = b/AB + c/AC;
d = d*cj;
d = d + a;
d.out();
return ;
}
TYVJ计算几何的更多相关文章
- [BZOJ3223]Tyvj 1729 文艺平衡树
[BZOJ3223]Tyvj 1729 文艺平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区 ...
- [BZOJ3224]Tyvj 1728 普通平衡树
[BZOJ3224]Tyvj 1728 普通平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除一个) ...
- ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)
POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...
- HDU 2202 计算几何
最大三角形 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- BZOJ3223: Tyvj 1729 文艺平衡树 [splay]
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3595 Solved: 2029[Submit][Sta ...
- BZOJ 3224: Tyvj 1728 普通平衡树
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 9629 Solved: 4091[Submit][Sta ...
- BZOJ 3223: Tyvj 1729 文艺平衡树
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3628 Solved: 2052[Submit][Sta ...
- TYVJ P1080 N皇后
描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 列号 1 2 3 4 5 6 -- ...
- ACM 计算几何中的精度问题(转)
http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...
随机推荐
- C#微信json结构接收参数 转载
http://blog.csdn.net/u010773333/article/details/48524155 发素材的时间要上传资源故此要用json格式数据,需要转化. 微信服务器交互基本上都是j ...
- iScroll.js和Swiper.js联合使用时的插件冲突(滑动冲突)
上面的截图 ,是手机端的一个滑动刷新效果.用的是scroll.js插件. 每项中又有一个滑动,是左右滑动的用swiper.js插件,查看每个班级的信息. 当手从sw ...
- oracle11g rac修改归档
oracle11g归档日志可以放在本地.共享存储或ASM磁盘,本次修改放在本地盘中 1.创建归档所需要的路径 节点1: mkdir /arch1 chown -R oracle:oinstall /a ...
- 2.Median of Two Sorted Arrays (两个排序数组的中位数)
要求:Median of Two Sorted Arrays (求两个排序数组的中位数) 分析:1. 两个数组含有的数字总数为偶数或奇数两种情况.2. 有数组可能为空. 解决方法: 1.排序法 时间复 ...
- python socket 常见方法及 简单服务/客户端
socket 常见方法: 补充说明:what is file descriptor? 文件描述符是什么? 参考(http://stackoverflow.com/questions/8191905/w ...
- Linux学习笔记(一)
1.正则表达式 \w 匹配任何字类字符,包括下划线.与“[A-Za-z0-9_]”等效. \W 与任何非单词字符匹配.与“[^A-Za-z0-9_]”等效. + 一次或多次匹配前面的字符或子表达 ...
- ImageMagick之PDF转换成图片(image)
安装完ImageMagick之后,直接执行“magick convert f:\parseWord\tmp\testpdf.pdf f:\parseWord\tmp\testpdf.jpg”,会报错: ...
- AX 4.0 调用打印设定的功能
PrintJobSettings printJobSettings; PrintJobSettings printJobSettings2; Boolean ok; container packPri ...
- [简单]docx4j常用方法小结
http://53873039oycg.iteye.com/blog/2194479?utm_source=tuicool&utm_medium=referral —————————————— ...
- 通过微信企业号发送zabbix报警
采用微信报警时,管理员账户中必须要设置"示警媒体"一项,"收件人"一项可随便填写一下.其它成员则可以不用添加设置. ---------------------- ...