PAT_A1140#Look-and-say Sequence

博客围绕PAT A1140外观数列问题展开,介绍了外观数列的定义,即后一个数是对前一个数的描述。给出了输入规格,包含数字d和正整数N,输出规格为打印第N个外观数列。还提及解题关键是简单模拟,并给出代码来源。

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

Source:

PAT A1140 Look-and-say Sequence (20 分)

Description:

Look-and-say sequence is a sequence of integers as the following:

D, D1, D111, D113, D11231, D112213111, ...

where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number. For example, the 2nd number means that there is one D in the 1st number, and hence it is D1; the 2nd number consists of one D (corresponding to D1) and one 1 (corresponding to 11), therefore the 3rd number is D111; or since the 4th number is D113, it consists of one D, two 1's, and one 3, so the next number must be D11231. This definition works for D = 1 as well. Now you are supposed to calculate the Nth number in a look-and-say sequence of a given digit D.

Input Specification:

Each input file contains one test case, which gives D (in [0, 9]) and a positive integer N (≤ 40), separated by a space.

Output Specification:

Print in a line the Nth number in a look-and-say sequence of D.

Sample Input:

1 8

Sample Output:

1123123111

Keys:

  • 简单模拟

Attention:

  • 这种小题有时候还挺头疼的-,-

Code:

 1 /*
 2 Data: 2019-05-24 10:44:34
 3 Problem: PAT_A1140#Look-and-say Sequence
 4 AC: 44:30
 5 
 6 题目大意:
 7 观察并说出响应的序列;
 8 比如给出第一个数字D,第二个数字为D1(D有1个)
 9 第三个数字为D111(D有1个,1有1个);
10 第四个数字为D113(D有1个,1有3个);
11 以此类推....
12 输入:
13 初始数字D,和轮次N
14 输出:
15 第N轮响应的序列
16 */
17 
18 #include<cstdio>
19 #include<string>
20 #include<iostream>
21 using namespace std;
22 
23 int main()
24 {
25 #ifdef    ONLINE_JUDGE
26 #else
27     freopen("Test.txt", "r", stdin);
28 #endif
29 
30     int n;
31     string s;
32     cin >> s >> n;
33     for(int i=1; i<n; i++)
34     {
35         string ans="";
36         int pt=0;
37         while(pt < s.size())
38         {
39             int cnt=1;
40             ans+=s[pt];
41             while(pt+1<s.size()&&s[pt]==s[pt+1]){
42                 cnt++;pt++;
43             }
44             ans+=('0'+cnt);
45             pt++;
46         }
47         s=ans;
48     }
49     cout << s;
50 
51     return 0;
52 }

 

转载于:https://www.cnblogs.com/blue-lin/p/10917168.html

内容概要:本文探讨了在MATLAB/SimuLink环境中进行三相STATCOM(静态同步补偿器)无功补偿的技术方法及其仿真过程。首先介绍了STATCOM作为无功功率补偿装置的工作原理,即通过调节交流电压的幅值和相位来实现对无功功率的有效管理。接着详细描述了在MATLAB/SimuLink平台下构建三相STATCOM仿真模型的具体步骤,包括创建新模型、添加电源和负载、搭建主电路、加入控制模块以及完成整个电路的连接。然后阐述了如何通过对STATCOM输出电压和电流的精确调控达到无功补偿的目的,并展示了具体的仿真结果分析方法,如读取仿真数据、提取关键参数、绘制无功功率变化曲线等。最后指出,这种技术可以显著提升电力系统的稳定性与电能质量,展望了STATCOM在未来的发展潜力。 适合人群:电气工程专业学生、从事电力系统相关工作的技术人员、希望深入了解无功补偿技术的研究人员。 使用场景及目标:适用于想要掌握MATLAB/SimuLink软件操作技能的人群,特别是那些专注于电力电子领域的从业者;旨在帮助他们学会建立复杂的电力系统仿真模型,以便更好地理解STATCOM的工作机制,进而优化实际项目中的无功补偿方案。 其他说明:文中提供的实例代码可以帮助读者直观地了解如何从零开始构建一个完整的三相STATCOM仿真环境,并通过图形化的方式展示无功补偿的效果,便于进一步的学习与研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值