Codefroces 849 A,B
1 second
256 megabytes
standard input
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.
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 "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
3
1 3 5
Yes
5
1 0 1 5 1
Yes
3
4 3 1
No
4
3 9 9 3
No
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;
}
1 second
256 megabytes
standard input
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.
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 "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).
5
7 5 8 6 9
Yes
5
-1 -2 0 0 -5
No
5
5 4 3 2 1
No
5
1000000000 0 0 0 0
Yes
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的更多相关文章
- AOJ.849 分数 (暴力)
AOJ.849 分数 (暴力) 题意分析 每次枚举分子,然后根据给出的分数值,推算出来分母,然后取分母上下几个数进行进一步计算,看看哪个更接近. 一开始想着直接枚举分子和分母,复杂度爆炸... 代码总 ...
- 【LEETCODE】52、数组分类,简单级别,题目:717,661,746,628,643,849
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 【Leetcode_easy】849. Maximize Distance to Closest Person
problem 849. Maximize Distance to Closest Person solution1: class Solution { public: int maxDistToCl ...
- 849. Maximize Distance to Closest Person ——weekly contest 87
849. Maximize Distance to Closest Person 题目链接:https://leetcode.com/problems/maximize-distance-to-clo ...
- Codefroces 1328E Tree Querie(dfs序)
Codefroces 1328E Tree Querie 题目 给出一棵1为根,n个节点的树,每次询问\(k_i\) 个节点,问是否存在这样一条路径: 从根出发,且每个节点在这条路径上或者距离路径的距 ...
- ACM - 最短路 - AcWing 849 Dijkstra求最短路 I
AcWing 849 Dijkstra求最短路 I 题解 以此题为例介绍一下图论中的最短路算法.先让我们考虑以下问题: 给定一个 \(n\) 个点 \(m\) 条边的有向图(无向图),图中可能存在重边 ...
- Codefroces 750D:New Year and Fireworks(BFS)
http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 3 ...
- Codefroces 750C:New Year and Rating(思维)
http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打 ...
- codefroces 589A
time limit per testsecondsmemory limit per testmegabytesinputstandard inputoutputstandard outputPoly ...
随机推荐
- 题解 LNOI2014 LCA
题目:传送门 这道题根本不用lca,也没有部分分... 考虑求两个点xy的lca的深度. 我们将x到树根所有点的值都加1,然后查询y到根的和,其实就是lca的深度. 所以本题离线一下上树剖乱搞就可以了 ...
- 华夏60 战斗机(最短路dijkstra)
华夏60 战斗机(最短路dijkstra) 华夏60 超音速战斗机是当今世界上机动性能最先进的战斗机.战斗过程中的一个关键问题是如何在最短的时间内使飞机从当前的飞行高度和速度爬升/俯冲到指定的高度并达 ...
- POJ——T2446 Chessboard
http://poj.org/problem?id=2446 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18560 ...
- Qt资料大全
简述 发福利了.发福利了.发福利了,重要的事情说三遍... 为了方便更多Qter了解.学习Qt,现将相关资源进行整理,主要内容包括:Qt官网.编码风格.GitHub & Third-Party ...
- C++primer书店程序
#include <iostream> #include <string> #include <cassert> #include <algorithm> ...
- mysql-过程与函数
一.过程与函数简介 过程与函数是命名的PL/SQL块(也是用户的方案对象),被编译后存储在数据库中,以备执行.因此,其他PL/SQL块可以按名称来使用他们.所以可以将商业逻辑.企业规划写成函数或过程保 ...
- 【剑指Offer面试题】 九度OJ1371:最小的K个数
题目链接地址: http://ac.jobdu.com/problem.php?pid=1371 题目1371:最小的K个数 时间限制:1 秒内存限制:32 兆特殊判题:否提交:5938解决:1265 ...
- android 自己定义dialog并实现失去焦点(背景透明)的功能
前言:因为在项目中须要用到更新显示动画的需求,所以想到了dialog,自己定义dialog不难.网上教程非常多,可是在实现dialog背景透明的需求时,遇到了一点问题.网上的一些方法在我的机器上并没有 ...
- poj_2187求凸包直径
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...
- 51nod-1296: 有限制的排列
[传送门:51nod-1296] 简要题意: 有一个集合,集合中的数为1到n 给出a限制条件,a[i]表示第a[i]位置的数要比相邻位置的数要小 给出b限制条件,b[i]表示第b[i]位置的数要比相邻 ...