题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5063
BestCoder 13 1002。。题解写的有点迟啊。。周末打来了三场篮球赛,累成狗。。- -。。不过是时候加大训练强度了。。不能这么懒散了。。
问题意思:
给你一个初始的数组 1 - n。(值对应下标)
4种操作:
1.奇位置放前面,偶位置放后面。
2.前后调换。
3.每个值平方。
4.询问某个位置的值。。最多50次询问。
这个最多50次询问就的该问题的突破点。。对于每个询问,我们可以逆推回去,直接求该位置的值。。时间复杂度最多50 * m。。
比赛的时候,注意到这个50次询问了。。我们应该想到这种做法。。但是,我们没有从这里作为突破口去想算法。可能这就是我们的不成熟吧。。
后来听了学长的想法。。20 +分钟没有写出来程序。这又暴露了我们的一大缺点。。只能说,我们还有很大的成长空间。。
Code:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
#define INT long long
const int N = 1e5 + 5;
const INT mod = 1000000007;
int n, m, od[N], top = 0;
void Init()
{
top = 0;
}
int solve(int id)
{
int mid = (n + 1) / 2, cnt = 0;
for(int i = top - 1; i >= 0; i --){
if(od[i] == 1){
if(id > mid) id = (id - mid) * 2;
else id = id * 2 - 1;
}
if(od[i] == 2){
id = n + 1 - id;
}
if(od[i] == 3){
cnt ++;
}
}
INT ans = id;
for(int i = 1; i <= cnt ; i ++){
ans = ans * ans % mod;
}
return ans;
}
int main()
{
// freopen("1.txt", "r", stdin);
int T;
scanf("%d", &T);
while(T --){
scanf("%d %d", &n, &m);
Init();
char order[4];
int type;
for(int i = 1; i <= m; i ++){
scanf("%s %d", order, &type);
if(order[0] == 'O'){
od[top ++] = type;
}
else {
printf("%d\n", solve(type));
}
}
}
return 0;
}
对于这场BC,我只能吐槽太坑。。1002 竟然有人直接把题目上的代码粘上去提交过的。。。无力吐槽。。1003 竟然2层for循环,给过的。。
出题人这是要坑死hdu啊。。。最后hack时间弄的了了收场。。 - -。。