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 ...
随机推荐
- 【CodeForces 613B】Skills
题 题意 给你n个数,可以花费1使得数字+1,最大加到A,最多花费m.最后,n个数里的最小值为min,为A的有k个,给你cm和cf,求force=min*cm+k*cf 的最大值,和n个数操作后的结果 ...
- load and initialize
NSObject是一切OC类的基类,所以我们必须对NSObject所有的方法有一个清楚的认识. + (void)load; 当类或者分类被加入到runtime时,load方法会被调用,也就是说在mai ...
- 【bzoj3246】 Ioi2013—Dreaming
www.lydsy.com/JudgeOnline/problem.php?id=3246 (题目链接) 题意 给出一棵不完全的树,要求在树上连最少的边使得所有点联通,并且使得两点间最大距离最小. S ...
- POJ2288 Islands and Bridges
Description Given a map of islands and bridges that connect these islands, a Hamilton path, as we al ...
- 高性能的分布式内存对象缓存系统Memcached
Memcached概述 什么是Memcached? 先看看下面几个概念: Memory:内存存储,不言而喻,速度快,对于内存的要求高,不指出的话所缓存的内容非持久化.对于CPU要求很低,所以常常采 ...
- H2Database数据类型
数据类型 整数(INT) 布尔型(BOOLEAN) 微整数(TINYINT) 小整数(SMALLINT) 大整数(BIGINT) 标识符(IDENTITY) 货币数(DECIMAL) 双精度实数( ...
- derby支持的数据类型
Data types This section describes the data types used in Derby. Built-In type overview Numeric types ...
- (转) 新的开始之Win7、CentOS 6.4 双系统 硬盘安装
http://blog.csdn.net/cnclenovo/article/details/11358447
- ajax原理,验证码生成原理
什么是ajax AJAX:”Asynchronous JavaScript and XML” 中文意思:异步JavaScript和XML 指一种创建交互式网页应用的网页开发技术. 不是指一种单一的 ...
- Spring各个jar包的简介
spring.jar是包含有完整发布的单个jar 包,spring.jar中包含除了spring-mock.jar里所包含的内容外其它所有jar包的内容,因为只有在开发环境下才会用到 spring-m ...