3 4 1 2 5
题意分析:
最开始给出一个排列,然后m次操作,把a移动到最前面,求最后的排列(stl+简单模拟。签到)
用map进行查重模拟一遍,不论某个数字改变多少次,怎么移动。从最后一步往前推。最后一步移动的肯定是在最前面。
然后依次在后面,往结果里存,用map检查该数字是否已经存入结果。
(这题因为我数组开小了,把1e5当做1w了,超时了好几次。我自己背锅。在时间允许的情况下,建议开动态的。避免我这样的问题,超时的原因吃好几次罚时才出来。)
#include
#include
#include
#include <math.h>
#include <string.h>
#include
#include
using namespace std;
#define ll long long
#define fo(i, a, b) for (int i = a; i < b; i++)
#define foo(i, a, b) for (int i = a; i > b; i–)
#define mst(a, b) memset(a, b, sizeof(a))
const int maxn = 100500;
int main()
{
// freopen(“in.txt”, “r”, stdin);
ios::sync_with_stdio(false);
map<int, int> a;
int q[maxn];
int qq[maxn];
int s[maxn];
int n, m;
while (cin >> n >> m)
{
map<int, int> a;
fo(i, 0, n)
{
cin >> q[i];
a[q[i]] = 0;
}
fo(i, 0, m)
{
cin >> qq[i];
}
foo(i, m - 1, -1)
{
if (a[qq[i]] != 1)
{
cout << qq[i] << ’ ';
a[qq[i]] = 1;
}
}
fo(i, 0, n)
{
if (a[q[i]] == 0)
{
cout << q[i] << ’ ';
a[q[i]] = 1;
}
}
mst(q, 0);
mst(qq, 0);
mst(s, 0);
}
}
1007 Windows Of CCPC(HDU6708)
Problem Description
In recent years, CCPC has developed rapidly and gained a large number of competitors .One contestant designed a design called CCPC Windows .The 1-st order CCPC window is shown in the figure:
And the 2-nd order CCPC window is shown in the figure:We can easily find that the window of CCPC of order k is generated by taking the window of CCPC of order k−1 as C of order k, and the result of inverting C/P in the window of CCPC of order k−1 as P of order k.
And now I have an order k ,please output k-order CCPC Windows , The CCPC window of order k is a 2k∗2k matrix.
input
The input file contains T test samples.(1<=T<=10)
The first line of input file is an integer T.
Then the T lines contains a positive integers k , (1≤k≤10)
Output
For each test case,you should output the answer .
Sample Input
3
1
2
3
Sample Output
CC
PC
CCCC
PCPC
PPCC
CPPC
CCCCCCCC
PCPCPCPC
PPCCPPCC
CPPCCPPC
PPPPCCCC
CPCPPCPC
CCPPPPCC
PCCPCPPC
题意分析:
规则 :最开始是4个字符左下角那个和其余3个不一样,用最初的可以拼成第2个,把第2个分成4部分,左下角和第一个相反,也就是P变为C,C变为P,其余相同。
思路:
按照上面的规则,看k的数据范围不是很大,就用打表的方式,因为每一个k的表都是建立在k-1的情况下。(题目虽然不难,但是理清怎么打好这个表,不容易,心累)
#include
#include
#include
#include <math.h>
#include <string.h>
using namespace std;
#define ll long long
#define fo(i, a, b) for (int i = a; i < b; i++)
#define foo(i, a, b) for (int i = a; i > b; i++)
#define mst(a, b) memset(a, b, sizeof(a))
const int maxn = 1050;
char ch[maxn][maxn];
int main()
{
//freopen(“in.txt”, “r”, stdin);
ios::sync_with_stdio(false);
mst(ch,0);
ch[0][0] = ch[0][1] = ch[1][1] = ‘C’;
ch[1][0] = ‘P’;
ll cnt = 1;
fo(k, 1, 10)
{
cnt = pow(2, k);
// cout << cnt << endl;
fo(i, cnt, 2 * cnt)//右下
fo(j, cnt, 2 * cnt)
ch[i][j] = ch[i - cnt][j - cnt];
fo(i, 0, cnt)//右上
fo(j, cnt, 2 * cnt)
ch[i][j] = ch[i][j - cnt];
fo(i, cnt, 2 * cnt)//左下倒置
fo(j, 0, cnt)
{
if (ch[i - cnt][j] == ‘C’)
ch[i][j] = ‘P’;
else
ch[i][j] = ‘C’;
}
}
int t;
cin >> t;
while (t–)
{
int k;
cin >> k;
最后
由于文档内容过多,为了避免影响到大家的阅读体验,在此只以截图展示部分内容
ch[i][j] = ch[i][j - cnt];
fo(i, cnt, 2 * cnt)//左下倒置
fo(j, 0, cnt)
{
if (ch[i - cnt][j] == ‘C’)
ch[i][j] = ‘P’;
else
ch[i][j] = ‘C’;
}
}
int t;
cin >> t;
while (t–)
{
int k;
cin >> k;
最后
[外链图片转存中…(img-5mRhOimo-1718161484410)]
[外链图片转存中…(img-LhXkZOBx-1718161484413)]
由于文档内容过多,为了避免影响到大家的阅读体验,在此只以截图展示部分内容