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的数阵,从左边一列到右边一列走过的数的和的最小.并输出路 ...
随机推荐
- 出现了npm ERR! cb() never called!错误
执行npm i 命令时,出现了npm ERR! cb() never called!错误 解决方案: 1.首先清除你的npm缓存: sudo npm cache clean -f 一般情况执行完后再试 ...
- conductor 系统任务
动态任务: 参数: dynamicTaskNameParam:来自任务输入的参数的名称,其值用于调度任务. 例如 如果参数的值为ABC,则调度的下一个任务类型为“ABC”. Example { &qu ...
- cmd 字符串截取
@echo off set "url=www.mzwu.com" echo 1.字符串截取 echo %url:~4,4% echo %url:~4,-4% echo %url:~ ...
- Jmeter响应数据为乱码的处理
jmeter新手,跟着教程,发现响应的数据为乱码,百度到两种方法: 方法一:在相应节点的下方,添加后置处理器-BeanShell PostProcessor 添加一句代码:prev.setDataEn ...
- mysq 数据库基本管理
命令表: 1.设置mysql数据库密码 mysqladmin -u root password 'new-password' 'new-password'为数据库密码. 2.登陆mysql数据库 my ...
- 数据库事务(Database Transaction)
事务(Transaction)是访问并可能更新数据库中各种数据项的一个程序执行单元(unit).事务由事务开始(begin transaction)和事务结束(commit transaction或 ...
- phpStudy1——PHP文件获取html提交的参数
示例代码: submit.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- mongo通信协议
先是一个包头: struct MsgHeader { int32 messageLength; // total message size, including this int32 requestI ...
- [leetcode]143. Reorder List重排链表
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You may not mod ...
- springMVC将处理的后的数据通过post方法传给页面时,可能会出现乱码问题,下面提出解决post乱码问题的方法
在web.xml中加入: <!-- 解决post乱码问题 --> <filter> <filter-name>CharacterEncodingFilter< ...