貌似和POj1753一样是一般都是用为位运算+枚举做的。但是捏。这里用了贪心算法很容易。怎么样才能做到只把当前位置的+改为-而不改变其它所有位置的符号呢。嗯。就是把当前位置所在的行和列所在的元素都反转一次。最后统计操作数是记数的位置就是要操作的位置。详见代码:

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;

char m;
int num[5][5];

int main()
{
    memset(num, 0, sizeof(num));
    for (int i=0; i<4; ++i)
    {
        for (int j=0; j<4; ++j)
        {
            cin >> m;
            if (m == '+')
            {
                for (int k=0; k<4; ++k)
                {
                   num[i][k]++;
                   num[k][j]++;
                }
                num[i][j]--;
            }
        }
    }
    int tot = 0;
    for (int i=0; i<4; ++i)
    {
        for (int j=0; j<4; ++j)
        {
            tot += num[i][j] % 2;
        }
    }
    cout << tot << endl;
    for (int i=0; i<4; ++i)
    {
        for (int j=0; j<4; ++j)
        {
            if (num[i][j] % 2)
            {
                cout << i+1 << ' ' << j+1 << endl;
            }
        }
    }
    return 0;
}

POJ 2965贪心神解的更多相关文章

  1. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  2. 枚举 POJ 2965 The Pilots Brothers' refrigerator

    题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...

  3. poj 2965 The Pilots Brothers&#39; refrigerator(dfs 枚举 +打印路径)

    链接:poj 2965 题意:给定一个4*4矩阵状态,代表门的16个把手.'+'代表关,'-'代表开.当16个把手都为开(即'-')时.门才干打开,问至少要几步门才干打开 改变状态规则:选定16个把手 ...

  4. POJ 2965 The Pilots Brothers' refrigerator【枚举+dfs】

    题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#pro ...

  5. poj 2965 The Pilots Brothers' refrigerator枚举(bfs+位运算)

    //题目:http://poj.org/problem?id=2965//题意:电冰箱有16个把手,每个把手两种状态(开‘-’或关‘+’),只有在所有把手都打开时,门才开,输入数据是个4*4的矩阵,因 ...

  6. poj 2965

    http://poj.org/problem?id=2965 本题要结合poj 1753 来看最好...又有了一点搜索的经验..加油... #include <iostream> #inc ...

  7. POJ 2965&&1753

    最近由于复习备考(然而考得还是很炸),很久没打题目了.现在开始刷寒假作业,不得不搞POJ 话说没有中文真的好烦啊! 先看1753 题目大意是说在一个4*4的格子中有黑白两色的棋子,你可以翻动其中的棋子 ...

  8. POJ 2965 The Pilots Brothers' refrigerator (枚举+BFS+位压缩运算)

    http://poj.org/problem?id=2965 题意: 一个4*4的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...

  9. poj 2965 The Pilots Brothers' refrigerator (dfs)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17450 ...

随机推荐

  1. Java求两个数平均值

    如何正确的求2个数的平均值.在练习算法二分查找的时候发现的,以前没有注意到的bug 备注:数据以int类型为例 一.以前的通用写法 /** * 求a+b平均值 * @param a * @param ...

  2. (转)MyBatis & MyBatis Plus

    (二期)3.mybatis与mybatis plus [课程三]mybatis ...运用.xmind0.1MB [课程三]mybatis...机制.xmind0.2MB [课程三]mybatis与j ...

  3. 解决 E: Unable to correct problems, you have held broken packages. 问题

    参考: Unable to correct problems, you have held broken packages 环境 Ubuntu 14.04, 64bit 问题 在安装gcc-4.9的时 ...

  4. python ros 订阅robot_pose获取机器人位置

    #!/usr/bin/env python import rospy import tf from tf.transformations import * from std_msgs.msg impo ...

  5. django 数据库同步

    python manage.py makemigrations python manage.py migrate

  6. MAC下Java安装之后的路径

    pwd /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home 安装好jdk之后,就开始配置环境变量了. 首先,在终端输入 s ...

  7. 转载: 华为内部Web安全测试原则

    原链接:http://www.ha97.com/5520.html Web安全原则 1.认证模块必须采用防暴力破解机制,例如:验证码或者多次连续尝试登录失败后锁定帐号或IP. 说明:如采用多次连续尝试 ...

  8. SQL Insert Case When Update

    CREATE TABLE LoadTestTable ( ID INT IDENTITY(1,1), FIRSTNAME VARCHAR(50), LASTNAME VARCHAR(50), GEND ...

  9. Random随机类

    // 创建随机数对象 Random random = new Random(); System.out.println("随机的boolean值" + random.nextBoo ...

  10. 直接通过OptionalAttribute, DefaultParameterValueAttribute定义缺省参数