zoukankan      html  css  js  c++  java
  • 【洛谷 3913】车的攻击

    题目描述

    N imes NN×N 的国际象棋棋盘上有KK 个车,第ii个车位于第R_iRi行,第C_iCi 列。求至少被一个车攻击的格子数量。

    车可以攻击所有同一行或者同一列的地方。

    输入格式

    第1 行,2 个整数N,KN,K。

    接下来K 行,每行2 个整数R_i,C_iRi,Ci

    输出格式

    1 个整数,表示被攻击的格子数量。

    输入输出样例

    输入 #1
    3 2
    1 2
    2 2
    输出 #1
    7

    说明/提示

    • 对于30% 的数据,1 le N le 10^3; 1 le K le 10^31N103;1K103;

    • 对于60% 的数据,1 le N le 10^6; 1 le K le 10^61N106;1K106;

    • 对于100% 的数据,1 le N le 10^9; 1 le K le 10^6; 1 le R_i , C_i le N1N109;1K106;1Ri,CiN。

    题解:这题有点似曾相识啊…数学题(二话不说先吸氧)

    // luogu-judger-enable-o2
    // luogu-judger-enable-o2
    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    typedef long long ll;
    using namespace std;
    const int N=1000009;
    long long n,k,x[N],y[N],i,h,l;
    int main()
    {
        cin>>n>>k;
        int a=1;
        int b=1;
        for(i=1;i<=k;i++)
        cin>>x[i]>>y[i];
        sort(x+1,x+k+1);
        sort(y+1,y+k+1);
        for(i=1;i<=k;i++)
        {
            if(x[i]!=x[i+1] && a==b) h++;
            if(y[i]!=y[i+1] && a==b) l++;
        }
        cout<<n*n-(n-h)*(n-l);
    }
  • 相关阅读:
    利用Telnet来模拟Http请求 有GET和POST两种
    WebConfig特殊字符的转义!
    userprofile同步用户失败的原因和解决方案
    linux mysql表名大小写
    web.py 中文模版报错
    docker 开启远程
    web.py 笔记
    python 安装influxdb-python
    安装pip
    influxdb 命令
  • 原文地址:https://www.cnblogs.com/wuhu-JJJ/p/11243180.html
Copyright © 2011-2022 走看看