哪些网站的简历做的比较好,商标设计用什么软件,商务网站推广目标有哪些,柏乡企业做网站cf1523A. Game of Life
题意#xff1a;
包含n个元素的数组#xff0c;数值为1或0#xff0c;如果一个元素为0#xff0c;并且其周围正好只有一个为1的元素#xff0c;那么下一刻本元素也会变成1. 给你一个数值#xff0c;问你m次时刻后数组的状态
题解#xff1a;
…cf1523A. Game of Life
题意
包含n个元素的数组数值为1或0如果一个元素为0并且其周围正好只有一个为1的元素那么下一刻本元素也会变成1. 给你一个数值问你m次时刻后数组的状态
题解
注意101情况下中间的0不能变成1因为题目说的是周围只有一个1如果有两个1就不行了。对于每一位i我们用j表示偏移量相当于左移j位右移j位看i-j位和ij位是否满足是由一个是1如果满足就变成1
代码
// Problem: A. Game of Life
// Contest: Codeforces - Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 Div. 2)
// URL: https://codeforces.com/contest/1523/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//#include bits/stdc.h
#include unordered_map
#define debug(a, b) printf(%s %d\n, a, b);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pairint, int PII;
clock_t startTime, endTime;
//Fe~Jozky
const ll INF_ll 1e18;
const int INF_int 0x3f3f3f3f;
template typename T inline void read(T x)
{T f 1;x 0;char ch getchar();while (0 isdigit(ch)) {if (ch -)f -1;ch getchar();}while (0 ! isdigit(ch))x (x 1) (x 3) ch - 0, ch getchar();x* f;
}
template typename T inline void write(T x)
{if (x 0) {x ~(x - 1);putchar(-);}if (x 9)write(x / 10);putchar(x % 10 0);
}
void rd_test()
{
#ifdef ONLINE_JUDGE
#elsestartTime clock();freopen(in.txt, r, stdin);
#endif
}
void Time_test()
{
#ifdef ONLINE_JUDGE
#elseendTime clock();printf(\nRun Time:%lfs\n, (double)(endTime - startTime) / CLOCKS_PER_SEC);
#endif
}
int main()
{//rd_test();string a, b;long long n, m, i, t, j;cin t;for (t t; t 0; t--) {cin n m a;b a;for (i 0; i n; i) {j 0;while ((i - j 0 || i j n) (i - j 0 || a[i - j] 0) (i j n || a[i j] 0))j;if (i - j 0) {if (a[i - j] 1 (i j n || a[i j] 0) j m) //在此步剔除101的情况{b[i] 1;}}if (i j n) {if (a[i j] 1 (i - j 0 || a[i - j] 0) j m) {b[i] 1;}}}cout b endl;}return 0;//Time_test();
}