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)denoting the rows and columns of LaunchPad.
    The second line of input contains single integer Q(0≤Q≤106) 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)

    输出描述:

    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 

    说明

    开两个数组分别记录当前行或列是否有操作,再开一个二维数组计算每个灯在操作后的亮灭情况(用来调整行和列所带来的一次操作而不是两次操作)。

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <stack>
     9 #include <queue>
    10 #include <set>
    11 #include <map>
    12 #include <sstream>
    13 #include <ctime>
    14 const int INF=0x3f3f3f3f;
    15 typedef long long LL;
    16 const int mod=1e9+7;
    17 const LL MOD=20010905;
    18 const double PI = acos(-1);
    19 const double eps =1e-8;
    20 #define Bug cout<<"---------------------"<<endl
    21 const int maxn=1e5+10;
    22 using namespace std;
    23 
    24 int row[1005];
    25 int col[1005];
    26 int d[1005][1005];
    27 
    28 int main()
    29 {
    30     #ifdef DEBUG
    31     freopen("sample.txt","r",stdin);
    32     #endif
    33 //    ios_base::sync_with_stdio(false);
    34 //    cin.tie(NULL);
    35     
    36     int n,m;
    37     scanf("%d %d",&n,&m);
    38     int q;
    39     scanf("%d",&q);
    40     for(int i=1;i<=q;i++)
    41     {
    42         int x,y;
    43         scanf("%d %d",&x,&y);
    44         row[x]++;
    45         col[y]++;
    46         d[x][y]++;
    47     }
    48     int sum=0;
    49     for(int i=1;i<=n;i++)
    50     {
    51         for(int j=1;j<=m;j++)
    52         {
    53             if((row[i]+col[j]+d[i][j])&1)
    54                 sum++;
    55         }
    56     }
    57     printf("%d
    ",sum);
    58     
    59     return 0;
    60 }
     1 作者:Uncle_drew
     2 链接:https://ac.nowcoder.com/discuss/363155?type=101
     3 来源:牛客网
     4 
     5 #include<bits/stdc++.h>
     6 using namespace std;
     7 #define ll long long
     8 const int maxn=1000+10;
     9 int a[maxn],b[maxn];
    10 int c[maxn][maxn];
    11 int main()
    12 {
    13     int n,m,q;
    14     scanf("%d %d",&n,&m);
    15     scanf("%d",&q);
    16     while(q--){
    17         int u,v;
    18         scanf("%d %d",&u,&v);
    19         c[u][v]^=1;
    20         a[u]^=1;
    21         b[v]^=1;
    22     }
    23     int ans=0;
    24     for(int i=1;i<=n;i++){
    25         for(int j=1;j<=m;j++){
    26             ans+=a[i]^b[j]^c[i][j];
    27         }
    28     }
    29     printf("%d
    ",ans);
    30     return 0;
    31 }

    -

  • 相关阅读:
    TTFB
    区分数组与对象
    单点登录使用163邮箱
    从其它系统登录到SharePoint 2010系统的单点登录
    js 弹出对话框3种方式
    PowerShell编辑
    修改SharePoint页面上的控件数量的限制
    在SharePoint 2010页面中嵌入SWF文件
    修改SharePoint列表项显示“新”图标的天数
    JSP页面显示乱码
  • 原文地址:https://www.cnblogs.com/jiamian/p/12216450.html
Copyright © 2011-2022 走看看