题目链接

用两个布尔数组分别维护每个行/列是否被插过旗帜,最后枚举每一行、列统计答案即可。空间复杂度O(n+m),时间复杂度O(n+m+k)。

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int t,ansx[],ansy[],ax,ay;
const int _K=,_B=,_P=;
int _X;
inline int get_rand(int _l,int _r){
_X=((long long)_K*_X+_B)%_P;
return _X%(_r-_l+)+_l;
}
int n,m,k,seed;
int x[],y[];
void Init(){
scanf("%d%d%d%d",&n,&m,&k,&seed);
_X=seed;
for (int i=;i<=k;++i)
x[i]=get_rand(,n),
y[i]=get_rand(,m);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
Init();
memset(ansx,,sizeof(ansx));
memset(ansy,,sizeof(ansy));
ax=;ay=;
for(int i=;i<=k;i++)
{
ansx[x[i]]=;
ansy[y[i]]=;
}
for(int i=;i<=n;i++)
if(!ansx[i]) ax++;
for(int i=;i<=m;i++)
if(!ansy[i]) ay++;
printf("%d %d\n",ax,ay);
}
return ;
}

HDU 5995 Kblack loves flag ---BestCoder Round #90的更多相关文章

  1. HDU 5995 Kblack loves flag (模拟)

    题目链接 Problem Description Kblack loves flags, so he has infinite flags in his pocket. One day, Kblack ...

  2. HDU 5996 dingyeye loves stone ---BestCoder Round #90

    题目链接 设根节点的深度为0,将所有深度为奇数的节点的石子数目xor起来,则先手必胜当且仅当这个xor和不为0. 证明同阶梯博弈.对于偶深度的点上的石子,若对手移动它们,则可模仿操作:对于奇深度上的石 ...

  3. BestCoder Round #90 A.Kblack loves flag(随机数生成种子)

    A.Kblack loves flag [题目链接]A.Kblack loves flag [题目类型]水题 &题意: kblack喜欢旗帜(flag),他的口袋里有无穷无尽的旗帜. 某天,k ...

  4. BestCoder Round #90 A+B题解!

    BestCoder Round #90 A  Kblack loves flag 题意有点迷不造思路很简单但不造怎么求随机数,纠结了一会后直接粘上题目所给的代码稍加修改A了. const int _K ...

  5. BestCoder Round #90

    有生以来第一场在COGS以外的地方打的比赛.挂成dog了. 主要是没有经验,加之代码能力过弱.还有最后的瞎hack三次,Too Young Too Simple...... 言归正传. (抄一发题解先 ...

  6. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  7. HDU - 5996 树上博弈 BestCoder Round #90

    就是阶梯NIM博弈,那么看层数是不是奇数的异或就行了: #include<iostream> #include<cstdio> #include<algorithm> ...

  8. HDU 5432 Rikka with Tree (BestCoder Round #53 (div.2))

    http://acm.hdu.edu.cn/showproblem.php?pid=5423 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树 ...

  9. HDU5806 NanoApe Loves Sequence Ⅱ (BestCoder Round #86 C)二分

    分析:大于等于m的变成1,否则变成0,预处理前缀和,枚举起点,找到第一个点前缀和大于m即可 找第一个点可以二分可以尺取 #include <cstdio> #include <cst ...

随机推荐

  1. 【Junit】JUnit-4.12使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误

    下载了最新的JUnit版本,是4.12,结果尝试使用发现总是报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing这样的错误, 上网查 ...

  2. AD域服务器|两台DC无法进行复制同步

    注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 说明:前段时间公司两台域控出现了一些问题导致数据无法相互进行同步,DC之间也无法进行共享访问,网络用户无法通过计算机名映射的共享访问 ...

  3. ajax浅析---UpdatePanel

    使用UpdatePanel控件 UpdatePanel可以用来创建丰富的局部更新Web应用程序,它是ASP.NET 2.0 AJAX Extensions中很重要的一个控件,其强大之处在于不用编写任何 ...

  4. Java并发包源码学习之AQS框架(一)概述

    AQS其实就是java.util.concurrent.locks.AbstractQueuedSynchronizer这个类. 阅读Java的并发包源码你会发现这个类是整个java.util.con ...

  5. 微信连wifi正式全量对外开放申请 升级智能服务

    之前我们提到过微信公众平台"微信连Wi-Fi"功能来了,昨日,微信连Wi-Fi自助申请入口正式全量对外开放(独立申请入口https://wifi.weixin.qq.com/),意 ...

  6. cf251.2.C (构造题的技巧)

    C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...

  7. 关于CSS中对IE条件注释的问题

    一.通用区分方式:IE6.IE7能识别*,标准浏览器(如FF)不能识别*:IE6能识别*,但不能识别 !important:IE7能识别*,也能识别 !important:IE8能识别\0,不能识别* ...

  8. .net Excel乱码

    .net 生成Excel乱码,如果你一直在乱码,怎么改GB2312和UTF-8也没用,那试试下面的方法吧  HttpContext.Current.Response.AppendHeader(&quo ...

  9. leetcode 100. Same Tree

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  10. leetcode150 Evaluate Reverse Polish Notation

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...