Codeforces 691A. Fashion in Berland

题目链接:http://codeforces.com/problemset/problem/691/A

题意:

  有一个夹克上有 n 个扣子,能扣紧这个夹克的要求是恰好有 n - 1 个扣子是扣着的,如果这个夹克恰有一个扣子,那么这个扣子应该是扣着的,用 “1” 代表扣着,用 “0” 代表开着,问这个夹克能否扣紧.(原题意比较难翻译!!!!)

代码:

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int MAXN = 100000;
 6 typedef long long LL;
 7 
 8 int main() {
 9     ios_base::sync_with_stdio(0); cin.tie(0);
10     int n; cin >> n;
11     int a[3] = {0};
12     for(int i = 0; i < n; i++) { int m; cin >> m; a[m] ++ ; }
13     int OK = 0;
14     if(n == 1 && a[1] == 1) OK = 1;
15     if(n != 1 && a[1] == n - 1) OK = 1;
16     if(OK) cout << "YES" << endl;
17     else cout << "NO" << endl;
18     return 0;
19 }

 

posted @ 2016-09-03 16:23  vrsashly  阅读(287)  评论(0编辑  收藏  举报