首页 > 其他分享 >D. Rudolf and the Ball Game

D. Rudolf and the Ball Game

时间:2024-03-18 19:55:17浏览次数:20  
标签:Ball int Game Rudolf ri mod

题解:模拟+去重

每一次扔球都将所有可能性加入队列,并设为一层;然后将一层的可能性挨个出列并进行 ((qj+ri−1) mod n+1),((qj−ri−1+n) mod n+1)操作,然后去重后入列。

code

 

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[1005];
int main(){
//    freopen("input.txt","r",stdin);
    int t;
    cin>>t;
    while (t--){
        int n,m,x;
        cin>>n>>m>>x;
        int r=0,l=0;
        a[r++]=x;
        for (int i=1;i<=m;i++){
            memset(b,0,sizeof(b));
            int ri,R=r;
            char c;
            cin>>ri>>c;
            while (l<R){
                int zero=(a[l]+ri-1)%n+1,one=(a[l]+n-ri-1)%n+1;
                if (c=='?') {
                    if (b[zero]==0){
                        a[r++]=zero;
                        b[zero]=1;
                    }
                    if (b[one]==0){
                        a[r++]=one;
                        b[one]=1;
                    }
                }
                if (c=='0')
                    if (b[zero]==0){
                        a[r++]=zero;
                        b[zero]=1;
                    }
                if (c=='1') 
                    if (b[one]==0){
                        a[r++]=one;
                        b[one]=1;
                    }
                l++;
            }
        }
        cout<<r-l<<endl;
        sort(a+l,a+r);
        cout<<a[l++];
        while (l<r) cout<<" "<<a[l++];
        cout<<endl;
    }
    return 0;
}

 

标签:Ball,int,Game,Rudolf,ri,mod
From: https://www.cnblogs.com/purple123/p/18081276

相关文章

  • Codeforces Round 933 G. Rudolf and Subway
    原题链接:Problem-G-Codeforces思路:根据题意可知相同颜色的边一定是联通的,那么就可以设置虚点,例如1-2,2-3,3-4边的颜色都是相同的,那么就可以设置一个特殊的点例如设置为10,那么这三条边就可以改成1-10,10-2,2-10,10-3,3-10,10-4,从点到虚点需要1的代价,但是从虚点到其他点不需要代价,......
  • Codeforces Round 933 Rudolf and k Bridges
    原题链接:Problem-E-Codeforces题目大意:给一个行为n列为m的河流二维数组,数字代表河流的深度。题目要求连续建造k座桥,桥的定义是从第一列到第m列,每隔d需要按照支架,安装支架的代价是深度+1。问安装最少需要多少代价?思路:单调队列优化dp,dp数组只需要一维,dp[i]的含义是从1到i建......
  • B. Rudolf and 121
    题解由于a1的值只能通过对a2的操作进行消除,所以我们可以先根据a1的值迭代出a2,a3的值,然后此时的a2,只能通过a3的操作进行消除.....以此类推,如果其中发现有ai的值<0就输出NO。code #include<bits/stdc++.h>usingnamespacestd;constintN=2e5+5;inta[N];intmain(){//......
  • C. Rudolf and the Ugly String
    题解遇到map时,sum++;遇到pie时,sum++。特殊情况遇到mapie时,sum--(因为map,pie分别加了一次,但是该子串只需要去掉p即可)code #include<bits/stdc++.h>usingnamespacestd;constintN=2e5+5;inta[N];intmain(){//freopen("input.txt","r",stdin);intt;ci......
  • A. Rudolf and the Ticket
    题解简单的二分应用,对于每个bi我们只需找到最大的ci使得bi+ci<=target即可code #include<bits/stdc++.h>usingnamespacestd;inta[105],b[105];intmain(){//freopen("input.txt","r",stdin);intt;cin>>t;while(t--){int......
  • G. Rudolf and Subway
    原题链接题解太巧妙了!!原题等效于该分层图,然后广搜本题中我用了另一种方法建边,因为清空太麻烦了code#include<bits/stdc++.h>usingnamespacestd;intmain(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);intt;cin>>t;while(t--)......
  • F. Rudolf and Imbalance
    原题链接题解最大值最小\(\to\)二分可行性判断:二分间断值\(len\\to\)如果原序列\(a_i-a_{i-1}>len\)\(\to\)双指针判断有没有\(b+f\)使得\(a_i-len<=b+f<=a_{i-1}+len\)由于只能使用一次,所以若使用两次也算错code#include<bits/stdc++.h>usingnamespacestd;......
  • 最奢华区块链游戏LouisTheGame:时尚精品LV结合NFT探索品牌历史
    数字化时代,奢侈品牌LouisVuitton(LV)不仅以其独特的设计和传统的工艺闻名,还在不断探索新的市场和创新方式来吸引年轻一代的消费者。其中,最奢华区块链游戏LouisTheGame作为LV品牌历史上的一次尝试,结合了游戏化元素和区块链技术,为玩家提供了一次与品牌互动的全新体验。让我们深入......
  • 04 games101-变换(模型、视图、投影)
    04变换(模型、视图、投影)MVP变换MVP变换用来描述视图变换的任务,即将虚拟世界中的三维物体映射(变换)到二维坐标中。MVP变换分为三步:●模型变换(modeltranformation):将模型空间转换到世界空间(找个好的地方,把所有人集合在一起,摆个pose)●摄像机变换(viewtranformation):将......
  • 06 games101-光栅化(深度测试与抗锯齿)
    06光栅化(深度测试与抗锯齿)从采样分析走样采样的对象:●在位置上采样——照片●在时间上采样——视频以下副标题均是在时域上分析。采样的瑕疵(Artifacts)Artifacts(Erros/Mistakes/Inaccuracies)●锯齿●摩尔纹●车轮效应●…走样的原因信号频率太快,采样太......