zoukankan      html  css  js  c++  java
  • hdu 4046 Panda

    题意:即3个连续的wbw算是一个love。看一下某个区间共同拥有多少个love,多次询问。

    还有替换某个位置的字母,然后询问。

    用树状数组处理,题目并不难,但由于一处想当然错了N次。。。

    题目链接:

    Panda

    #include"stdio.h"
    #include"string.h"
    #define N 50005
    #define lowbit(i) (i&(-i))
    char str[N];
    int c[N],n;
    int judge(char c1,char c2,char c3)
    {
    	if(c1=='w'&&c2=='b'&&c3=='w')
    		return 1;
    	return 0;
    }
    void modify(int x,int d)
    {
    	int i;
    	for(i=x;i<n;i+=lowbit(i))
    		c[i]+=d;
    }
    int getsum(int x)
    {
    	int i,s=0;
    	for(i=x;i>0;i-=lowbit(i))
    		s+=c[i];
    	return s;
    }
    
    void inti()
    {
    	int i;
    	for(i=2;i<n;i++)
    	{
    		if(judge(str[i-2],str[i-1],str[i]))
    			modify(i,1);
    	}
    }
    int main()
    {
    	int T,m,op,l,r,k,cnt=1;
    	char ch;
    	scanf("%d",&T);
    	while(T--)
    	{
    		scanf("%d%d",&n,&m);
    		scanf("%s",str);
    		memset(c,0,sizeof(c));
    		inti();
    		printf("Case %d:
    ",cnt++);
    		while(m--)
    		{
    			scanf("%d",&op);
    			if(op==0)
    			{
    				scanf("%d%d",&l,&r);
    				if(r-l<2)
    				{
    					printf("0
    ");
    					continue;
    				}
    				printf("%d
    ",getsum(r)-getsum(l+1));
    			}
    			else
    			{
    				scanf("%d %c",&k,&ch);
    				if(str[k]==ch)
    					continue;
    				if(k>=2&&judge(str[k-2],str[k-1],str[k]))
    					modify(k,-1);
    				if(k>=2&&judge(str[k-2],str[k-1],ch))
    					modify(k,1);
    				if(k>=1&&k+1<n&&judge(str[k-1],str[k],str[k+1]))
    					modify(k+1,-1);
    				if(k>=1&&k+1<n&&judge(str[k-1],ch,str[k+1]))
    					modify(k+1,1);
    				if(k+2<n&&judge(str[k],str[k+1],str[k+2]))
    					modify(k+2,-1);
    				if(k+2<n&&judge(ch,str[k+1],str[k+2]))
    					modify(k+2,1);
    				str[k]=ch;
    			}
    		}
    	}
    	return 0;
    }



  • 相关阅读:
    Webdriver启动Firefox浏览器后,页面显示空白
    Windows+Python+Selenium基础篇之1-环境搭建
    office2010无法卸载问题
    .NET使用FastDBF读写DBF
    并发编程相关概念
    C#的多线程简洁笔记
    asp.net core 3.1 入口:Program.cs中的Main函数
    【WPF学习】第四十四章 图画
    .NET知识梳理——1.泛型Generic
    C#个推SDK推送安卓+iOS
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/6790003.html
Copyright © 2011-2022 走看看