hdu 5063 操作逆推+mul每次要*2%(modo - 1)
http://acm.hdu.edu.cn/showproblem.php?pid=5063
只有50个询问,50个操作逆推回去即可,注意mul每次要*2%(modo
- 1)因为是指数!
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL; int n,m;
const double pi = acos ( -1.0 ) ;
const LL modo = 1000000007;
int op[100005],op_n;
LL ans[55];
int ans_n;
LL quick_pow(LL a,int b)
{
LL c = 1;
while(b){
if(b&1)
c = (c*a)%modo;
b>>=1;
a = (a*a)%modo;
}
return c;
}
LL gao(LL x)
{
int mul = 1;
for(int i = op_n - 1;i >= 0;--i){
if(op[i] == 1){
// 1,3,5->1,2,3
// 2,4,6->4,5,6 // 1,3,5,7->1,2,3,4
// 2,4,6->5,6,7
if(x <= (n+1)/2)
x = x*2 - 1;
else
x = (x - (n+1)/2)<<1;
}
else if(op[i] == 2){
x = n + 1 - x;
}
else{
mul = (mul*2)%(modo-1);
}
}
return quick_pow(x,mul);
}
void work()
{
op_n = ans_n = 0;
LL x;
char q[2];
while(m--){
scanf("%s%I64d",q,&x);
if(q[0] == 'O'){
op[op_n++] = (int)x;
}else{
ans[ans_n++] = gao(x);
}
}
for(int i = 0;i < ans_n;++i)
printf("%I64d\n",ans[i]);
return;
}
int main () {
int T;
RD(T);
while(T--){
RD2(n,m);
work();
}
return 0 ;
}
hdu 5063 操作逆推+mul每次要*2%(modo - 1)的更多相关文章
- HDU 5844 LCM Walk(数学逆推)
http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意: 现在有坐标(x,y),设它们的最小公倍数为k,接下来可以移动到(x+k,y)或者(x,y+k).现 ...
- hdu 3853 LOOPS (概率dp 逆推求期望)
题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Tota ...
- HDU 1176-免费馅饼(DP_逆推)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU 5063 Operation the Sequence(仔细审题)
http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
- HDU 5063 Operation the Sequence(暴力 数学)
题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...
- Codeforces Round #499 (Div. 2) C.FLY 数学推导_逆推
本题应该是可以使用实数二分的,不过笔者一直未调出来,而且发现了一种更为优美的解法,那就是逆推. 首先,不难猜到在最优解中当飞船回到 111 号节点时油量一定为 000, 这就意味着减少的油量等于减少之 ...
- Natas11 Writeup(常见编码、异或逆推、修改cookie)
Natas11: 页面提示cookie被异或加密保护,查看源码,发现了一个预定义参数和三个函数. //预定义参数,猜测将showpassword设置为yes即可得到密码. $defaultdata = ...
- UVA116Unidirectional TSP(DP+逆推)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18206 题意:M*N的数阵,从左边一列到右边一列走过的数的和的最小.并输出路 ...
随机推荐
- 机房servlet过滤器
1.源代码 loginform.html <html> <head> <title>使用过滤器改变请求编码</title> <meta http- ...
- git cherry-pick基本使用
git cherry-pick可以选择某一分支中的一个或几个commit来进行操作--commit 使用场景: 稳定版本分支1与开发版本分支2,不能直接把两个分支合并,否则会导致版本混乱,要将分支2中 ...
- 一行转多行 及多行转一行的 hive语句
注意 :|,: 是特殊符号,要用 "\\|", "\\;"来表示. 一行转多行 usertags 里面有很多项,每项之间以逗号分隔 create t ...
- Baidu URL的部分参数
[Baidu URL的部分参数] 1.Baidu Form表单如下: 2.部分参数解析 wd 查询关键字,就是你要搜索的内容. bs 上一次搜索的词或者内容: rn 搜索结果页每页显示的数目,默认 ...
- springmvc后台生成验证码
url http://localhost:8080/admin/getCode http://localhost:8080/admin/checkCode controller package com ...
- The Unique MST
The Unique MST http://poj.org/problem?id=1679 Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- leetcdoe 175. Combine Two Tables
给定两个表,一个是人,一个是地址,要求查询所有人,可以没有地址. select a.FirstName, a.LastName, b.City, b.State from Person as a le ...
- [leetcode]318. Maximum Product of Word Lengths单词长度最大乘积
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
- 【SQL模板】三.插入/更新 数据模板TSQL
---Name: 插入/更新 数据模板.sql ---Purpose: 用于更新 数据库中 历史数据 或 插入 新数据 的脚本模板 ---Author: xx ---Time: 2015-12-18 ...
- SQL 将一个字段内用逗号分隔的内容分成多条记录
转自:http://www.cnblogs.com/zfanlong1314/archive/2013/01/14/2859848.html --> 测试数据 if not object_id( ...