【codechef】Devu and his Class(巧妙的 模拟,分类讨论)

本文探讨了Devu在一个特殊类型的锁上所面临的挑战:如何在有限的时间内创建尽可能多的、符合特定数学条件的锁组合。文章详细解释了锁的工作原理、成本计算方式以及求解方法。

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

Devu likes to play with a lock of N dials. Each dial rotates from numbers 0 to 9 clockwise (i.e. 0 to 1, 2 to 3 and 8 to 9). You can not rotate from 9 to 0.

Initially all the dials of the lock are set to 0. From the current lock, Devu can move any dial to at most 10 different positions (i.e. 0 to 9), so there are total 10N different locks possible.

Let us say for a lock we define cost of converting the initial lock (all zeros) to this lock. For this, we have to rotate each dial to corresponding position in the lock. Cost of moving a single dial to value x takes xseconds.
eg. cost of moving to 123 is 1 + 2 + 3 = 6 and cost of moving to 99 is 9 + 9 is 18.

Now Devu has to hurry up to meet his girlfriend, So he has at most M seconds to spend, he wonders how many possible locks he can create such that when a lock is represented as a decimal number, it should be divisible by P. As answer could be large, print answer modulo 998244353.

Input

Only line of input will contain three integers N, P, MM respectively. Use of MM is defined in the output section.

Output

Print a single line containing MM + 1 integers, ith (0 based indexing) of them should represent the
answer for the problem with given N, P and M = i.

Example

Input:
8
0
BB
0
BG
0
BBGG
1
BGG
1
BGGB
1
BBBGG
2
BBGG
2
BGB

Output:
-1
0
1
1
1
3
1
0

Explanation

Note type of the first 3 test cases is 0. So c(i, j) = 1. Hence we just have to count minimum number of swaps needed.

Example case 1. There is no way to make sure that both the boys does not stand nearby. So answer is -1.

Example case 2. Arrangement is already valid. No swap is needed. So answer is 0.

Example case 3. Swap boy at position 1 with girl at position 2. After swap the arrangement will be BGBGwhich is a valid arrangement. So answer is 1.

Now type of the next 3 test cases is 1. So c(i, j) = |j − i|, that is, the absolute value of the difference betweeni and j.

Example case 4. Swap boy at position 0 with girl at position 1. After swap the arrangement will be GBGwhich is a valid arrangement. So answer is |1 - 0| = 1.

Example case 5. Swap boy at position 0 with girl at position 1. After swap the arrangement will be GBGBwhich is a valid arrangement. So answer is |1 - 0| = 1.

Example case 6. Swap boy at position 1 with girl at position 4. After swap the arrangement will beBGBGB which is a valid arrangement. So answer is |4 - 1| = 3.

Then type of the last 2 test cases is 2. So c(i, j) = (j − i)2

Example case 7. Swap boy at position 1 with girl at position 2. After swap the arrangement will be BGBGwhich is a valid arrangement. So answer is (2 - 1)2 = 1.

Example case 8. Arrangement is already valid. No swap is needed. So answer is 0.

http://www.codechef.com/problems/DEVCLASS

