Codeforces Round #601 (Div. 2)D(蛇形模拟)

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 vector<char>ans;
 5 char a[107][107];
 6 int main(){
 7     ios::sync_with_stdio(false);
 8     cin.tie(NULL);
 9     cout.tie(NULL);
10     for(int i=‘0‘;i<=‘9‘;++i)
11         ans.emplace_back(i);
12     for(int i=‘A‘;i<=‘Z‘;++i)
13         ans.emplace_back(i);
14     for(int i=‘a‘;i<=‘z‘;++i)
15         ans.emplace_back(i);
16     int t;
17     cin>>t;
18     while(t--){
19         int r,c,k;
20         cin>>r>>c>>k;
21         int cnt=0;
22         for(int i=1;i<=r;++i)
23             for(int j=1;j<=c;++j){
24                 cin>>a[i][j];
25                 if(a[i][j]==‘R‘)
26                     ++cnt;
27             }
28         int x=cnt/k,y=cnt%k;
29         int pt=0;
30         int tx=x;
31         if(y)
32             ++tx,--y;
33         for(int i=1;i<=r;++i){
34             if(i&1){
35                 for(int j=1;j<=c;++j){
36                     if(a[i][j]==‘R‘)
37                         --tx,--cnt;
38                     a[i][j]=ans[pt];
39                     if(!cnt)
40                         continue;
41                     if(!tx){
42                         ++pt;
43                         if(y)
44                             tx=x+1,--y;
45                         else
46                             tx=x;
47                     }
48                 }
49             }
50             else{
51                 for(int j=c;j>=1;--j){
52                     if(a[i][j]==‘R‘)
53                         --tx,--cnt;
54                     a[i][j]=ans[pt];
55                     if(!cnt)
56                         continue;
57                     if(!tx){
58                         ++pt;
59                         if(y)
60                             tx=x+1,--y;
61                         else
62                             tx=x;
63                     }
64                 }
65             }
66         }
67         for(int i=1;i<=r;++i){
68             for(int j=1;j<=c;++j)
69                 cout<<a[i][j];
70             cout<<"\n";
71         }
72     }
73     return 0;
74 }

原文地址:https://www.cnblogs.com/ldudxy/p/11939198.html

时间: 2024-08-01 15:46:20

Codeforces Round #601 (Div. 2)D(蛇形模拟)的相关文章

Codeforces Round #259 (Div. 2) (简单模拟实现题)

题目链接:http://codeforces.com/problemset/problem/454/A A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine

Codeforces Round #327 (Div. 2) B. Rebranding 模拟

B. Rebranding The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the

Codeforces Round #552 (Div. 3)-1154E-Two Teams-(模拟+双指针)

http://codeforces.com/contest/1154/problem/E 解题: 举例n=10,k=1 1,2,10,4,7,6,9,8,5,3 第一次,1队先挑2,10,4这三个人 1,2,10,4,7,6,9,8,5,3 第二次,2队挑6,9,8三个人 1,2,10,4,7,6,9,8,5,3 第三次,1队挑1,7,5三个人 1,2,10,4,7,6,9,8,5,3 第四次,2队挑3一个人 1,2,10,4,7,6,9,8,5,3 显然需要实现的有两点 (1)挑完后的“连接”

Codeforces Round #601 (Div. 2)E(寻找质因子,DP)

先分解质因数,对于当前a[i],假设当前的质因数为x,这个位置要满足能被k整除,有两个可能,要么是它向后一个转移x%k个,要么是后一个向它转移k-x%k个. 对于每一个a[i]满足后,因为只会对下一个位置产生影响,所以下一个位置a[i+1]算上a[i]产生的影响,之后又是一个新的子问题(禁止套娃). 对于每一个质因数x,对所有所有位置i求min(a[i],x-a[i])的和,取所有质因子i的求和的最小值作为答案. 1 #define HAVE_STRUCT_TIMESPEC 2 #include

Codeforces Round #610 (Div. 2)E(模拟,DFS)

先找到一条多边形的边,然后循环一圈输出多边形上的点.把每个三角形看作一个结点,以两个三角形之间公用边为边建立一张图,DFS输出叶子结点,则得到先切后切的顺序. 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 vector<int>v[100007]; 5 bool vis[100007]; 6 void dfs(int x){ 7 vis[x]=1; 8 for(au

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模拟 枚举

Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模拟  枚举 题意 一个红绿灯 按逆时针方向一次给出各个路口的左转,直行,右转,以及行人车道让你判断,汽车是否有可能撞到行人 注意 当前车道的左转有可能撞到别的车道的行人的 题解 一大堆特判 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring&g

Codeforces Round #259 (Div. 2) B. Little Pony and Sort by Shift(模拟)

题目链接:Codeforces Round #259 (Div. 2)  B. Little Pony and Sort by Shift 求给出的序列最少移动多少次成为非下降序列.移动方式:只能将最后一个元素移到第一个位置 即:a1,?a2,?...,?an?→?an,?a1,?a2,?...,?an?-?1. 从后前开始搜非下降的子序列,然后前面的子序列接在其后面,最后判断变化后的序列是否是非下降序列即可. AC代码: #include<stdio.h> #include<strin

模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

题目传送门 1 /* 2 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 3 题目倒是很长:) 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <algorithm> 9 #include <cstring> 10 using namespace std; 11 12 const int MAXN = 2e5 + 10; 13