
题目链接:Bear and Finding Criminals
大致题意就是小熊警察住在某个城市,他要抓各个城市的罪犯,现在用一个 BCD 可以知道那个城市里一定有罪犯。
一定能确定该城市有小偷的几种情况:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include<bits/stdc++.h> using namespace std; int t[107]; int main() { int n, a; while(cin>>n>>a){ int sum = 0; for(int i =1; i <= n; i++) cin >> t[i]; if(t[a]) sum++;//小熊所在城市有罪犯 for(int i = 1; i <= n; i++){ if(a-i > 0&&a+i <= n) { if(t[a-i] == 1&&t[a+i] == 1) sum+=2; } else if(a-i <= 0&&a+i <= n){//警察在第一个点 if(t[a+i]) sum++; } else if(a-i > 0&&a+i > n){ if(t[a-i]) sum++; } } cout <<sum<<endl; } return 0; } |
|---|