POJ 3304 Segments

Segments
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7363 Accepted: 2207

Description

Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on it, all projected segments have at least one point in common.

Input

Input begins with a number T showing the number of test cases and then, T test cases follow. Each test case begins with a line containing a positive integer n ≤ 100 showing the number of segments. After that, n lines containing four real numbers x1 y1 x2 y2 follow, in which (x1, y1) and (x2, y2) are the coordinates of the two endpoints for one of the segments.

Output

For each test case, your program must output "Yes!", if a line with desired property exists and must output "No!" otherwise. You must assume that two floating point numbers a and b are equal if |a - b| < 10-8.

Sample Input

3
2
1.0 2.0 3.0 4.0
4.0 5.0 6.0 7.0
3
0.0 0.0 0.0 1.0
0.0 1.0 0.0 2.0
1.0 1.0 2.0 1.0
3
0.0 0.0 0.0 1.0
0.0 2.0 0.0 3.0
1.0 1.0 2.0 1.0

Sample Output

Yes!
Yes!
No!

Source

 
 
 
 
#include<stdio.h>
#include<math.h>

const int eps=1e-8;

struct point{
    double x,y;
}p[410];

double xmult(point a,point b,point c){
    return (a.x-b.x)*(c.y-b.y)-(c.x-b.x)*(a.y-b.y);
}

double abs(double a){
    if(a<0)
        return -a;
    return a;
}

bool work(int n){
    int flag;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++){
            if(abs(p[j].x-p[i].x)>eps || abs(p[j].y-p[i].y)>eps){
                flag=1;
                for(int k=1;k<=n;k+=2)
                    if(xmult(p[i],p[j],p[k])*xmult(p[i],p[j],p[k+1])>0){
                        flag=0;
                        break;
                    }
                if(flag)
                    return 1;
            }
        }
    return 0;
}

int main(){

    //freopen("input.txt","r",stdin);

    int t,n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        int cnt=1;
        for(int i=1;i<=n;i++,cnt+=2)
            scanf("%lf%lf%lf%lf",&p[cnt].x,&p[cnt].y,&p[cnt+1].x,&p[cnt+1].y);
        if(work(cnt-1))
            printf("Yes!\n");
        else
            printf("No!\n");
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/jackge/archive/2013/03/14/2960434.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 JavaScript 编写的简单俄罗斯方块游戏(附源代码) 项目:使用 JavaScript 编写的简单俄罗斯方块游戏(附源代码) 该游戏是一个使用 HTML5 和 JavaScript 开发的简单项目。这款游戏允许玩家策略性地旋转下落的方块以清除关卡。要在此游戏中得分,您必须通过操纵方块来清除线条,使它们填满水平行。当方块掉落时,您必须 根据需要移动 和旋转它们,使它们均匀地排列在底部。 游戏制作 该游戏仅使用 HTML、CSS 和 JavaScript。谈到这款游戏的功能,这款游戏的 PC 控制也很简单。首先,您必须按空格键才能开始游戏。您可以使用箭头键来更改下落方块的位置。您可以在侧栏看到形成的分数和行。 该游戏包含大量的 javascript,用于对游戏的某些部分进行验证。 如何运行该项目? 要运行此游戏,您不需要任何类型的本地服务器,但需要浏览器。我们建议您使用现代浏览器,如 Google Chrome 和 Mozilla Firefox, 以获得更好、更优化的游戏体验。要玩游戏,首先,单击 index.html 文件在浏览器中打开游戏。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值