codeforces A. Dima and Continuous Line 解题报告
题目链接:http://codeforces.com/problemset/problem/358/A
题目意思:在横坐标上给出n个不同的点,需要把前一个点跟后一个点(这两个点的顺序是紧挨着的)用一个半圆弧来连接。现在要判断的是这些符合条件的点连接以后,圆弧之间是否相交了。是则输出yes,否则输出no。
假设序列是x1,x2,x3,x4.....xn。相交其实只有两种情况,第一种就是样例已经给出了的:即 x1 < x3 < x2 且 x2 < x4。另外一种情况就是第一种情况的对称位置x3 < x1 且 x1 < x4 < x2。
要特别注意的是,由于序列中前后两个数不是按从小到大的顺序排好的,因此要先确保前一个数要大于后一个数。另外,当n <= 3时,是绝对不会发生交叉的。
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std; const int maxn = + ;
int a[maxn], tmp1[], tmp2[]; int main()
{
int i, j, n, flag;
while (scanf("%d", &n) != EOF)
{
// freopen("in.txt", "r", stdin);
for (i = ; i < n; i++)
{
scanf("%d", &a[i]);
}
if (n <= )
{
printf("no\n");
}
else
{
flag = ;
for (i = ; i < n-; i++)
{
if (a[i] > a[i+])
{
tmp1[] = a[i+];
tmp1[] = a[i];
}
else
{
tmp1[] = a[i];
tmp1[] = a[i+];
}
// printf("tmp1[0] = %d, tmp1[1] = %d\n", tmp1[0], tmp1[1]);
for (j = ; j < n-; j++)
{
if (a[j] > a[j+])
{
tmp2[] = a[j+];
tmp2[] = a[j];
}
else
{
tmp2[] = a[j];
tmp2[] = a[j+];
}
if ((tmp1[] > tmp2[] && tmp1[] < tmp2[] && tmp1[] > tmp2[]) || (tmp1[] < tmp2[] && tmp1[] > tmp2[] && tmp1[] < tmp2[]))
{
flag = ;
// printf("tmp1[0] = %d, tmp1[1] = %d\n", tmp1[0], tmp1[1]);
// printf("tmp2[0] = %d, tmp2[1] = %d\n", tmp2[0], tmp2[1]);
goto h;
}
}
}
h: if (!flag)
printf("no\n");
else
printf("yes\n");
}
}
return ;
}
codeforces A. Dima and Continuous Line 解题报告的更多相关文章
- codeforces B. Dima and Text Messages 解题报告
题目链接:http://codeforces.com/problemset/problem/358/B 题目意思:给出n个单词(假设为word1,word2.word3...wordn)和一句test ...
- codeforces A. Cinema Line 解题报告
题目链接:http://codeforces.com/problemset/problem/349/A 题目意思:题目不难理解,从一开始什么钱都没有的情况下,要向每一个人售票,每张票价格是25卢布,这 ...
- codeforces B. Shower Line 解题报告
题目链接:http://codeforces.com/contest/431/problem/B 题目意思:给出5 * 5 的矩阵.从这个矩阵中选出合理的安排次序,使得happiness之和最大.当第 ...
- Codeforces Round #208 (Div. 2) A.Dima and Continuous Line
#include <iostream> #include <algorithm> #include <vector> using namespace std; in ...
- codeforces C1. The Great Julya Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...
- codeforces B. Eugeny and Play List 解题报告
题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...
- codeforces 433C. Ryouko's Memory Note 解题报告
题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...
- 【LeetCode】149. Max Points on a Line 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+最大公约数 日期 题目地址:https://l ...
- 【LeetCode】581. Shortest Unsorted Continuous Subarray 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 方法一:排序比较 日期 题目地址:https://leetco ...
随机推荐
- BZOJ-1927 星际竞速 最小费用最大流+拆点+不坑建图
1927: [Sdoi2010]星际竞速 Time Limit: 20 Sec Memory Limit: 259 MB Submit: 1593 Solved: 967 [Submit][Statu ...
- spring获取ApplicationContext对象的方法——ApplicationContextAware
一. 引言 工作之余,在看一下当年学的spring时,感觉我们以前都是通过get~ set~方法去取spring的Ioc取bean,今天就想能不能换种模型呢?因为我们在整合s2sh时,也许有那么一天就 ...
- 【poj1050】 To the Max
http://poj.org/problem?id=1050 (题目链接) 题意 求二维最大子矩阵 Solution 数据好像很水,N最大才100,N^4大暴力都可以随便水过. 其实有N^3的做法.枚 ...
- android 常见死机问题--log分析
http://blog.csdn.net/fangchongbory/article/details/7645815 android 常见死机问题--log分析============ ...
- HD2255奔小康赚大钱(最大权匹配模板)
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg)
linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg) 2013-11-10 16:51:14 分类: 系统运维 为什么要写这篇文章? 答:通过常规的三大步(./confi ...
- jQuery特效
基础特效 方法 描述 hide() 立即隐藏jQuery对象内的所有元素 hide(time).hide(time, easing) 在指定的时间内以动画方式隐藏jQuery对象内的所有元素,并可选一 ...
- matlab 之cov 协方差
COV 1.cov(x) 如果x为向量,返回x的方差 计算方法为: S为方差. 2.cov(X) 如果X为矩阵,把矩阵X的行作为观察值,把列作为变量,返回X的协方差矩阵: diag(cov(X))是每 ...
- TableInputFormat分片及分片数据读取源码级分析
我们在MapReduce中TextInputFormat分片和读取分片数据源码级分析 这篇中以TextInputFormat为例讲解了InputFormat的分片过程以及RecordReader读取分 ...
- thinkphp中I方法
概述 正如你所见到的一样,I方法是ThinkPHP众多单字母函数中的新成员,其命名来自于英文Input(输入),主要用于更加方便和安全的获取系统输入变量,可以用于任何地方,用法格式如下:I('变量类型 ...