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. 基于LevelDB的高可用ActiveMQ集群

    基于LevelDB的高可用ActiveMQ集群 http://donald-draper.iteye.com/blog/2347913

  2. UNIX环境高级编程之第4章:文件和文件夹-习题

    4.1 stat函数是尾随符号链接的,所以用stat替换lstat不会显示符号链接的信息 4.2 在一个目录下先再shell中输入umask shell进程再进行创建文件的操作.其权限抖都会被屏蔽 4 ...

  3. HNU13377:Book Club(DFS)

    Problem description Porto's book club is buzzing with excitement for the annual book exchange event! ...

  4. ubuntu,jdk安装成功后,点击eclipse,提示信息A Java RunTime Environment (JRE) or Java Development Kit (JDK)

    A Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Ecl ...

  5. Case study: word play

    For the exercises in this chapter we need a list of English words. There are lots of word lists avai ...

  6. JMeter使用碰到的问题

    1.创建http请求 使用threadGroup-->add-->sampler--http request 2.使用计数器 使用threadGroup-->add-->con ...

  7. C语言基础-第三章

    C语句和数据输入/输出(函数) 1.printf();输出函数 2.getch();输入函数 3.scanf();格式输入 4.puts();字符串输出 5.gets();字符串输入

  8. AngularJs轻松入门(六)表单校验

    表单数据的校验对于提高WEB安全性意义不大,因为服务器接收到的请求不一定来自我们的前端页面,有可能来自别的站点,黑客可以自己做一个表单,把数据提交到我们的服务器(即跨站伪造请求),这样就绕过了前端页面 ...

  9. js中字符串转驼峰转为下划线

    function dasherize(str) { return str.replace(/::/g, '/') .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') ...

  10. 鼠标点击textarea后,在光标后追加内容

    $("#insertMsg").on("click",function(){ //获取下拉选项框的值 var textFeildValue = $(" ...