HDU 5063 Operation the Sequence(仔细审题)
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(仔细审题)的更多相关文章
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
- hdu 5063 Operation the Sequence(Bestcoder Round #13)
Operation the Sequence Time Limi ...
- hdu 5063 Operation the Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5063 思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值. #include ...
- HDU 5063 Operation the Sequence(暴力 数学)
题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...
- HDOJ 5063 Operation the Sequence
注意到查询次数不超过50次,那么能够从查询位置逆回去操作,就能够发现它在最初序列的位置,再逆回去就可以求得当前查询的值,对于一组数据复杂度约为O(50*n). Operation the Sequen ...
- 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 ...
- HDU 5288——OO’s Sequence——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 【HDOJ】5063 Operation the Sequence
#include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 100005 #defin ...
- 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 ...
随机推荐
- Linux Mysql 忘记用户密码
1.停止mysql 服务 /etc/init.d/mysqld stop 2.启动mysql服务跳过授权表并在后台运行 /etc/init.d/mysqld start -u root --sk ...
- Leetcode Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 不想说作用域scope,因为是scopeTree,
ps:本文前面大部分是错的,后边大部分也是错的,搞混了不要怪我................... 这篇文章讲述了一个悲伤的故事,从一个似似而非的概念一步一步到错误的理解,最后勉强正确的过程 其实我 ...
- HTML5新增的标签
结构性元素<header><footer>定义页眉(与<head>不一样)和页脚 <section>定义section<article> 定 ...
- 问题(the question)
I want to know: 1. 软件开发最主要的目的 是什么? 2. 软件开发是否同样需要模,和架构? 3.软件开发与其他程序的需求分析是否相似,有什么不同之处? 4.软件开发最常用的计算机语言 ...
- Javascript初学篇章_3(注释/if/switch)
五.javascript的注释 // 单行注释 /* …*/ 多行注释 注:多行注释不能互相嵌套 六.程序流程控制 一.条件语句 if 语法: if(condition) statements1 el ...
- 基于jquery上的轻量级《数据模板解析》插件
1.先上一个栗子. <!doctype html> <html lang="en"> <head> <meta charset=" ...
- Switch语句的case穿透
Switch语句的case穿透 一 switch语句几点说明: 1. case后面只能是常量,不能是变量,而且,多个case后面的值不能出现相同的. 2.case后面表达式可以接受: 基本数据类型,b ...
- PHP 实现“贴吧神兽”验证码
最早看到 “贴吧神兽” 验证码是在百度贴吧,吧主防止挖坟贴,放出了究极神兽验证码 例如: 地址:http://tieba.baidu.com/p/3320323440 可以用 PHP + JavaSc ...
- SpringBoot list查询方法
SpringBoot中根据不同查询条件,获取list列表.@Componentpublic class QuerySpecifications {} (1)根据商户,查询商品全部列表 public S ...