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 ...
随机推荐
- hive 使用笔记(partition; HDFS乱码)
6. insert 语句 1) 因为目标表有partition, 所以刚开始我使用的语句是 insert overwrite table sa_r_item_sales_day_week_month ...
- BZOJ-1087 互不侵犯King 状压DP+DFS预处理
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2337 Solved: 1366 [Submit][ ...
- (Beta)Let's-版本发布说明
Let's App(Beta)现已隆重上市 GIT源码请戳此处 版本的新功能 我们在这一版本对于项目的规划目标主要集中在三个方面——预约用户观感,完善功能链条,改善用户体验 界面 首先,在β阶 ...
- POJ2485Highways(prime 水题)
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26516 Accepted: 12136 Descri ...
- CentOS 6.4 32位系统 LAMP(Apache+MySQL+PHP)安装步骤
先来解释一下,什么是 LAMP.正如标题所言,LAMP 实际上就是 Linux.Apache.MySQL.PHP 四个名称的缩写,当然最后一个 “P” 还有其他说法是 Perl 或者 Python.不 ...
- data URI
参考资料:http://www.cnblogs.com/hustskyking/p/data-uri.html 与http,ftp等协议类似,data URL也是一种协议,不同的是它直接将数据(编码或 ...
- C++标准转换运算符reinterpret_cast
C++标准转换运算符reinterpret_cast reinterpret_cast <new_type> (expression) reinterpret_cast运算符是用来处理无关 ...
- Java & C++ 大数计算
Java--大数计算,妈妈再也不用担心我的学习了 . BigInteger 英文API: http://docs.oracle.com/javase/8/docs/api/ 中文API: http:/ ...
- iOS-自定义Log
打印Log是一件非常消耗系统性能的事情,因此在发布时要把程序中的Log进行隐藏.以下是在iOS中自定义Log的代码 #ifdef DEBUG // 处于开发阶段 #define DJLog(...) ...
- dns (域名系统)
dns (域名系统) DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP ...