HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence
把操作存下来。因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置。输出就可以
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long ll;
const int N = 100005;
const ll MOD = 1000000007; int t, n, m, c;
ll a[N];
int op[N], on;
char str[3]; ll pow_mod(ll x, ll k) {
ll ans = 1;
while (k) {
if (k&1) ans = ans * x % MOD;
x = x * x % MOD;
k >>= 1;
}
return ans;
} ll solve(int c) {
ll mul = 1;
for (int i = on - 1; i >= 0; i--) {
if (op[i] == 1) {
if (c > (n + 1) / 2) c = (c - (n + 1) / 2) * 2;
else c = (c - 1) * 2 + 1;
} else if (op[i] == 2) c = n - c + 1;
else mul = mul * 2 % (MOD - 1);
}
return pow_mod(a[c], mul);
} int main() {
scanf("%d", &t);
while (t--) {
on = 0;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) a[i] = i;
while (m--) {
scanf("%s%d", str, &c);
if (str[0] == 'O') op[on++] = c;
else printf("%lld\n", solve(c));
}
}
return 0;
}
HDU 5063 Operation the Sequence(暴力)的更多相关文章
- hdu 5063 Operation the Sequence(Bestcoder Round #13)
Operation the Sequence Time Limi ...
- HDU 5063 Operation the Sequence(暴力 数学)
题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...
- HDU 5063 Operation the Sequence(仔细审题)
http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...
- hdu 5063 Operation the Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5063 思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值. #include ...
- HDOJ 5063 Operation the Sequence
注意到查询次数不超过50次,那么能够从查询位置逆回去操作,就能够发现它在最初序列的位置,再逆回去就可以求得当前查询的值,对于一组数据复杂度约为O(50*n). Operation the Sequen ...
- HDU 5273 Dylans loves sequence 暴力递推
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...
- 【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 ...
- HDU 6274 Master of Sequence (暴力+下整除)
题意 两个1e5的数组a,b,定义\(S(t)=\left \lfloor \frac{t-b_i}{a_i} \right \rfloor\),有三个操作 1 x y:将\(a[x]\)变为\(y\ ...
随机推荐
- EasyUI 编写实体类树状选择器
<%@ page contentType="text/html;charset=UTF-8"%> <%@ include file="/WEB-INF/ ...
- SQLServer XXX IS NOT NULL
SQLServer中不能使用像Java和C#中的 XXX!=null 这种用法, 使用上面的用法返回值永远是False False False 正确的用法应该是--> XXXis not ...
- HTML+CSS(11)
n CSS背景属性 Background-color:背景色. Background-image:背景图片地址.如:background-image:url(images/bg.gif;) Back ...
- poj1101 the game 广搜
题目大意: 类似于连连看,问从起点到终点最少需要几条线段. 规则: 1.允许出界. 2.空格的地方才能走. 分析: 题目做下来发现没有卡时间,所以主要还是靠思路.也就是说不用考虑离线算法.直接以每个起 ...
- 【SQL】字符型函数
1. ASCII ASCII(American Standard Code for Information Interchange,美国信息交换标准代码)是基于拉丁字母的一套电脑编码系统. 1) 返回 ...
- java的优先队列注意事项
在C++语言中,使用优先队列,直接构建一个lambda表达式,使用一个匿名函数指针.java比较函数的返回值不是bool型,只能是整型. 内部对应的C++匿名函数: // 匿名Comparator实现 ...
- VTK嵌入MFC同步显示
使用VTK嵌入MFC,实现四视图更新,机制和细节参考原文. 原文链接:http://blog.csdn.net/www_doling_net/article/details/8939115 原文代码: ...
- http 请求头示例
POST /3-0/app/account/item HTTP/1.1 Host 10.100.138.32:8046 Content-Type application/json Accept-E ...
- sql server 查询时间 格式化输出
use test select * from vote insert into vote (contents) values(GETDATE()) insert into vote (contents ...
- eas之怎么设置单据保存或者提交完不跳到下个新增页面
this.chkMenuItemSubmitAndAddNew.setSelected(false);