#include<iostream>  
#include<algorithm>  
#include<string>  
#include<map>  
#include<set>  
#include<cmath>  
#include<string.h>  
#include<stdlib.h>  
#include<cstdio>  
#define ll long long  
using namespace std; 
int main(){
	string s;
    int i,j,ans,type,l,g,b,e,t;
    scanf("%d",&t);
    while(t--){
		scanf("%d",&type);
   		cin>>s;
    	l=s.length();
    	g=0;b=0;ans=0;j=0;e=0; 
    	for(i=0;i<l;i++){
    		if(s[i]=='G')
    			g++;
    		else 
				b++;
    	}
    	if(type==0){   //0次方(不管abs(j-i)等于什么都为1) 
			if(g==b+1){
				for(i=0;i<l;i=i+2) //分类 
    				if(s[i]=='B')
    					ans++;
    		}
    		else if(b==g+1){
    			for(i=0;i<l;i=i+2) //分类 
    				if(s[i]=='G')
    					ans++;
    		}
    		else if(b==g){
   		 		e=0;
    			for(i=0;i<l;i=i+2){ //分类 
    				if(s[i]=='B')
    					ans++;
    				else
    					e++;
    			}
    			ans=min(ans,e);
    		}
    		else 
				ans=-1;
    	}
    	else{    //当type>0时都是一样处理(相邻交换,其实题目的type次方是没用的) 
    		if(g==b+1){
    			for(i=0;i<l;i=i+2){
    				while(s[j]!='G')
    					j++;
    				ans+=abs(i-j);
    				j++;
				}
    		}
    		else if(b==g+1){
    			for(i=0;i<l;i=i+2){
    				while(s[j]!='B')
    					j++;
					ans+=abs(i-j);
    				j++;
    			}
    		}
    		else if(b==g){
    			for(i=0;i<l;i=i+2){
    				while(s[j]!='B')
    					j++;
    				e+=abs(i-j);
    				j++;
    			}
				j=0;		
    			for(i=0;i<l;i=i+2){
    				while(s[j]!='G')
    					j++;
   	 				ans+=abs(i-j);
    				j++;
    			}
    			ans=min(ans,e);
    		}
    		else 
				ans=-1;
    	}
    	printf("%d\n",ans);
    }
    return 0;
}
/*
1
6
BBBGGG
*/ 


