新生赛02 Problem F. Little Sheep and a paper

本文探讨了通过折纸过程中的数学规律,计算折纸后凸出折痕的数量,并提供了解决此类问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

       One day, god Sheep gets an AK(all kill) in a contest, so he is very boring, then he just plays with a paper. The paper has two faces called A and B. Sheep finds the paper can be folded for infinity times, and now Sheep thinks the paper is interesting, so he tries to fold the paper in half for many times. He finds out he has four way to make the paper folded in half, there are listed below:


At first, god Sheep keeps the face A of the paper faced to him,and he fold the paper for many times. In the end, Sheep opens up the paper, and keeps the face A faced to him again. Now the question is : How many creases on the face A of the paper are protruding? God sheep solves the question without 2 seconds. Can you?  You should make your anwser mod 100000009.

Input

       The first line of input contains a single positive integer N , which means the number of test cases. The following N lines gives N non-empty strings containing only characters in "UDLR", which is the sequences of the actions of the Sheep to fold paper. The length of the each string is a positive number less than 10^6.

Output

       For each case output the anwser mod 100000009 in a line.

Sample Input

4
L
LR
DLUR
ULULL

Sample Output

0
1
10
22


这个题其实是一个找规律的题,弄清楚折纸后凸出来的折痕的规律,就是一个十分简单的题了。

折了好多纸之后,很快就发现了规律。解题的关键就是分开计算横折和竖折的次数。

首先,第一次折纸,无论怎么折,凸出的折痕都是没有的,凸出折痕数都是0,所以不计数。

然后,左折和右折、上折和下折是没有区别的,所以只横折或者只竖折仅和折的次数有关。之后再竖折或者横折不影响总数,分开计算横折(h)和竖折(s)的次数就行了

我们,假设先竖折,可以很轻松的找到规律,凸出的折痕为sum=2^(s-1)

接着是横折,每横折一次,竖折产生的凸出折痕数就会翻一倍,所以每横折一次,sum=sum*2。

竖折会把纸张分成2^s块。

横折产生的凸出折痕数是竖折分成块数的一半,然后乘以横折产生的折痕数就行了。


#include<iostream>
#include<stdio.h>

using namespace std;
#define M 100000009;

char z[1000010];

long long pow(int a,int b)
{
    long long  r=1,base=a;
    while(b!=0)
    {
        if(b&1)
        r=r*base%M;
        base=base*base%M;
        b>>=1;
    }
    return r;
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
	int n,i;
    int l,s;
	int sum;
	scanf("%d",&n);
	while(n--)
	{
	    l=0;s=0;sum=0;
	    scanf("%s",&z);
        for(i=1;z[i];i++)
        {
            if(z[i]=='L'||z[i]=='R')
            {
                l++;
            }
            if(z[i]=='U'||z[i]=='D')
            {
                s++;
            }
        }
	    if(s+l==0)
	    {
	        printf("0\n");
	    }
	    else
	    if(s+l==1)
	    {
	        printf("1\n");
	    }
	    else
	    {
	        if(l!=0)
	        {
                sum=int(sum+pow(2,l)-1)%M;
                for(i=1;i<=s;i++)
                {
                    sum=(sum*2)%M;
                }
                sum=sum+pow(2,l)*(pow(2,s)-1)%M;
            }
            else
            {
                    sum=int(sum+pow(2,s)-1)%M;
            }
            sum=sum%M;
            printf("%d\n",sum);
	    }
	}
	return 0;
}




资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值