zoukankan      html  css  js  c++  java
  • LaunchPad

    链接:https://ac.nowcoder.com/acm/contest/3665/D
    来源:牛客网

    Hery is a boy with strong practical abilities. Nowadays,he designed a LaunchPad which is not same as what you ever seen.
    The LaunchPad is a touch screen divided into squares of N rows and M columns. Each square has two states of light and shade. And all squares are shady initially. When you touch the square in row X and column Y, the state of all the squares in the row and column will change. Now he wants to know how many squares are light on the LaunchPad after he makes multiple touches.

    输入描述:

    The first line of input contains two integers N,M(1≤N,M≤1000)N,M (1leq N,Mleq 1000)N,M(1N,M1000) denoting the rows and columns of LaunchPad.
    The second line of input contains single integer Q(0≤Q≤106)Q (0leq Qleq 10^6)Q(0Q106) denoting the times of touch.
    On the next Q lines,describe X and Y - the position of the square being touched. (1≤X≤N,1≤Y≤M)(1leq X leq N,1leq Yleq M)(1XN,1YM)

    输出描述:

    Print one line - the number of the squares that is on light state.
    示例1

    输入

    复制
    1 1
    1
    1 1

    输出

    复制
    1
    示例2

    输入

    复制
    2 4
    2
    2 4
    1 4

    输出

    复制
    6

    说明

    题目大意:

    就是说一开始n*m矩阵中都是暗的,你可以按压n*m矩阵中任意一个方格,该方格行和列都会变亮,再摁一次会变暗,问m次操作后亮的方格的个数;

    解析:

    就是行和列的性质不变,但是vis[a][b]会重复

    AC代码:

    #pragma GCC optimize(2)
    #include<bits/stdc++.h>
    using namespace std;
    inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}
    typedef long long ll;
    const int maxn=1e4+10;
    const int M=1e7+10;
    const int INF=0x3f3f3f3f;
    int vis[1010][1010];
    int h[maxn];//
    int l[maxn];//
    int main()
    {
        int n,m,t; 
        cin>>n>>m>>t;
        int a,b;
        for(int i=0;i<t;i++){
            cin>>a>>b;
            h[a]++;
            l[b]++;
            vis[a][b]++;
        }
        int sum=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if((h[i]+l[j]-vis[i][j])%2==1){
                    sum++;
                }
            }
        }
        printf("%d",sum);
        return 0;
    }
  • 相关阅读:
    页面跳转
    基于MCP2515的Linux CAN总线驱动程序设计(三)
    基于MCP2515的Linux CAN总线驱动程序设计(二)
    基于MCP2515的Linux CAN总线驱动程序设计(一)
    任意ASCII码格式信息的huffman tree压缩(编码)和解压(译码)
    转:Linux环境下段错误的产生原因及调试方法小结
    转:C语言中volatile关键字的作用 专家博客
    处理字节对齐
    转: sizeof,总结
    sizeof()用法汇总
  • 原文地址:https://www.cnblogs.com/lipu123/p/12215556.html
Copyright © 2011-2022 走看看