可检验模板正确度

  • An Easy Problem?!
  • Ancient Berland Circus
  • Open-air shopping malls

An Easy Problem?!

problem

就是大讨论

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define eps 1e-6struct vec {double x, y;vec(){}vec( double X, double Y ) { x = X, y = Y; }vec operator + ( vec t ) { return vec( x + t.x, y + t.y ); }vec operator - ( vec t ) { return vec( x - t.x, y - t.y ); }vec operator * ( double t ) { return vec( x * t, y * t ); }friend double dot( vec s, vec t ) { return s.x * t.x + s.y * t.y; }friend double cross( vec s, vec t ) { return s.x * t.y - s.y * t.x; }
};struct point {double x, y;point(){}point( double X, double Y ) { x = X, y = Y; }point operator + ( vec t ) { return point( x + t.x, y + t.y ); }vec operator - ( point t ) { return vec( x - t.x, y - t.y ); }
};struct line {point p; vec v;line(){}line( point P, vec V ) { p = P, v = V; }
};point intersect( line l, line r ) {return l.p + l.v * ( - ( cross( r.v, r.p - l.p ) / cross( l.v, r.v ) ) );
}bool seg_intersect( point p1, point p2, point p3, point p4 ) {double d1 = cross( p3 - p1, p4 - p1 ), d2 = cross( p3 - p2, p4 - p2 );double d3 = cross( p1 - p3, p2 - p3 ), d4 = cross( p1 - p4, p2 - p4 );if( d1 * d2 > 0 || d3 * d4 > 0 ) return 0;else return 1;
}int main() {int T; double x1, x2, y1, y2;scanf( "%d", &T );while( T -- ) {scanf( "%lf %lf %lf %lf", &x1, &y1, &x2, &y2 );point p1( x1, y1 ), p2( x2, y2 );scanf( "%lf %lf %lf %lf", &x1, &y1, &x2, &y2 );point p3( x1, y1 ), p4( x2, y2 );if( fabs( p2.y - p1.y ) < eps || fabs( p4.y - p3.y ) < eps ) {printf( "0.00\n" );continue;//有水平线case }if( p1.y > p2.y ) swap( p1, p2 );if( p3.y > p4.y ) swap( p3, p4 );line l( p1, p2 - p1 ), r( p3, p4 - p3 );if( fabs( l.v.x * r.v.y - l.v.y * r.v.x ) < eps ) {printf( "0.00\n" );continue;//两直线平行 (x1,y1)(x2,y2)->x1y2=x2y1; }if( ! seg_intersect( p1, p2, p3, p4 ) ) {printf( "0.00\n" );continue;//无交点 }point p = intersect( l, r );vec y( 0, 1 );if( cross( l.v, y ) * cross( r.v, y ) > 0 ) {//收集部分在竖直线一侧if( cross( l.v, r.v ) > 0 && p4.x - p2.x >= -eps ) {printf( "0.00\n" );continue;//收集部分l在r下面 且l被r遮挡完} if( cross( l.v, r.v ) < 0 && p2.x - p4.x >= -eps ) {printf( "0.00\n" );continue;//收集部分l在r上面 }}double ans_y = min( p2.y, p4.y ); //相似三角形解横坐标 double ans_x1 = p2.x + ( p1.x - p2.x ) * ( ans_y - p2.y ) / ( p1.y - p2.y );double ans_x2 = p4.x + ( p3.x - p4.x ) * ( ans_y - p4.y ) / ( p3.y - p4.y );double ans = ( ans_x1 - ans_x2 ) * ( ans_y - p.y ) / 2;//s=底x高/2 printf( "%.2f\n", fabs( ans ) + eps );}return 0;
}

Ancient Berland Circus

#include <cmath>
#include <cstdio>
#define eps 1e-2
double pi = acos( -1.0 );
struct point {double x, y;
}p[3];
double len[3], rad[3];double gcd( double x, double y ) {if( fabs( y ) < eps ) return x;else if( fabs( x ) < eps ) return y;else return gcd( y, fmod( x, y ) );
}double dis( int i, int j ) {return sqrt( ( p[i].x - p[j].x ) * ( p[i].x - p[j].x ) + ( p[i].y - p[j].y ) * ( p[i].y - p[j].y ) );
}int main() {for( int i = 0;i < 3;i ++ )scanf( "%lf %lf", &p[i].x, &p[i].y );double C = 0;for( int i = 0;i < 3;C += len[i], i ++ )len[i] = dis( i, ( i + 1 ) % 3 );C /= 2;double S = sqrt( C * ( C - len[0] ) * ( C - len[1] ) * ( C - len[2] ) );double R = len[0] * len[1] * len[2] / ( 4 * S );for( int i = 0;i < 2;i ++ )rad[i] = acos( 1 - len[i] * len[i] / ( 2 * R * R ) );rad[2] = 2 * pi - rad[0] - rad[1];double e = gcd( rad[0], gcd( rad[1], rad[2] ) );printf( "%.6f\n", pi * R * R * sin( e ) / e );return 0;
}

Open-air shopping malls

problem

枚举圆心,二分半径,然后求与每个圆相交面积,是否达到一半

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define eps 1e-10
#define maxn 25
int T, n;double pi = acos( -1.0 );int dcmp( double x ) {return fabs( x ) < eps ? 0 : ( x > 0 ? 1 : -1 );
}struct point {double x, y;point(){}point( double X, double Y ) { x = X, y = Y; }friend double dis( point p1, point p2 ) { return sqrt( ( p1.x - p2.x ) * ( p1.x - p2.x ) + ( p1.y - p2.y ) * ( p1.y - p2.y ) ); }
};struct circle {point o; double r;circle(){}circle( point O, double R ) { o = O, r = R; }
}C[maxn];double area_circle_intersect( circle c1, circle c2 ) {double d = dis( c1.o, c2.o );if( dcmp( d - c1.r - c2.r ) >= 0 ) return 0;if( dcmp( d - fabs( c1.r - c2.r ) ) <= 0 ) {double r = min( c1.r, c2.r );return pi * r * r;}double rad1 = acos( ( c1.r * c1.r + d * d - c2.r * c2.r ) / ( 2 * c1.r * d ) ); double rad2 = acos( ( c2.r * c2.r + d * d - c1.r * c1.r ) / ( 2 * c2.r * d ) );return rad1 * c1.r * c1.r + rad2 * c2.r * c2.r - c1.r * d * sin( rad1 );
}bool check( circle c ) {for( int i = 1;i <= n;i ++ )if( dcmp( area_circle_intersect( c, C[i] ) * 2 - pi * C[i].r * C[i].r ) < 0 )return 0;return 1;
}double solve( double l, double r, circle c ) {double ans;while( fabs( r - l ) > eps ) {double mid = ( l + r ) / 2;c.r = mid;if( check( c ) ) ans = mid, r = mid;else l = mid;}return ans;
}int main() {scanf( "%d", &T );while( T -- ) {scanf( "%d", &n );for( int i = 1;i <= n;i ++ )scanf( "%lf %lf %lf", &C[i].o.x, &C[i].o.y, &C[i].r );double ans = 1e18;for( int i = 1;i <= n;i ++ ) {double l = 0, r = 0;for( int j = 1;j <= n;j ++ )r = max( r, C[j].r + dis( C[i].o, C[j].o ) );ans = min( ans, solve( l, r, C[i] ) );}printf( "%.4f\n", ans );}return 0;
}

数论六之计算几何——An Easy Problem,Ancient Berland Circus,Open-air shopping malls相关推荐

  1. 1.19 Ancient Berland Circus

    古老的伯兰德马戏团 Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the pa ...

  2. 2022.01.19翻译Ancient Berland Circus

    Ancient Berland Circus 题目(https://acs.jxnu.edu.cn/problem/CF1C)描述: Nowadays all circuses in Berland ...

  3. Ancient Berland Circus

    描述: Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past thi ...

  4. 数论六之计算几何干货——计算几何模板解释全集 及 模板检验训练场

    文章目录 点和向量及运算 直线和线段 求解点到直线的距离/点在直线上 求解点到线段的距离/点在线段上 求解两条线段是否相交 求解两直线的交点 多边形 求解多边形面积 求解多边形重心 求解判断定点与多边 ...

  5. Ancient Berland Circus CodeForces - 1C

    题意:给定一个正多边形的三个顶点,求这个正多边形的最小面积. 思路:首先,边数越小面积越小,所以只要确定出包含这三个顶点的边数最小的正多边形即可.这个三角形和正多边形外接同一个圆.所以先求出外接圆的半 ...

  6. POJ 2826 An Easy Problem?! 叉积求多边形面积 【计算几何】

    ACM博客_kuangbin POJ 2826 An Easy Problem?! An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536 ...

  7. 2019年ICPC银川区域赛 Easy Problem(简单莫比乌斯函数 + 欧拉降幂)

    Easy Problem ∑a1=1m∑a2=1m∑a3=1m⋯∑an−1m∑anm[gcd(a1,a2,a3,-,an−1,an)==d](a1,a2,a3,-,an−1,an)k=dkd∑a1=1 ...

  8. 信息学奥赛一本通 1223:An Easy Problem | OpenJudge NOI 4.6 1455:An Easy Problem

    [题目链接] ybt 1223:An Easy Problem OpenJudge NOI 4.6 1455:An Easy Problem [题目考点] 1. 数制 2. 枚举 [解题思路] 解法1 ...

  9. 信息学奥赛一本通(1223:An Easy Problem)

    1223:An Easy Problem 时间限制: 1000 ms         内存限制: 65536 KB 提交数: 5835     通过数: 4111 [题目描述] 给定一个正整数N,求最 ...

最新文章

  1. 详解Google第二代TPU 既能推理又能训练 性能霸道
  2. 010_Redis的发布和订阅
  3. matlab中矩阵的各种分解
  4. CSP认证201604-4 游戏[C++题解]:bfs、拆点、迷宫问题加强版、三维数组
  5. 这些大佬,真的牛逼了!
  6. C++中各种智能指针的实现及弊端(二)
  7. mysql错误码 1045_MySql 错误代码 1045
  8. keepalive之LVS-DR架构
  9. 算法导论12.2节习题解答
  10. 第三章 SQL知识点总结
  11. 记录工作中用到的日期转换方法
  12. Eclipse中使用google代码风格
  13. Phycharm下载并安装
  14. 卸载MYSQL数据库及MYSQL的安装
  15. 经典Retinex算法简要剖析
  16. cad查看_CAD手机看图软件中批注的图片在电脑上如何查看?
  17. 设计模式之责任链模式(Java实现)
  18. SiT3808:1 -80MHz 单端压控振荡器VCXO
  19. 支付宝前端团队详解基于Node.js Web框架Chair
  20. k8s裸机安装Service使用LoadBalancer

热门文章

  1. 宝宝学数学的第一套书,秒杀题海战术!上小学前应该这样学数学!
  2. 计算机能不能直接识别汇编语言程序,计算机能直接识别执行用汇编语言编写的程序吗...
  3. oracle 加密怎么解密,oracle加密encrypt,解密decrypt,
  4. 计算机职称 计算机二级证,国家计算机二级证书含金量有多高
  5. java并行流 阻塞主线程_多线程入门案例与java8的并行流
  6. 雨棚板弹性法计算简图_钢结构工程量计算4点注意事项,还不来看?
  7. php webshell开源,[github开源]webshell连接器--Jeshell
  8. hive 导入mysql数据库_求助 Hive 导入MYsql 数据库 报错啊
  9. html中label的寬度無法修改,如何设置HTML span、label 的宽度
  10. 宝塔mysql远程链接_宝塔apache启动失败:报错 AH00526: Syntax error on line 解决方案