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. spring-表达式语言-SpEL【转】

    Spring表达式语言(Spring Expression Language)简称:SpEL 课程概要: Spring表达式语言的入门介绍 Spring表达式语言的操作范围 Spring表达式语言的运 ...

  2. System.Windows.Application.Current.Dispatcher.BeginInvoke

    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>                        ...

  3. XVI Open Cup named after E.V. Pankratiev. GP of SPB

    A. Bubbles 枚举两个点,求出垂直平分线与$x$轴的交点,答案=交点数+1. 时间复杂度$O(n^2\log n)$. #include<cstdio> #include<a ...

  4. sketchup

    1. clean start 1. 删除中间人物 2. windows---style 3. Windows---Model Info 2. 好的建模习惯 1. 正面朝镜头 View---ToolBa ...

  5. Excel大批量导入数据到SQLServer数据库-万条只用1秒

    private string ExcelToStudent() { /*---*/ var preStr = DateTime.Now.ToString("yyyyMMddHHmmssfff ...

  6. Android入门(十):界面的布局方式及其实际应用

    关于Android界面布局,网上已经有了很多非常不错的学习资料,在这里我也不班门弄斧了,推荐两篇我认为写的不错的教程,然后再重点讲一下几种布局方式的实际应用. 教程链接:①http://www.cnb ...

  7. 【BZOJ】3427: Poi2013 Bytecomputer

    题意: 给定一个长度为\(n\)的\(\{-1, 0, 1\}\)组成的序列,你可以进行\(x_i=x_i+x_{i-1}\)这样的操作,求最少操作次数使其变成不降序列.(\(n \le 100000 ...

  8. MongoDB-权限配置

    启动 Mongo\bin\mongo.exe1.添加>use admin #切换到MongoDB数据库的用户表>db.addUser("Name","Pass ...

  9. js快速排序

    function sort(arr){ if(arr.length<=1){ return arr; } var num = Math.floor(arr.length/2); var numV ...

  10. go语言学习笔记

    Go语言学习基本类型Bool 取值范围:true,false (不可以用数字代替)Int/uint 根据平台可能为32或64位int8/uint8 长度:1字节 取值范围-128~127/0~255b ...