A. Odds and Ends
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?

Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.

A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.

Input

The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.

The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.

Output

Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.

You can output each letter in any case (upper or lower).

Examples
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
Note

In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.

In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.

In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.

In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.

拆分序列,序列个数不能为偶数,每个子序元素个数不能为偶数,每个子序列不能以偶数开头或结尾。

特判开头结尾,判断n即可。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int a[],n;
int main()
{
scanf("%d",&n);
a[]=;
int ans=;
bool flag=true;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
if((i==n && a[i]%==) ||(i== && a[i]%==)) flag=false;
if(a[i]&) ans++;
else
{
if(a[i-]&) a[i]=,ans++;
}
}
if(ans%==) flag=false;
puts(flag?"Yes":"No");
return 0;
}
B. Tell Your World
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Connect the countless points with lines, till we reach the faraway yonder.

There are n points on a coordinate plane, the i-th of which being (i, yi).

Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.

Input

The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points.

The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.

Output

Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise.

You can print each letter in any case (upper or lower).

Examples
Input
5
7 5 8 6 9
Output
Yes
Input
5
-1 -2 0 0 -5
Output
No
Input
5
5 4 3 2 1
Output
No
Input
5
1000000000 0 0 0 0
Output
Yes
Note

In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.

In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.

In the third example, it's impossible to satisfy both requirements at the same time.

找两条斜率相等地直线,使得这些点全在直线上。并且每条直线上至少包含一个点。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int a[],n,vis[];
double k1,k2;
int main()
{
scanf("%d",&n);
bool flag=false;
int pos=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]-==) pos++;
}
if(pos==n-) flag=true;
for(int i=;i<=n;i++)
{
memset(vis,,sizeof(vis));
vis[]=,vis[i]=;
k1=((a[i]-a[])*(1.0))/((i-)*1.0);
int ans=;
for(int j=;j<=n;j++)
{
if(((a[j]-a[])*(1.0))/((j-)*1.0)==k1) vis[j]=,ans++;
}
int ok=,xx=-;
for(int j=;j<=n;j++)
{
if(vis[j]== && ok==) xx=j,ok++;
else if(ok== && vis[j]==) k2=((a[j]-a[xx])*(1.0))/((j-xx)*1.0),ok++;
else if(ok>= && vis[j]==)
{
if(((a[j]-a[xx])*(1.0))/((j-xx)*1.0)==k2) ok++;
}
}
if((ans+ok==n && ok && k1==k2) || ans==n- || ok==n-) flag=true;
if(ans==n || ok==n)
{
flag=false;
goto k;
}
}
k:puts(flag?"Yes":"No");
return ;
}

Codefroces 849 A,B的更多相关文章

  1. AOJ.849 分数 (暴力)

    AOJ.849 分数 (暴力) 题意分析 每次枚举分子,然后根据给出的分数值,推算出来分母,然后取分母上下几个数进行进一步计算,看看哪个更接近. 一开始想着直接枚举分子和分母,复杂度爆炸... 代码总 ...

  2. 【LEETCODE】52、数组分类,简单级别,题目:717,661,746,628,643,849

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  3. 【Leetcode_easy】849. Maximize Distance to Closest Person

    problem 849. Maximize Distance to Closest Person solution1: class Solution { public: int maxDistToCl ...

  4. 849. Maximize Distance to Closest Person ——weekly contest 87

    849. Maximize Distance to Closest Person 题目链接:https://leetcode.com/problems/maximize-distance-to-clo ...

  5. Codefroces 1328E Tree Querie(dfs序)

    Codefroces 1328E Tree Querie 题目 给出一棵1为根,n个节点的树,每次询问\(k_i\) 个节点,问是否存在这样一条路径: 从根出发,且每个节点在这条路径上或者距离路径的距 ...

  6. ACM - 最短路 - AcWing 849 Dijkstra求最短路 I

    AcWing 849 Dijkstra求最短路 I 题解 以此题为例介绍一下图论中的最短路算法.先让我们考虑以下问题: 给定一个 \(n\) 个点 \(m\) 条边的有向图(无向图),图中可能存在重边 ...

  7. Codefroces 750D:New Year and Fireworks(BFS)

    http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 3 ...

  8. Codefroces 750C:New Year and Rating(思维)

    http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打 ...

  9. codefroces 589A

    time limit per testsecondsmemory limit per testmegabytesinputstandard inputoutputstandard outputPoly ...

随机推荐

  1. Docker学习总结(12)——非常详细的 Docker 学习笔记

    一.Docker 简介 Docker 两个主要部件: Docker: 开源的容器虚拟化平台 Docker Hub: 用于分享.管理 Docker 容器的 Docker SaaS 平台 -- Docke ...

  2. 【转】C# 正则表达式大全

    [转]C# 正则表达式大全 前言 在网上看到一个不错的简易版正则匹配和替换的工具,现在补充进来,感觉还不错,效果如下(输入验证中文汉字的正则表达式) 在线下载   密码:5tpt 注:好像也是一位园友 ...

  3. mysql中文乱码解决方式

    近期项目使用到mysql.却突然出现了中文乱码问题.尝试了多种方案,最终解决乱码问题,总结一下解决方式,给遇到同样问题的人一点參考. 中文乱码的原因 1.安装mysqlserver的时候编码集设定有问 ...

  4. hadoop-14-进行libtirpc的rpm包安装

    hadoop-14-进行libtirpc的rpm包安装 安装过程中出现了这个问题,进行安装: yum localinstall --nogpgcheck libtirpc-0.2.1-13.el6.x ...

  5. [React] Refactor a Stateful List Component to a Functional Component with React PowerPlug

    In this lesson we'll look at React PowerPlug's <List /> component by refactoring a normal clas ...

  6. MongoDB count distinct group by JavaAPI查询

    import java.net.UnknownHostException; import com.mongodb.BasicDBList; import com.mongodb.BasicDBObje ...

  7. 响应http报文中的Date属性与cookie过期时间的关系

    今天在測试.net时,发现一个莫名其妙的问题:cookie老是保存不到浏览器端; 经过细致的比对成功与不成功的报文,居然无意中发现好像Date与它有关系,这太让我意想不到了,从来不知道cookie保存 ...

  8. OC第二课

    主要内容:实例变量可见度.方法 一.实例变量可见度 public(共同拥有的):实例变量能够在类的内部和外部使用 protected(受保护的.默认的):实例变量仅仅能在该类及其子类中使用 priva ...

  9. 安卓开发--AsyncTask2

    package com.cnn.imageasyncdemo01; import android.app.Activity; import android.content.Intent; import ...

  10. k-meas非监督聚类分析

    实验名称: k-meas非监督聚类分析   一.实验目的和要求 目的: 加深对非监督学习的理解和认识 掌握聚类方法K-Means算法的设计方法   要求:     根据聚类数据,采用k-Means聚类 ...