【BZOJ2054】疯狂的馒头

Description
这里写图片描述

Input

第一行四个正整数N,M,p,q

Output

一共输出N行,第i行表示第i个馒头的最终颜色(如果最终颜色是白色就输出0)。

Sample Input

4 3 2 4
Sample Output

2

2

3

0
HINT
这里写图片描述

Source

冰茶几的小应用

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define MAXN 1000010
#define GET (ch>='0'&&ch<='9')
using namespace std;
int n,m,p,q;
int c[MAXN],f[MAXN];
int find(int x) {   return (f[x]==x||!f[x])?f[x]=x:f[x]=find(f[x]); }
int main()
{
    for (scanf("%d%d%d%d",&n,&m,&p,&q);m;m--)
    {
        int i=m,l=((long long)(i*p)+q)%n+1,r=((long long)(i*q)+p)%n+1;
        if (l>r)    swap(l,r);
        for (int j=find(l);j<=r;j=find(j))  c[j]=i,f[j]=j+1;
    }
    for (int i=1;i<=n;i++)  printf("%d\n",c[i]);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值