Paste will expire never.
- // Очно-заочный кружок
- // Занятие №9. Дополнительные олимпиадные задачи
- // Задача A. Проверьте правильность ситуации
- // ibelyaev: 31Oct2011
- // http://cppalgo.blogspot.com/2011/04/blog-post.html
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <string>
- #include <string.h>
- #include <cmath>
- #include <queue>
- #include <vector>
- #include <map>
- #include <stdlib.h> // for exit(0)
- #include <stack>
- #include <list>
- #include <ctime>
- #include <set>
- using namespace std;
- int n;
- int mas[3][3];
- int one, two;
- void input(){
- for (int i=0;i<3;++i)
- for (int j=0;j<3;++j) {
- scanf("%d", &mas[i][j]);
- if (mas[i][j] == 1) one++;
- if (mas[i][j] == 2) two++;
- }
- }
- bool check_amount() {
- return one == two || one == two + 1;
- }
- int calc_ver(int val) {
- int amount = 0;
- for (int j=0;j<3;++j) {
- bool isOK = true;
- for (int i=0;i<3;++i)
- isOK &= mas[i][j] == val;
- amount += isOK ? 1 : 0;
- }
- return amount;
- }
- int calc_gor(int val) {
- int amount = 0;
- for (int i=0;i<3;++i) {
- bool isOK = true;
- for (int j=0;j<3;++j)
- isOK &= mas[i][j] == val;
- amount += isOK ? 1 : 0;
- }
- return amount;
- }
- int calc_dia(int val) {
- int amount = 0;
- amount += (mas[0][0] == mas[1][1] && mas[1][1] == mas[2][2] && mas[2][2] == val) ? 1 : 0;
- amount += (mas[2][0] == mas[1][1] && mas[1][1] == mas[0][2] && mas[0][2] == val) ? 1 : 0;
- return amount;
- }
- bool check_lines() {
- int ONE = calc_ver(1) + calc_gor(1) + calc_dia(1);
- int TWO = calc_ver(2) + calc_gor(2) + calc_dia(2);
- return
- (one == two && !ONE && TWO <= 1) ||
- (one == two + 1 && !TWO && ONE <= 1) ||
- (one == 5 && two == 4);
- }
- void solve(){
- bool isOK = true;
- isOK &= check_amount();
- isOK &= check_lines();
- if (isOK)
- printf("YES");
- else
- printf("NO");
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- input();
- solve();
- return 0;
- }
Editing is locked.