CodeForces - 405B(Domino Effect)

本文解析了一道名为DominoEffect的编程题,通过模拟过程找出最终保持直立状态的多米诺骨牌数量。文章提供了完整的代码实现,并对关键步骤进行了说明。

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

B. Domino Effect
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".

Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.

After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.

Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!

Input

The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to

  • "L", if the i-th domino has been pushed to the left;
  • "R", if the i-th domino has been pushed to the right;
  • ".", if the i-th domino has not been pushed.

It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".

Output

Output a single integer, the number of the dominoes that remain vertical at the end of the process.

Examples
input
14
.L.R...LR..L..
output
4
input
5
R....
output
0
input
1
.
output
1
Note

The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.

In the second example case, all pieces fall down since the first piece topples all the other pieces.

In the last example case, a single piece has not been pushed in either direction.

题目连接:点击打开链接

题意:就是一个卡诺牌,给你个顺序,然后判断下有几个竖着的,一个模拟题,L代表往左倒,R代表往右倒,‘.’就代表普通的,直接模拟走就行了;

#include<stdio.h>
#include<iostream> 
#include <algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<set>
#define LL long long
#define INF 0x3f3f3f3f
#define s(n) scanf("%d",&n)
using namespace std; 
int main()
{
	int n,i;
	char st[3100];
	while(scanf("%d",&n)!=EOF)
	{
		scanf("%s",&st);
		int ans1=0;//记录到L或者R之间有多少个.
		int ans=0;//记录总共有多少个可以竖着 
		int flag=0;//碰到一个往右的就改成1 
		for(int i=0;i<n;i++)
		{
			if(st[i]=='.')
				ans1++;
			if(st[i]=='L')//往左边歪倒  所以过来这一路的所有的.都清空 
			{
				if(flag)//说明右边有一个配对的 
				{
					if(ans1%2)//中间的做柱子 
						ans=ans+1;
				} 
				ans1=0;//判断完了
				flag=0;
			} 
			if(st[i]=='R')//开始储存当前的点 
			{
				ans=ans+ans1;
				ans1=0;
				flag=1;
			}
		}
		if(flag)//最后剩下一个往右的 所有往右记录的.都清空 
			ans1=0;
		printf("%d\n",ans+ans1);
	}
	return 0;
} 

模拟题目就是需要一个思维,如果卡思维就完犊子了~


一、综合实战—使用极轴追踪方式绘制信号灯 实战目标:利用对象捕捉追踪和极轴追踪功能创建信号灯图形 技术要点:结合两种追踪方式实现精确绘图,适用于工程制图中需要精确定位的场景 1. 切换至AutoCAD 操作步骤: 启动AutoCAD 2016软件 打开随书光盘中的素材文件 确认工作空间为"草图与注释"模式 2. 绘图设置 1)草图设置对话框 打开方式:通过"工具→绘图设置"菜单命令 功能定位:该对话框包含捕捉、追踪等核心绘图辅助功能设置 2)对象捕捉设置 关键配置: 启用对象捕捉(F3快捷键) 启用对象捕捉追踪(F11快捷键) 勾选端点、中心、圆心、象限点等常用捕捉模式 追踪原理:命令执行时悬停光标可显示追踪矢量,再次悬停可停止追踪 3)极轴追踪设置 参数设置: 启用极轴追踪功能 设置角度增量为45度 确认后退出对话框 3. 绘制信号灯 1)绘制圆形 执行命令:"绘图→圆→圆心、半径"命令 绘制过程: 使用对象捕捉追踪定位矩形中心作为圆心 输入半径值30并按Enter确认 通过象限点捕捉确保圆形位置准确 2)绘制直线 操作要点: 选择"绘图→直线"命令 捕捉矩形上边中点作为起点 捕捉圆的上象限点作为终点 按Enter结束当前直线命令 重复技巧: 按Enter可重复最近使用的直线命令 通过圆心捕捉和极轴追踪绘制放射状直线 最终形成完整的信号灯指示图案 3)完成绘制 验证要点: 检查所有直线是否准确连接圆心和象限点 确认极轴追踪的45度增量是否体现 保存绘图文件(快捷键Ctrl+S)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值