Light OJ Basic Geometry

Basic Geometry

一共十八道题,在前面的beginners problems里面做了8道:1022 1072 1107 1211 1216 1305 1331 1433  详见:beginners problems

剩下的10道题,解决了6道,剩下的4道等什么时候有思路了再做吧,先放放。

1043 Triangle Partitioning

相似

#include <cstdio>
#include <cmath>
int main()
{
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        double a,b,c,ratio;
        scanf("%lf%lf%lf%lf",&a,&b,&c,&ratio);
        printf("Case %d: %lf\n",i,a/sqrt((ratio+1)/ratio));
    }
    return 0;
}

1058  Parallelogram Counting

求平行四边形个数

// 求给定点能构成平行四边形的个数
// 由于平行四边形对角线中点相重,所以我们先把这种点找出来
// 满足中点的k条线段用C(k,2)得到以某点为中心的平行四边形
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
struct point
{
    double x,y;
};
point p[1001],mid[1001010];
bool cmp(point a,point b)
{
    if(a.x==b.x)
        return a.y<b.y;
    return a.x<b.x;
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int ii=1;ii<=t;ii++)
    {
        int n;
        scanf("%d",&n);
        int total=0;
        for(int i=1;i<=n;i++)
            scanf("%lf%lf",&p[i].x,&p[i].y);
        for(int i=1;i<n;i++)
            for(int j=i+1;j<=n;j++)
            {
                mid[++total].x=p[i].x+p[j].x;
                mid[total].y=p[i].y+p[j].y;
            }
        sort(mid+1,mid+total+1,cmp);
        int sum=1;
        int ans=0;
        for(int i=1;i<total;i++)
        {
            if(mid[i].x==mid[i+1].x&&mid[i].y==mid[i+1].y)
                sum++;
            else
            {
                ans+=sum*(sum-1)/2;
                sum=1;
            }
        }
        printf("Case %d: %d\n",ii,ans);
    }
    return 0;
}

1118  Incredible Molecules

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#define PI (2*acos(0.0))
using namespace std;
struct point
{
    double x,y;
};
double Distance(point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double triangle(double a,double b,double c)
{
    double p=(a+b+c)/2;
    return sqrt(p*(p-a)*(p-b)*(p-c));
}
double jiao(double a,double b,double c)
{
    return acos((a*a+b*b-c*c)/(2*a*b));
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        point p1,p2;
        double r1,r2;
        scanf("%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&r1,&p2.x,&p2.y,&r2);
        double d=Distance(p1,p2);
        double ans;
        if(d<=fabs(r1-r2))// 等于号掉了会WA呃
        {
            double r=r1<r2?r1:r2;
            ans=r*r*PI;
        }
        else if(d>=r1+r2)
        {
            ans=0;
        }
        else
        {
            double a0=jiao(r1,r2,d);
            double a1=jiao(r1,d,r2);
            double a2=jiao(r2,d,r1);
            ans=r1*r1*a1;
            ans+=r2*r2*a2;
            ans-=sin(a0)*r1*r2;
        }
        printf("Case %d: %.8lf\n",i,ans);
    }
    return 0;
}

1178  Trapezium

#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
double triangle(double a,double b,double c)
{
    double p=(a+b+c)/2;
    return sqrt(p*(p-a)*(p-b)*(p-c));
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        double a,b,c,d;
        scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
        if(a>c)
            swap(a,c);
        double ans;
        double tmp=c-a;
        double cnt=acos((b*b+tmp*tmp-d*d)/(2*b*tmp));
        ans=a*b*sin(cnt);
        ans+=triangle(c-a,b,d);
        printf("Case %d: ",i);
        printf("%lf\n",ans);
    }
    return 0;
}


1366  Pair of Touching Circles

// 参考别人的uva5815
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int total;
int x[501],y[501],z[501];
void solve() //预处理,先把勾股数放在数组
{
    total=0;
    for(int i=1;i<=500;i++)
    for(int j=i+1;j<=500;j++)
    {
        int k=(int)sqrt(i*i+j*j);
        if(i*i+j*j==k*k)
        {
            total++;
            x[total]=i;
            y[total]=j;
            z[total]=k;
        }
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    solve();
    for(int cases=1;cases<=t;cases++)
    {
        int H,W;
        scanf("%d%d",&H,&W);
        printf("Case %d: ",cases);
        long long sum=0,tmp;
        int mx=max(H,W);
        for(int i=2;i<mx;i+=2)//垂直或水平相切
            for(int j=i;i+j<=mx;j+=2)
            {
                int length=i+j;
                int broad=max(i,j);
                tmp=0;
                if(broad<=H&&length<=W)
                    tmp+=(H+1-broad)*(W+1-length);
                if(broad<=W&&length<=H)
                    tmp+=(W+1-broad)*(H+1-length);
                if(i!=j)
                    tmp*=2;
                sum+=tmp;
            }
        for(int i=1;i<=total;i++)//两圆斜切
            for(int j=1;j<z[i];j++)
            {
                tmp=0;
                int length=max(z[i]+x[i],2*max(j,z[i]-j));
                int broad=max(z[i]+y[i],2*max(j,z[i]-j));
                if(length<=H&&broad<=W)
                    tmp+=(H+1-length)*(W+1-broad);
                if(broad<=H&&length<=W)
                    tmp+=(H+1-broad)*(W+1-length);
                tmp*=2;
                sum+=tmp;
            }
        printf("%lld\n",sum);
    }
    return 0;
}


1385  Kingdom Division

// 将EF连起来,区域d划分为x和y
// 由比例关系知
// a/b=x/c
// (a+x+y)/(b+c)=y/(x+c)
// 最终求d=x+y的值
// b=x的时候A点就不存在了
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#define eps 10-9
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        double a,b,c,x,y;
        scanf("%lf%lf%lf",&a,&b,&c);
        x=a*c/b;
        y=(a+x)*(c+x)/(b-x);
        if(b-x<=eps)
            printf("Case %d: -1\n",i);
        else
            printf("Case %d: %lf\n",i,x+y);
    }
    return 0;
}


Remained:

1378 The Falling Circle

1383 Underwater Snipers

1388 Trapezium Drawing

1391 Speed Zones

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值