| 线段 | ||||||
|
||||||
| 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;
}
原文:http://blog.csdn.net/u013445530/article/details/41650691