H-Fashion in Berland
#include <bits/stdc++.h>
using namespace std;
int a[1005];
int main()
{
int n;
scanf("%d",&n);
int sum = 0;
int flag;
for(int i = 0; i < n; i ++)
{
scanf("%d",&a[i]);
if(a[i]==0){
sum ++;
}
}
if(n == 1)
{
if(a[0] == 1)
{
flag = 1;
}
else
{
flag = 0;
}
}
else
{
if(sum==1)
{
flag = 1;
}
else
{
flag = 0;
}
}
if(flag)
printf("YES\n");
else
printf("NO\n");
return 0;
}
题目描述:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with n buttons. Determine if it is fastened in a right way.
Input
The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.
The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1.
Output
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
Example
3
1 0 1
YES
3
1 0 0
NO
H-Fashion in Berland的更多相关文章
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- codeforces 691A A. Fashion in Berland(水题)
题目链接: A. Fashion in Berland 题意: 思路: AC代码: //#include <bits/stdc++.h> #include <iostream> ...
- 【模拟】Codeforces 691A Fashion in Berland
题目链接: http://codeforces.com/problemset/problem/691/A 题目大意: n个数0或1,要求恰好n-1个1,如果n为1则那个数一定要是1 题目思路: [模拟 ...
- Codeforces 691A Fashion in Berland
水题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #includ ...
- Educational Codeforces Round 14
A - Fashion in Berland 水 // #pragma comment(linker, "/STACK:102c000000,102c000000") #inclu ...
- Codeforces Round #375 (Div. 2)——D. Lakes in Berland(DFS连通块)
D. Lakes in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #375 (Div. 2) D. Lakes in Berland dfs
D. Lakes in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 644A Parliament of Berland
A. Parliament of Berland time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...
随机推荐
- babel tsc webpack
我要用啥?js的话:babel编译+webpack模块打包ts的话:tsc编译成js+babel编译+webpack模块打包浏览器情况:如果您的浏览器支持es6所有语法那么就可以只用webpack来处 ...
- 写一个vue的滚动条插件
组件源码如下: vue-scroll.vue <template> <div class="vue-scroll" ref="vueScrollW&qu ...
- VS.NET(C#)--2.3良构的XHTML
良构的XHTML 1.关闭所有标签 2.禁止标签嵌套 3.区分大小写 4.引号 所有属性值都要置于引号中 5.唯一的根元素<html></html> 6.保留字符 XML中五 ...
- Java源码阅读之ArrayList
基于jdk1.8的ArrayList源码分析. 实现List接口最常见的大概就四种,ArrayList, LinkedList, Vector, Stack实现,今天就着重看一下ArrayList的源 ...
- zabbix4.2的yum+mariadb方式部署安装
本文依据官方文档操作(英文4.2):https://www.zabbix.com/documentation/4.2/manual/installation/install_from_packages ...
- 2743711 - Possible Unexpected Results When Using Query With an ORDER BY Clause on a Rowstore Table With a Parallelized Search on a Cpbtree-Type Index
2743711 - Possible Unexpected Results When Using Query With an ORDER BY Clause on a Rowstore Table W ...
- dao 接口定义了一个方法,报错 The method xxx is undefined for the type xxx;
转自:https://blog.csdn.net/panshoujia/article/details/78203837 持久层(DAO层)下的一个接口 ,eclipse报了一个The method ...
- awk 常用选项及数组的用法和模拟生产环境数据统计
awk 常用选项总结 在 awk 中使用外部的环境变量 (-v) awk -v num2="$num1" -v var1="$var" 'BEGIN{print ...
- Linux中条件语句
Linux中备份一个jar包,需要既判断进程是否停止,又判断文件是否存在 1. 进程停了,文件存在则备份 2.进程停了,文件不存在,无需备份 3. 进程在跑,停止进程:文件存在,将文件进行备份 4. ...
- python小知识点汇总
一 写mysql 场景:自动化用例中需要构造数据,写入redis 表中已有该primary_key的记录,在现有基础上更新字段 表中无该记录,需要插入 # 请求传入table字段,db.table,c ...