2020 杭电第五场 Boring Game 6816(思维,折纸问题)
题目
http://acm.hdu.edu.cn/showproblem.php?pid=6816
题意
将n张纸铺在一起,同方向折叠k次,给定一个序列,为纸张从上到下,正反两面赋值,问展开纸张后,纸张从上到下,从左到右的值是多少?
题解
每次折叠的过程,都是将原序列上半部分翻转并合并到下半部分的左侧,模拟一下就可以了。
AC代码
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const int mod = (int)(1e9) + 7;
const int maxn = 1e6+5;
vector<int> v[maxn],t[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,k;
scanf("%d %d",&n,&k);
int m = 2*n;
for(int i=1; i<=k; i++)
{
m*=2;
}
for(int i=0; i<m; i++)
{
int a;
scanf("%d",&a);
v[i].clear();
v[i].push_back(a);
}
for(int i=0; i<k; i++)
{
for(int j=m/2-1,k=0; j>=0; j--,k++)
{
int size = v[j].size();
for(int z=size-1; z>=0; z--)
{
t[k].push_back(v[j][z]);
}
}
for(int j=m/2,k=0; j<m; j++,k++)
{
int size = v[j].size();
for(int z=0; z<size; z++)
{
t[k].push_back(v[j][z]);
}
}
for(int j=0; j<m/2; j++)
{
int size = t[j].size();
v[j].clear();
for(int z=0; z<size; z++)
{
v[j].push_back(t[j][z]);
}
t[j].clear();
}
m/=2;
}
for(int i=0; i<m; i++)
{
int size = v[i].size();
for(int j=0; j<size; j++)
{
if(i!=0||j!=0)
printf(" ");
printf("%d",v[i][j]);
}
}
puts("");
}
return 0;
}