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

可检验模板正确度

  • 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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/317283.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

CodeForces:12271261(div1)1262(div2)

文章目录前言CF1227A Math ProblemDescription\text{Description}DescriptionSolution\text{Solution}SolutionCode\text{Code}CodeCF1227B BoxDescription\text{Description}DescriptionSolution\text{Solution}SolutionCode\text{Code}CodeCF1227C MessyDescription\text{Des…

【NET CORE微服务一条龙应用】应用部署

简介本章主要介绍https://github.com/q315523275/FamilyBucket上微服务一条龙应用&#xff0c;在实际使用中的应用部署&#xff0c;以原始方式部署非docker部署应用主要包括&#xff1a;1、网关应用部署2、授权认证应用部署3、配置中心查询服务端应用部署4、综合管理应用部署5、…

牛客网区间dp练习

NC13230 合并回文子串 NC16129 小小粉刷匠 NC19909 [CQOI2007]涂色PAINT NC19997 [HAOI2016]字符合并 NC20238 [SCOI2003]字符串折叠 NC20252 [SCOI2007]压缩 NC20312 [SDOI2008]SUE的小球 POJ3042 Grazing on the Run

CF516D-Drazil and Morning Exercise【树上差分,倍增】

正题 题目链接:https://www.luogu.com.cn/problem/CF516D 题目大意 给出一棵nnn个点的树&#xff0c;定义f(x)f(x)f(x)表示距离点xxx最远的点的距离&#xff0c;qqq次询问给出一个kkk&#xff0c;要求一个最大的连通块满足连通块中所有点的f(x)f(x)f(x)最大最小差值不能超过k…

容斥问卷调查反馈——Co-prime,Character Encoding,Tree and Constraints,「2017 山东一轮集训 Day7」逆序对

文章目录Co-primesourcesolutioncodeCharacter EncodingsourcesolutioncodeTree and Constraintssourcesolutioncode「2017 山东一轮集训 Day7」逆序对sourcesolutioncodeCo-prime source TTT组数据&#xff0c;给出&#x1d43f;,&#x1d445;,&#x1d441;&#x1d43f;, …

手工修复Azure DevOps无法连接到Azure的问题

点击上方蓝字关注“汪宇杰博客”今天我在为一个从TFVC迁移到Git的老项目重新配置发布到Azure App Service的CI/CD管线的时候&#xff0c;Azure DevOps竟然爆了。这是一个微软已知的bug&#xff0c;目前还未修复&#xff0c;我来带大家看看如何手工workaround这个问题。首先&…

Loj#576-「LibreOJ NOI Round #2」签到游戏【线段树】

正题 题目链接:https://loj.ac/p/576 题目大意 给出一个长度为nnn的序列aaa&#xff0c;还有一个未知序列bbb&#xff0c;你每次可以花费gcd⁡ilrai\gcd_{il}^r a_igcdilr​ai​的代价得到∑ilrbi\sum_{il}^rb_i∑ilr​bi​的值。 每次修改aaa中的一个数&#xff0c;求得到b…

NC14732 锁

NC14732 锁 题意&#xff1a; n个居民&#xff0c;门上有k把锁&#xff0c;每个居民有若干钥匙&#xff0c;为1到k的一个子集&#xff0c;如果几名居民的钥匙的并集是1到k&#xff0c;即他们拥有全部锁的对应钥匙。 求最小的k&#xff0c;使得可以适当地给居民们每人若干钥匙…

CodeForces:1103(div1)1104(div2)

文章目录前言CF1104A Splitting into digitsDescription\text{Description}DescriptionSolution\text{Solution}SolutionDescription\text{Description}DescriptionCF1104B Game with stringDescription\text{Description}DescriptionSolution\text{Solution}SolutionCode\text…

专题突破一之分块——Untitled Problem II,Balanced Lineup,[ioi2009]Regions

文章目录SP2940 UNTITLE1 - Untitled Problem IIsourcesolutioncodeBalanced LineupsourcecodeCount on a tree II[ioi2009]RegionsSP2940 UNTITLE1 - Untitled Problem II source solution 分块 si{sik(i−l1)sikik(1−l)l≤i≤rsik(r−l1)r<is_i\begin{cases} s_ik\tim…

.NET Core实战项目之CMS 第十七章 CMS网站系统的部署

目前我们的.NET Core实战项目之CMS系列教程基本走到尾声了&#xff0c;通过这一系列的学习你应该能够轻松应对.NET Core的日常开发了&#xff01;当然这个CMS系统的一些逻辑处理还需要优化&#xff0c;如没有引入日志组件以及缓存功能&#xff0c;权限目前只支持控制到菜单&…

ICPC2019南昌区域赛

ICPC2019南昌区域赛 题号题目知识点难度A9102BA Funny Bipartite Graph状压dp思维稳银快金CAnd and Pair二项式定理快铜DBitwise TreeEBob’s Problem思维&#xff0c;生成树签到FDynamic Suffix ArrayGEating Plan思维题稳铜快银HPowers of TwoIResistanceJSummonKTreeLWho i…

Loj#510-「LibreOJ NOI Round #1」北校门外的回忆【线段树】

正题 题目链接:https://loj.ac/p/510 题目大意 给出一个代码 function add(x,v)while x < n dos[x] s[x] xor vx x lowbit(x) //注意&#xff0c;这里是 lowbit&#xff0c;这也是两份代码唯一的区别end while end functionfunction query(x)ans 0while x > 0 doa…

如何用EFCore Lazy Loading实现Entity Split

α角 与 β角支持 现实生活 的 计算机系统&#xff0c;总有着两大偏差&#xff0c;第一个是 现实生活 与 计算机系统 的α角&#xff0c;另外一个是计算机系统的 逻辑设计 与 物理设计 的β角。举个栗子&#xff1a;α角&#xff1a;假设某个公司的商业流程&#xff0c;我们在做…

CodeForces:372(div1)div373(div2)

文章目录前言CF373A Collecting Beats is FunDescription\text{Description}DescriptionSolution\text{Solution}SolutionCode\text{Code}CodeCF373B Making Sequences is FunDescription\text{Description}DescriptionSolution\text{Solution}SolutionCF372A Counting Kangaro…

一二三系列之CodeChef分块——Chef and Churu,Chef and Problems,Children Trips

文章目录Chef and ChurusourcesolutioncodeChef and ProblemssourcesolutioncodeChildren TripssourcesolutioncodeChef and Churu source solution 对于单独的iii&#xff0c;查询可以用线段树/树状数组O(nlog⁡n)O(n\log n)O(nlogn)&#xff0c;这暗示可以平衡查询修改次数…

Bob‘s Problem

Bob’s Problem 题意&#xff1a; 一个有n个点的图&#xff0c;其中边分为白色和黑色&#xff0c;每个边都有边权&#xff0c;所选白边的数量的数量不能超过k&#xff0c;问现在选择一些边&#xff0c;使得所有点连通&#xff0c;问最大权值是多少&#xff1f; 题解&#xf…

.NET Core 开源项目 Anet 在路上

今天给大家介绍我刚开源的一个 .NET Core 项目&#xff1a;Anet。Anet 的目标是实现一个 .NET Core 通用库、通用框架和通用模板。我给它的定义是&#xff1a;A .NET Core Common Lib, Framework and Boilerplate.它的取名正是来自于这句话的前面四个字母&#xff1a;ANET。Ane…

Loj#2324-「清华集训 2017」小 Y 和二叉树

正题 题目链接:https://loj.ac/p/2324 题目大意 给出nnn个点的一棵树&#xff0c;每个点的度数不超过333。 你要求它的一个二叉树结构&#xff08;根任意选择&#xff09;使得其中序遍历的字典序最小。 1≤n≤1061\leq n\leq 10^61≤n≤106 解题思路 直接找根感觉比较麻烦&…

模板:后缀自动机(SAM)

所谓后缀自动机&#xff0c;就是通过后缀建立的自动机 &#xff08;逃&#xff09; 请允许我先介绍一下后缀家族&#xff1a; &#xff08;又逃&#xff09; 前言 OI生涯目前为止学习的最为难以理解的算法&#xff0c;没有之一。 到现在也没有完全的理解。 qwq 概念 定义&…