• 524 (Div. 2) Masha and two friends


    Codeforces Round #524 (Div. 2)

    C. Masha and two friends

    题目链接

    题意:较为简单,初始给定这个白黑相交的格子,第一遍把坐标范围内的全部涂白,第二遍把坐标范围内的全部涂黑,问最终各个颜色的数目。

    思路:写一个函数,求白黑相间矩阵内的黑色格子的数目,如果格子数为偶数,白=黑。如果为奇数,当矩阵左下角坐标x1+y1为奇数,黑色多一。然后黑色格子数处理三次,第一次减少,第二次增加,第三次(重叠的部分)增加,数目为范围内的原来的黑色格子数。

    知识点,判断矩阵相交

          long long x5,y5,x6,y6;
          x5=max(x1,x3);y5=max(y1,y3);
          x6=min(x2,x4);y6=min(y2,y4);
          if(x5<=x6&&y5<=y6)
    

    #include <iostream>
    #include<cstring>
    #include<iomanip>
    #include<algorithm>
    #include<iostream>
    #include<string>
    #include<cstring>
    #include<vector>
    #include<stack>
    #include<bitset>
    #include<cstdlib>
    #include<cmath>
    #include<set>
    #include<list>
    #include<deque>
    #include<map>
    #include<queue>
    using namespace std;
    typedef long long ll;
       ll n,m;
    ll num_black(ll x1,ll y1,ll x2,ll y2)
    {
        ll ans=(x2-x1+1)*(y2-y1+1);
        if(ans&1 &&(x1+y1)&1)return ans/2+1;else return ans/2;
    }
    int main()
    {
      std::ios::sync_with_stdio(false);
    	std::cin.tie(0);
      int t;
      cin>>t;
      ll n,m,x1,x2,y1,y2,x3,y3,x4,y4;
       ll black;
      while(t--)
      {
          cin>>n>>m>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
          black=num_black(1,1,m,n);
          black-=num_black(x1,y1,x2,y2);
             //  cout<<black<<endl;
          black+=(x4-x3+1)*(y4-y3+1)-num_black(x3,y3,x4,y4);
           //   cout<<black<<endl;
          ll x5,y5,x6,y6;
          x5=max(x1,x3);y5=max(y1,y3);
          x6=min(x2,x4);y6=min(y2,y4);
          if(x5<=x6&&y5<=y6)black+=num_black(x5,y5,x6,y6);
     cout<<n*m-black<<" "<<black<<endl;
    
      }
        return 0;
    }
    
    不疯魔不成活
  • 相关阅读:
    DAY 206 Python验证常见的50个正则表达式
    DAY 205 python使用ftplib模块实现FTP文件的上传下载
    Jmeter组件介绍
    Jmeter安装
    Jmeter学习笔记
    Jmeter:相应断言介绍
    python time模块
    python+selenium+Eclipse安装
    Python os.path模板函数
    ping 计算机全名,返回的不是IP地址
  • 原文地址:https://www.cnblogs.com/gzr2018/p/10021476.html
Copyright © 2020-2023  润新知