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;
    }
  • 相关阅读:
    Java 中的按值传递
    字符串排序(非字典排序)
    字符串匹配的KMP算法(转)
    效率更高的整数转化为字符串函数
    Trie 树(转)
    C 语言字符串(译)
    linux 下 epoll 编程
    CSS攻击:记录用户密码
    Wireshark(抓包神器)使用方法
    搭建KVM环境——Linux上安装KVM带web管理界面
  • 原文地址:https://www.cnblogs.com/lipu123/p/12215556.html
Copyright © 2011-2022 走看看