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 ...
随机推荐
- Rancher介绍安装以及对docker的管理
原文:Rancher介绍安装以及对docker的管理 一.简介 Rancher是一个开源的企业级全栈化容器部署及管理平台.Rancher为容器提供一揽子基础架构服务:CNI兼容的网络服务.存储服务.主 ...
- ETL-informatica进阶资料整理
名称 资源 说明 Informatica全球客户支持网站 https://network.informatica.com/ Informatica全球客户支持网站Network,其前身为MySuppo ...
- 阿里云CentOS系统配置iptables防火墙
虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT.OUTPUT和FORWORD都是ACCEPT的规则 一.检查iptabl ...
- [javase学习笔记]-7.6 thiskeyword的原理
这一节我们来讲一个keyword.就是thiskeyword. 我们还是通过样例来看吧: class Person { private String name; private int age; Pe ...
- FPGA静态时序分析——IO口时序(Input Delay /output Delay)
1.1 概述 在高速系统中FPGA时序约束不止包括内部时钟约束,还应包括完整的IO时序约束和时序例外约束才能实现PCB板级的时序收敛.因此,FPGA时序约束中IO口时序约束也是一个重点.只有约束正确 ...
- System Databases in SQL Server
https://docs.microsoft.com/en-us/sql/relational-databases/databases/system-databases SQL Server incl ...
- hdoj--5569--matrix(动态规划)
matrix Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- spring cloud集成 consul源码分析
1.简介 1.1 Consul is a tool for service discovery and configuration. Consul is distributed, highly ava ...
- Android框架-Volley(二)
1. ImageRequest的用法 前面我们已经学习过了StringRequest和JsonRequest的用法,并且总结出了它们的用法都是非常类似的,基本就是进行以下三步操作即可: 1. 创建一个 ...
- PullToRefreshListView的刷新和加载的控制
pullToRefresh.setMode(Mode.BOTH); Mode.BOTH:同时支持上拉下拉 Mode.PULL_FROM_START:只支持下拉Pulling Down M ...