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 ...
随机推荐
- C# 、子窗体调用父窗体属性、方法
namespace Test { public partial class FrmMain : Form { public FrmMain() { InitializeComponent(); } p ...
- 如何判断当前修改过的datatable的某一列值是否为int型或double类型
如何判断当前修改过的datatable的某一列值是否为int型或double类型 今天在做datatable数据验证时碰到要对datatable的列数据进行数据类型校验,因此记录一下本人校验的方法,如 ...
- core直接获取报异常数据
报异常直接跳转到/Home/Error [ResponseCache(Duration = , Location = ResponseCacheLocation.None, NoStore = tru ...
- js 遍历树的层级关系的实现
1.遍历树的层级关系 1)先整理数据 2)找到id和数据的映射关系 3)然后找到父节点的数据,进行存储 test() { const list = [ { id: ", parentId: ...
- kubernetes 应用快速入门
使用kubectl进行增.删.查.改等常用操作 查看kubectl命令帮助 kubectl -h kubectl controls the Kubernetes cluster manager. Fi ...
- ELK文档--ELK简介
请参考:http://www.cnblogs.com/aresxin/p/8035137.html
- JAVA笔记整理(六),JAVA中的多态
JAVA引用变量有两个类型:一个是编译时类型,一个运行时类型 编译时类型由声明该变量时使用的类型决定,运行时类型由实际赋给该变量的对象决定.如果编译时类型和运行时类型不一样,就形成了多态. 因为子类其 ...
- JAVA笔记整理(七),JAVA几个关键字
本篇主要总结JAVA中的super.this.final.static.break.continue 1.super super主要用在继承当中,表示调用父类的构造函数. 1.如果要在子类方法中调用父 ...
- Linux sudo(CVE-2019-14287)漏洞复现过程
简述: 该漏洞编号是CVE-2019-14287. sudo是Linux系统管理指令,允许用户在不需要切换环境的前提下用其他用户的权限运行程序或命令,通常是以root身份运行命令,以减少root用户的 ...
- 读入 并查集 gcd/exgcd 高精度 快速幂
ios_base::sync_with_stdio(); cin.tie(); ], nxt[MAXM << ], Head[MAXN], ed = ; inline void added ...