<think>我们正在处理的是为IMX6ULL移植桌面版Ubuntu系统。根据引用内容,我们注意到:引用[1]提到了tslib触摸库的路径设置,这提示我们在移植过程中可能需要处理触摸屏驱动。引用[2]提到了uboot移植的环境变量设置,以及交叉编译工具链的路径设置。由于IMX6ULL是ARMCortex-A7架构,而Ubuntu官方并没有为imx6ull提供官方的桌面版镜像,因此我们需要通过构建rootfs并配置桌面环境来实现。步骤概述:1.准备交叉编译环境和开发环境。2.获取并编译uboot(针对imx6ull)。3.获取并配置Linux内核(针对imx6ull)。4.构建根文件系统(使用UbuntuBase),并安装桌面环境(如LXDE、XFCE等轻量级桌面)。5.配置系统服务、驱动(包括触摸屏等)和网络。6.生成系统镜像并烧录。详细步骤:###1.环境准备安装必要的工具,设置交叉编译工具链。```bashsudoaptupdatesudoaptinstallgitmakegccg++bisonflexlibssl-devlibncurses-devu-boot-toolsdevice-tree-compilergcc-arm-linux-gnueabihf```下载并设置交叉编译工具链(如使用arm-linux-gnueabihf):```bash#假设我们将工具链安装在/opt目录下sudotarxvfgcc-arm-linux-gnueabihf-*.tar.xz-C/optexportPATH=/opt/gcc-arm-linux-gnueabihf/bin:$PATHexportARCH=armexportCROSS_COMPILE=arm-linux-gnueabihf-```###2.获取并编译U-Boot从官方或开发板供应商处获取U-Boot源码,并针对imx6ull进行配置和编译。```bashgitclonehttps://github.com/u-boot/u-boot.gitcdu-boot#切换到稳定版本,例如v2021.04gitcheckoutv2021.04-bimx6ull#配置为imx6ull的默认配置(具体配置根据开发板而定,例如mx6ull_14x14_evk)makemx6ull_14x14_evk_defconfigmake```编译完成后,得到u-boot.imx文件。###3.获取并编译Linux内核从官方或开发板供应商处获取Linux内核源码。```bashgitclonehttps://github.com/nxp-imx/linux-imx.gitcdlinux-imx#切换到合适的分支,例如imx_4.19.35_1.1.0gitcheckoutimx_4.19.35_1.1.0#配置内核makeimx_v7_defconfig#使用imx6ull的默认配置#如果需要,可以进一步配置内核(比如添加触摸屏驱动等)makemenuconfig#编译内核和设备树makezImagedtbs-j4```###4.构建根文件系统使用UbuntuBase构建根文件系统,并安装桌面环境。下载UbuntuBase20.04(注意选择armhf架构):```bashwgethttp://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/ubuntu-base-20.04.5-base-armhf.tar.gzmkdirubuntu_rootfssudotar-xpfubuntu-base-20.04.5-base-armhf.tar.gz-Cubuntu_rootfs```配置根文件系统,安装桌面环境(这里以LXDE为例):```bash#挂载必要的文件系统sudomount-tproc/procubuntu_rootfs/procsudomount-tsysfs/sysubuntu_rootfs/syssudomount-obind/devubuntu_rootfs/devsudomount-obind/dev/ptsubuntu_rootfs/dev/pts#进入chroot环境sudochrootubuntu_rootfs#在chroot环境中aptupdateaptinstalllanguage-pack-en-basesudosshnetwork-managerlxde-corelxdmxorg#安装LXDE桌面#设置root密码passwdroot#创建普通用户并设置密码adduserubuntu#设置主机名echo"imx6ull-ubuntu">/etc/hostname#退出chrootexit#卸载sudoumountubuntu_rootfs/procsudoumountubuntu_rootfs/syssudoumountubuntu_rootfs/dev/ptssudoumountubuntu_rootfs/dev```###5.配置系统####5.1配置触摸屏(如果需要)参考引用[1],如果需要触摸屏,可以移植tslib并配置。将tslib编译后,将库和配置文件放入根文件系统,并设置环境变量。####5.2配置显示确保内核中已经启用了正确的显示驱动(如mxsfb),并配置Xorg使用fbdev驱动。####5.3配置网络确保内核中网络驱动(如FEC)已启用,并在根文件系统中配置NetworkManager或netplan。###6.制作系统镜像创建一个空的镜像文件,分区并格式化,然后将根文件系统复制进去。```bash#创建镜像文件(假设4GB)ddif=/dev/zeroof=ubuntu-desktop.imgbs=1Mcount=4096sudopartedubuntu-desktop.img--script--mklabelmsdossudopartedubuntu-desktop.img--script--mkpartprimaryext41MiB4095MiB#挂载镜像并格式化sudolosetup-fPubuntu-desktop.imgsudomkfs.ext4/dev/loop0p1sudomount/dev/loop0p1/mnt#复制根文件系统sudocp-aubuntu_rootfs/*/mntsudoumount/mntsudolosetup-d/dev/loop0```###7.烧录镜像将U-Boot、内核、设备树和根文件系统镜像烧录到SD卡或eMMC中。具体步骤取决于开发板的启动方式。通常步骤:1.使用dd命令将U-Boot写入SD卡的开头:```bashsudoddif=u-boot.imxof=/dev/sdXbs=1kseek=1conv=fsync```2.将SD卡分为两个分区:第一个分区(FAT32)存放内核和设备树,第二个分区(ext4)作为根文件系统。3.复制内核(zImage)和设备树(*.dtb)到第一个分区。4.将根文件系统镜像解压或复制到第二个分区。###8.启动开发板连接串口,上电启动,进入系统后登录并配置桌面环境。注意事项:-由于IMX6ULL资源有限,建议使用轻量级桌面(如LXDE、XFCE)。-确保内核配置中包含了必要的驱动(显示、触摸、网络等)。-根据开发板的具体硬件调整设备树。§§相关问题§§1.如何为IMX6ULL的Ubuntu系统优化启动时间?2.IMX6ULL运行Ubuntu桌面版时如何降低内存占用?3.如何在IMX6ULL上配置双屏显示?4.如何为IMX6ULL的Ubuntu系统配置硬件加速?5.如何解决IMX6ULL运行Ubuntu桌面时的触摸屏校准问题?</think>### 在IMX6ULL上移植桌面版Ubuntu系统的详细步骤 #### 1. **准备交叉编译环境** ```bash # 安装基础工具 sudo apt update sudo apt install git make gcc g++ bison flex libssl-dev libncurses-dev u-boot-tools # 设置交叉编译工具链(以arm-buildroot-linux-gnueabihf为例) export ARCH=arm export CROSS_COMPILE=arm-buildroot-linux-gnueabihf- export PATH=$PATH:/your/toolchain/path/bin # 替换为实际路径[^2] ``` #### 2. **获取U-Boot源码并配置** ```bash git clone https://github.com/u-boot/u-boot.git cd u-boot make mx6ull_14x14_evk_defconfig # 根据开发板型号选择 make menuconfig # 配置DRAM参数、串口等 make ``` 生成文件:`u-boot.imx` #### 3. **编译Linux内核** ```bash git clone https://github.com/nxp-imx/linux-imx.git cd linux-imx git checkout imx_4.19.35_1.1.0 # 选择稳定分支 make imx_v7_defconfig # 配置桌面支持 make menuconfig # 启用关键选项: # Device Drivers → Graphics support → FB_MXS # Device Drivers → Input device support → Touchscreens # File systems → Enable POSIX ACLs # General setup → Desktop-oriented features make zImage dtbs -j$(nproc) ``` 生成文件:`arch/arm/boot/zImage` 和 `.dtb`设备树文件 #### 4. **构建根文件系统** ```bash # 下载Ubuntu Base wget http://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/ubuntu-base-20.04.5-base-armhf.tar.gz mkdir ubuntu_rootfs sudo tar -xpf ubuntu-base-20.04.5-base-armhf.tar.gz -C ubuntu_rootfs ``` #### 5. **安装桌面环境** ```bash # 挂载虚拟文件系统 sudo mount -t proc /proc ubuntu_rootfs/proc sudo mount -t sysfs /sys ubuntu_rootfs/sys sudo mount -o bind /dev ubuntu_rootfs/dev sudo mount -o bind /dev/pts ubuntu_rootfs/dev/pts # 进入chroot环境 sudo chroot ubuntu_rootfs # 在chroot中执行 apt update apt install --no-install-recommends ubuntu-desktop lxdm xorg network-manager passwd root # 设置root密码 adduser ubuntu # 创建普通用户 exit # 卸载 sudo umount ubuntu_rootfs/{proc,sys,dev/pts,dev} ``` #### 6. **配置触摸屏支持** ```bash # 编译tslib(参考引用[1]) cd ~ git clone https://github.com/libts/tslib.git cd tslib ./autogen.sh ./configure --host=arm-buildroot-linux-gnueabihf --prefix=/opt/tslib make sudo make install # 复制到根文件系统 sudo cp -r /opt/tslib ubuntu_rootfs/usr/local/ ``` #### 7. **创建系统镜像** ```bash # 创建4GB镜像 dd if=/dev/zero of=ubuntu-desktop.img bs=1M count=4096 sudo parted ubuntu-desktop.img mklabel msdos sudo parted ubuntu-desktop.img mkpart primary ext4 1MiB 100% # 格式化并挂载 sudo losetup -fP ubuntu-desktop.img sudo mkfs.ext4 /dev/loop0p1 sudo mount /dev/loop0p1 /mnt # 复制文件系统 sudo cp -a ubuntu_rootfs/* /mnt sudo umount /mnt ``` #### 8. **烧录到开发板** 1. 准备TF卡: ```bash sudo dd if=u-boot.imx of=/dev/sdX bs=1k seek=1 conv=fsync ``` 2. 分区: - 第1分区(FAT32):存放zImage和.dtb - 第2分区(ext4):存放根文件系统 3. 复制文件: ```bash sudo cp zImage /media/boot/ sudo cp *.dtb /media/boot/ sudo tar -xpf ubuntu-desktop.img -C /media/rootfs/ ``` #### 9. **首次启动配置** 1. 连接串口控制台 2. 登录后执行: ```bash systemctl enable lxdm # 启用桌面登录管理器 systemctl start lxdm ``` 3. 校准触摸屏(如需要): ```bash ts_calibrate ``` #### 10. **优化桌面体验** ```bash # 在开发板上执行 sudo apt install --no-install-recommends lxde-core # 轻量级桌面 sudo apt remove gnome-software ubuntu-software # 移除冗余组件 # 配置GPU加速(IMX6ULL支持OpenGL ES) sudo apt install imx-gpu-viv-tools ``` > **关键注意事项**: > 1. IMX6ULL内存有限(通常512MB-1GB),建议使用LXDE/LXQT轻量桌面 > 2. 确保内核配置中启用FB_MXS显示驱动 > 3. 触摸屏需在设备树中正确配置`&i2c1`节点 > 4. 首次启动时间较长(需生成SSH密钥等)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值