HDU 5995 Kblack loves flag ---BestCoder Round #90

题目链接

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

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int t,ansx[1000005],ansy[1000005],ax,ay;
const int _K=50268147,_B=6082187,_P=100000007;
int _X;
inline int get_rand(int _l,int _r){
    _X=((long long)_K*_X+_B)%_P;
    return _X%(_r-_l+1)+_l;
}
int n,m,k,seed;
int x[1000006],y[1000006];
void Init(){
    scanf("%d%d%d%d",&n,&m,&k,&seed);
    _X=seed;
    for (int i=1;i<=k;++i)
        x[i]=get_rand(1,n),
        y[i]=get_rand(1,m);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        Init();
        memset(ansx,0,sizeof(ansx));
        memset(ansy,0,sizeof(ansy));
        ax=0;ay=0;
        for(int i=1;i<=k;i++)
        {
            ansx[x[i]]=1;
            ansy[y[i]]=1;
        }
        for(int i=1;i<=n;i++)
        if(!ansx[i]) ax++;
        for(int i=1;i<=m;i++)
        if(!ansy[i]) ay++;
        printf("%d %d\n",ax,ay);
    }
    return 0;
}
时间: 2024-07-28 13:24:35

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

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

题目链接 设根节点的深度为0,将所有深度为奇数的节点的石子数目xor起来,则先手必胜当且仅当这个xor和不为0. 证明同阶梯博弈.对于偶深度的点上的石子,若对手移动它们,则可模仿操作:对于奇深度上的石子,移动一次即进入偶深度的点. 时空复杂度O(n). 用vector存搜一下就行. #include <cstdio> #include <iostream> #include <vector> #include <cstring> using namespac

HDU 5268 ZYB loves Score (BestCoder Round#44)

题目链接:ZYB loves Score 题面: ZYB loves Score Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 395    Accepted Submission(s): 232 Problem Description One day,ZYB participated in the BestCoder Contest

hdu 5230 ZCC loves hacking(BestCoder Round #41)

ZCC loves hacking                                                   Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others) Total Submission(s): 126    Accepted Submission(s): 49 Problem Description Now, a Codefires roun

BestCoder Round #90

有生以来第一场在COGS以外的地方打的比赛.挂成dog了. 主要是没有经验,加之代码能力过弱.还有最后的瞎hack三次,Too Young Too Simple...... 言归正传. (抄一发题解先) T1 Kblack loves flag 用两个布尔数组分别维护每个行/列是否被插过旗帜,最后枚举每一行.列统计答案即可.空间复杂度O(n+m),时间复杂度O(n+m+k). T2 dingyeye loves stone 设根节点的深度为0,将所有深度为奇数的节点的石子数目xor起来,则先手必

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

BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这个题.... C 数据结构题   我写了半个小时分块   然后发现     改的是颜色.... 我的天  炸炸炸 D. 没看懂题目要干啥.....  官方题解要搞死小圆

HDU-5194-DZY Loves Balls(BestCoder Round # 35 )

DZY Loves Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 374    Accepted Submission(s): 205 Problem Description There are n black balls and m white balls in the big box. Now, DZY starts

HDU 5224 Tom and paper(BestCoder Round #40)

题目链接:Tom and paper 题面: Tom and paper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 679    Accepted Submission(s): 432 Problem Description There is a piece of paper in front of Tom, its length

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

分析:大于等于m的变成1,否则变成0,预处理前缀和,枚举起点,找到第一个点前缀和大于m即可 找第一个点可以二分可以尺取 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef long long LL; const int N = 2e5+5; int T,n,m,k,a[N],sum[N]; int mai

HDU5805 NanoApe Loves Sequence (BestCoder Round #86 B)前后缀预处理

分析:维护空隙的差,然后预处理前缀最大,后缀最大,扫一遍 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef long long LL; const int N = 1e5+5; int a[N],T,n,b[N],l[N],r[N]; int main(){ scanf("%d",&