http://acm.hdu.edu.cn/showproblem.php?pid=5063

题目大意:

  题目意思还是比较简单。所以就不多少了。注意这句话,对解题有帮助。

  Type4: Q i query current value of a[i], this operator will have at most
50
.

解题思路:

  因为给定n和m都是100000,我们每一步都做具体的操作,时间将是O(n*m),肯定超时。最开始的时候

我怎么想都不知道怎么解决。以为是线段树。比赛完了以后,看了解题报告(http://bestcoder.hdu.edu.cn/

我吓到了,原来是自己没有仔细分析题目的给的条件。Q i query current value of a[i], this operator will

have at most 50.询问Q i最多50次。

  所以我们把每部的操作都记下来,每次Q i的时候,就反推回去。自己可以推推。

  假设当前位置为x,我们要求操作之前的位置。

  fun1:

  n = (n + 1) / 2;

   x = x <= n / 2 ? (2 * x - 1) : ((x - n) * 2);

  fun2:

  x = n + 1 - x;

  fun3:

  我们用flag记录平方次数。

  这样处理的时间复杂度O(50*n)

AC代码:

 #include<cstdio>

 #define MAXN 100000+10
#define MOD 1000000007 int op[MAXN], count; int fun_1(int x, int n){
n = (n + ) >> ;
if(x <= n){
return (x << ) - ;
}
return (x - n) << ;
} int fun_2(int x, int n){
return n + - x;
} void solve(int x, int n){
int flag = ;//记录平方次数 for(int i = count - ; i >= ; --i){//逆推回去 找出初始位置
if(op[i] == ){
x = fun_1(x, n);
}else if(op[i] == ){
x = fun_2(x, n);
}else{
flag++;
}
} __int64 num = x;
for( ; flag > ; --flag){
num = num * num % MOD;
}
printf("%I64d\n", num);
} int main(){
char str[];
int t, n, m, i, num; scanf("%d", &t);
while(t--){
scanf("%d%d", &n, &m);
for(count = i = ; i < m; ++i){ scanf("%s%d", str, &num);
if(str[] == 'O'){
op[count++] = num;//记录执行fun1、fun2、fun3
}else{
solve(num, n);
}
}
}
return ;
}

HDU 5063 Operation the Sequence(仔细审题)的更多相关文章

  1. HDU 5063 Operation the Sequence(暴力)

    HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...

  2. hdu 5063 Operation the Sequence(Bestcoder Round #13)

    Operation the Sequence                                                                     Time Limi ...

  3. hdu 5063 Operation the Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=5063 思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值. #include ...

  4. HDU 5063 Operation the Sequence(暴力 数学)

    题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...

  5. HDOJ 5063 Operation the Sequence

    注意到查询次数不超过50次,那么能够从查询位置逆回去操作,就能够发现它在最初序列的位置,再逆回去就可以求得当前查询的值,对于一组数据复杂度约为O(50*n). Operation the Sequen ...

  6. HDU 5783 Divide the Sequence (训练题002 B)

    Description Alice has a sequence A, She wants to split A into as much as possible continuous subsequ ...

  7. HDU 5288——OO’s Sequence——————【技巧题】

    OO’s Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  8. 【HDOJ】5063 Operation the Sequence

    #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 100005 #defin ...

  9. HDU - 5036 Operation the Sequence

    Problem Description You have an array consisting of n integers: a1=1,a2=2,a3=3,-,an=n. Then give you ...

随机推荐

  1. pandas 学习(1): pandas 数据结构之Series

    1. Series Series 是一个类数组的数据结构,同时带有标签(lable)或者说索引(index). 1.1 下边生成一个最简单的Series对象,因为没有给Series指定索引,所以此时会 ...

  2. Only Link: Inheritance and the prototype chain

    Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_cha ...

  3. SPOJ : DIVCNT2 - Counting Divisors (square)

    设 \[f(n)=\sum_{d|n}\mu^2(d)\] 则 \[\begin{eqnarray*}\sigma_0(n^2)&=&\sum_{d|n}f(d)\\ans&= ...

  4. ACM: SCU 4440 Rectangle - 暴力

     SCU 4440 Rectangle Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practic ...

  5. vue.js慢速入门(1)

    0.MVVM 什么是MVVM?就是Model-View-ViewModel. ViewModel是Vue.js的核心,它是一个Vue实例. 不太懂也没关系,慢慢就懂了. 1.基础示例 代码: < ...

  6. Unity3D设计原则

    原则1:单一职责 原则2:里氏替换原则(子类扩展但不改变父类功能) 原则3:依赖倒置原则 原则4:接口隔离原则 原则5:迪米特法则(最少知道原则) 原则6:开闭原则 原则1:单一职责原则 说到单一职责 ...

  7. C#中(int)、int.Parse()、int.TryParse()和Convert.ToInt32()的区别

    转自:http://www.cnblogs.com/leolis/p/3968943.html 在编程过程中,数据转换是经常要用到的,C#中数据转换的方法很多,拿将目标对象转换为 整型(int)来讲, ...

  8. bzoj2243: [SDOI2011]染色--线段树+树链剖分

    此题代码量较大..但是打起来很爽 原本不用lca做一直wa不知道为什么.. 后来改lca重打了一遍= =结果一遍就AC了orz 题目比较裸,也挺容易打,主要是因为思路可以比较清晰 另:加读入优化比没加 ...

  9. ORA-12519: TNS:no appropriate service handler found 解决(转)

    可能是数据库上当前的连接数目已经超过了它能够处理的最大值. select count(*) from v$process --当前的连接数 select value from v$parameter  ...

  10. convert与int.parse int

    1,convert :适合将object 转换 int:简单数据转换 int.parse:将string类型转换为int 2,convert:对于空值返回0 不会报异常 int.parse:将会抛出异 ...