Hrbust2178

线段
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 10(6 users)Total Accepted: 7(6 users)Rating: Special Judge: No
Description

坐标轴上有一些点,依次给出。点与点之间要求用一个半圆的直径连接,即把这两个点作为连接他们的半圆的直径的两个端点。第一个点与第二个点连,第二个与第三个连。半圆不能在坐标轴下面。问最后连出的图形,是否存在两个半圆他们是交叉的。

Input

多组测试数据。

每组测试数据的第一行有一个数n(1 ≤ n ≤ 1000),表示有n个点。

之后一行有n个数x1, x2, ..., xn ( - 10^6 ≤ xi ≤ 10^6),每个数表示该点在坐标轴的位置。
Output

如果最后的图形有交叉,输出yes,如果没有,输出no。

Sample Input

4

0 10 5 15

4

0 15 5 10

Sample Output

yes

no

Source
2014.11.29新生赛-热身赛


要考虑多种情况,注意两个半月有一点重合的地方那种情况就行

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn = 1e6+10;
struct Node
{
    int x,y;
}node[maxn];

bool cmp(Node a, Node b)
{
    if(a.x == b.x) return a.y < b.y;
     return a.x < b.x;
}
int main()
{

   int n;
   while(scanf("%d",&n) != EOF)
   {
       int a[1000];
       for(int i = 0; i < n; i++)
       {
           scanf("%d",&a[i]);
       }
       int cent = 0;
       for(int i = 1; i < n; i++)
       {
           node[cent].x = a[i-1] < a[i] ? a[i-1] : a[i];
           node[cent++].y = a[i-1] < a[i] ? a[i] : a[i-1];

       }

       sort(node,node+cent,cmp);
       int flag = 1;

       for(int i = 0; i < cent; i++)
        for(int j = 0; j < i; j++)
       {
           if( node[i].x  == node[j].x && node[i].y >= node[j].y) continue;
           if(node[i].x < node[j].y && node[i].y > node[j].y)
            {
              flag = 0;
           }
       }

       if(flag) printf("no\n");
       else printf("yes\n");
   }
   return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值