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\ ...
随机推荐
- Servlet初始化与异步支持
Shared libraries(共享库) / runtimes pluggability(运行时插件能力) 1.Servlet容器启动会扫描,当前应用里面每一个jar包的 ServletContai ...
- MEF编程模型
Contract由Contract name和Contract type组成,Contract两个参数可以省略可以implicit也可以explicit,implicit时name和type会自动推断 ...
- Android 微博sdk接入授权指南
1:首先在微博官方注册账号,官方地址是:http://open.weibo.com/然后创建一个新应用. 2:当然我们得现在自己电脑上创建一个应用,例如包名叫com.winorout.weib ...
- MongoDB安装使用教程
参考菜鸟教程:http://www.runoob.com/mongodb/mongodb-tutorial.html
- win8使用教程
win8如何关机 http://product.pconline.com.cn/itbk/software/win8/1305/3301394.html shutdown.exe -s -t 00 W ...
- 【sqli-labs】 less29 GET- Error based -Impidence mismatch -Having a WAF in front of web application (GET型基于错误的带有WAF注入)
这关有点意思,有一点需要事先注意,这关玩的是login.php而不是默认的index.php 再注入之前需要先了解一下HPP(HTTP Parameter Pollution),详情参照这篇 http ...
- 使用Java生成具有安全哈希的QR码
这是关于如何在Java中使用salt生成QR代码和安全散列字符串的分步教程. 首先,需要一个可以处理QR码的库,我决定使用Zebra Crossing("ZXing")库,因为它简 ...
- .Net Core 中X509Certificate2 私钥保存为 pem 的方法
在自己签发CA证书和颁发X509证书时,私钥通过下面的方法保存为PEM 相关代码可以已经提交在了 https://github.com/q2g/q2g-helper-pem-nuget/pull/13 ...
- 25-Ubuntu-文件和目录命令-其他命令-重定向
重定向 Linux允许将命令执行结果重定向到一个文件. 将本应显示到终端上的内容输出或追加到指定文件中. 重定向命令 含义 > 表示输出,会覆盖原有文件. >> 表示追加,会将内容追 ...
- 【udacity】机器学习-支持向量机
Evernote Export 支持向量机(Support Vector Machine) 不适定问题不止一个决策边界 要找一个决策边界,不仅能将训练集很好的划分,而且提升模型的泛化能力 支持向量机直 ...