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. 祝贺 Linux 25 岁:25 个关于 Linux 的惊人真相!【转载】

    作者:Javen Fang链接:https://zhuanlan.zhihu.com/p/22222383来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 25 年前的这 ...

  2. js直接打印pdf文件内容

    (1)需求:是网页上打开一个pdf文件,然后直接打开打印机,就是直接打印,不用用户再次点击打印按钮,这样用户体验好 (2)经历: 我在网上找了资料就是使用window.print(),但是这个只是打印 ...

  3. NSMutableAttributedString常用代码

    NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage imageNam ...

  4. python字符串

    字符串格式化 字符串格式化使用字符串格式化操作符%来实现:格式化字符串 % 值(字符串或者数字或者多个值的元组,字典) >>> format = "hello, %s. % ...

  5. 解决Windows Server2008R2中导入Excel不能使用Jet 4.0

    操作系统使用了Windows Server2008R2(Windows Server2008R2是64位系统,同时配置IIS7.0 原读取Excel文件代码为: string strConn = st ...

  6. Openfire3.9.3源代码导入eclipse中开发配置指南

    这篇文章向大家介绍一下,如何把openfire3.9.3源码导入eclipse中,编译并启动的详细过程. 首先得感谢这篇文章的作者,http://www.micmiu.com/opensource/o ...

  7. (转)完全用GNU/Linux工作 by 王珢

    完全用GNU/Linux工作 王珢      (看完这篇博文,非常喜欢王珢的这篇博客,也我坚定了学gnu/linux的决心,并努力去按照国外的计算机思维模式去学习编程提高自己.看完这篇文章令我热血沸腾 ...

  8. Spring中scope作用域

    scope作用域: 1.prototype 2.request      3.session 4.singleton 5.global session 1.prototype(多例) prototyp ...

  9. 完成对数据库的CRUD操作

    PS:查询相对复杂,要处理结果集,增删改则不用. package it.cast.jdbc; import java.sql.Connection; import java.sql.ResultSet ...

  10. 【iCore3应用开发平台】发布 iCore3 应用开发平台PID控制代码

    说明:1.本代码包包含FPGA和STM32F407两部分内容2.FPGA工程为出厂代码FPGA工程,版本为REV43.STM32F407为只含PID控制的ARM工程4.在使用风扇过程中,请勿将手伸入扇 ...