【宽搜】ECNA 2015 D Rings (Codeforces GYM 100825)

本文介绍了一种使用宽度优先搜索(宽搜)算法来解决特定年轮问题的方法。在一个N*N的网格中,'T'代表年轮,'.'为空地,目标是确定每个'T'所属的年轮圈数。通过初始化所有点为无穷大,标记边缘和空地,再逐步扩展更新答案,最终输出每个格子对应的年轮数。

题目链接:

  http://codeforces.com/gym/100825

题目大意:

  给你一张N*N(N<=100)的图表示一个树桩,'T'为年轮,'.'为空,求每个'T'属于哪一圈年轮,空的为'.',如果最内圈<10,每个格子用两位表示,否则用三位,不足的用'.'补足。

题目思路:

  【宽搜】

  初始所有点标记为INF,先将图上所有的'.'标记为0,边缘如果有'T'记为1,并把'.'和边缘所有的点加入队列,接下来一个一个上下左右扩展并更新答案,没进队的进队。最后输出。

 

  1 //
  2 //by coolxxx
  3 //#include<bits/stdc++.h>
  4 #include<iostream>
  5 #include<algorithm>
  6 #include<string>
  7 #include<iomanip>
  8 #include<map>
  9 #include<stack>
 10 #include<queue>
 11 #include<set>
 12 #include<bitset>
 13 #include<memory.h>
 14 #include<time.h>
 15 #include<stdio.h>
 16 #include<stdlib.h>
 17 #include<string.h>
 18 //#include<stdbool.h>
 19 #include<math.h>
 20 #define min(a,b) ((a)<(b)?(a):(b))
 21 #define max(a,b) ((a)>(b)?(a):(b))
 22 #define abs(a) ((a)>0?(a):(-(a)))
 23 #define lowbit(a) (a&(-a))
 24 #define sqr(a) ((a)*(a))
 25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
 26 #define mem(a,b) memset(a,b,sizeof(a))
 27 #define eps (1e-10)
 28 #define J 10000
 29 #define mod 1000000007
 30 #define MAX 0x7f7f7f7f
 31 #define PI 3.14159265358979323
 32 #pragma comment(linker,"/STACK:1024000000,1024000000")
 33 #define N 104
 34 #define M 10004
 35 using namespace std;
 36 typedef long long LL;
 37 double anss;
 38 LL aans;
 39 int cas,cass;
 40 int n,m,lll,ans;
 41 int q[M][2];
 42 int a[N][N];
 43 bool u[N][N];
 44 char s[N][N];
 45 void spfa()
 46 {
 47     int x,y,l=0,r=cas;
 48     while(l!=r)
 49     {
 50         x=q[l=(l+1)%M][0],y=q[l][1];
 51         cass=max(cass,a[x][y]);
 52         u[x][y]=0;
 53         if(x+1<=n && a[x+1][y]>a[x][y]+1)
 54         {
 55             q[r=(r+1)%M][0]=x+1,q[r][1]=y;
 56             u[x+1][y]=1;
 57             a[x+1][y]=a[x][y]+1;
 58         }
 59         if(y+1<=m && a[x][y+1]>a[x][y]+1)
 60         {
 61             q[r=(r+1)%M][0]=x,q[r][1]=y+1;
 62             u[x][y+1]=1;
 63             a[x][y+1]=a[x][y]+1;
 64         }
 65         if(x-1>0 && a[x-1][y]>a[x][y]+1)
 66         {
 67             q[r=(r+1)%M][0]=x-1,q[r][1]=y;
 68             u[x-1][y]=1;
 69             a[x-1][y]=a[x][y]+1;
 70         }
 71         if(y-1>0 && a[x][y-1]>a[x][y]+1)
 72         {
 73             q[r=(r+1)%M][0]=x,q[r][1]=y-1;
 74             u[x][y-1]=1;
 75             a[x][y-1]=a[x][y]+1;
 76         }
 77     }
 78 }
 79 int main()
 80 {
 81     #ifndef ONLINE_JUDGE
 82 //    freopen("1.txt","r",stdin);
 83 //    freopen("2.txt","w",stdout);
 84     #endif
 85     int i,j,k;
 86     int x,y,z;
 87 //    init();
 88 //    for(scanf("%d",&cass);cass;cass--)
 89 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
 90 //    while(~scanf("%s",s))
 91     while(~scanf("%d",&n))
 92     {
 93         cas=0;cass=0;mem(u,0);mem(a,MAX);
 94         scanf("%d",&m);
 95         for(i=1;i<=n;i++)
 96         {
 97             scanf("%s",s[i]+1);
 98             for(j=1;j<=m;j++)
 99             {
100                 if(s[i][j]=='.')
101                 {
102                     q[++cas][0]=i,q[cas][1]=j;
103                     a[i][j]=0;
104                 }
105                 else if(i==1 || i==n || j==1 || j==m)
106                 {
107                     q[++cas][0]=i,q[cas][1]=j;
108                     a[i][j]=1;
109                 }
110             }
111         }
112         spfa();
113         /*
114         for(i=1;i<=n;i++)
115         {
116             for(j=1;j<=m;j++)
117                 printf("%d ",a[i][j]);
118             puts("");
119         }
120         */
121         if(cass<10)
122         {
123             for(i=1;i<=n;i++)
124             {
125                 for(j=1;j<=m;j++)
126                 {
127                     printf(".");
128                     if(a[i][j]==0)printf(".");
129                     else printf("%d",a[i][j]);
130                 }
131                 puts("");
132             }
133         }
134         else
135         {
136             for(i=1;i<=n;i++)
137             {
138                 for(j=1;j<=m;j++)
139                 {
140                     printf(".");
141                     if(a[i][j]==0)printf("..");
142                     else if(a[i][j]<10)printf(".%d",a[i][j]);
143                     else printf("%d",a[i][j]);
144                 }
145                 puts("");
146             }
147         }
148         
149     }
150     return 0;
151 }
152 /*
153 //
154 
155 //
156 */
View Code

 

转载于:https://www.cnblogs.com/Coolxxx/p/5850570.html

【电力系统】单机无穷大电力系统短路故障暂态稳定Simulink仿真(带说明文档)内容概要:本文档围绕“单机无穷大电力系统短路故障暂态稳定Simulink仿真”展开,提供了完整的仿真模型与说明文档,重点研究电力系统在发生短路故障后的暂态稳定性问题。通过Simulink搭建单机无穷大系统模型,模拟不同类型的短路故障(如三相短路),分析系统在故障期间及切除后的动态响应,包括发电机转子角度、转速、电压和功率等关键参数的变化,进而评估系统的暂态稳定能力。该仿真有助于理解电力系统稳定性机理,掌握暂态过程分析方法。; 适合人群:电气工程及相关专业的本科生、研究生,以及从事电力系统分析、运行与控制工作的科研人员和工程师。; 使用场景及目标:①学习电力系统暂态稳定的基本概念与分析方法;②掌握利用Simulink进行电力系统建模与仿真的技能;③研究短路故障对系统稳定性的影响及提高稳定性的措施(如故障清除时间优化);④辅助课程设计、毕业设计或科研项目中的系统仿真验证。; 阅读建议:建议结合电力系统稳定性理论知识进行学习,先理解仿真模型各模块的功能与参数设置,再运行仿真并仔细分析输出结果,尝试改变故障类型或系统参数以观察其对稳定性的影响,从而深化对暂态稳定问题的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值