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\ ...
随机推荐
- 跳出双重for循环的案例__________跳出了,则不再执行标签ok下的for循环代码
ok: for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { System.out.print("*" ...
- Tomcat 程序无问题的情况下页面打开变慢的原因
看看这写日志的频率就知道我有多闲了.. 前言: 其实关于tomcat,遇到过很多关于“慢”的问题,比如启动慢,比如页面打开慢, 以前太忙也太懒,不愿意花时间分析原因,现在终于肯静下来找原因 环境是ec ...
- 在Winform中怎么实现图片的旋转,比如说实现仪表盘功能,看代码吧,看太不懂的欢迎问
; //旋转的角度 //Timer定时器 private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; ...
- Spring 错误日志
13:19:14.437 [main] DEBUG org.springframework.boot.context.logging.ClasspathLoggingApplicationListen ...
- I2C controller core之Bit controller(03)
FPGA proven, AISC proven, I2C controller core from OpenCores http://opencores.org/project,i2c Bit-co ...
- 人脸Pose检测:ASM、AAM、CLM总结
人脸的Pose检测可以使用基于位置约束的特征点的方法.人脸特征点定位的目的是在人脸检测的基础上,进一步确定脸部特征点(眼睛.眉毛.鼻子.嘴巴.脸部外轮廓)的位置.定位算法的基本思路是:人脸的纹理特征和 ...
- js截取字符串测试
function gget() { $.ajax({ type: "GET", url: "index", data: { U: '1234', P: '000 ...
- Jquery常见操作多选框/复选框/checkbox
1.判断checkbox是否为选中状态: if($("#searchNews").attr("checked")=="checked") { ...
- Qt中采用多线程实现Socket编程
Socket通常也称作"套接字",应用程序通常通过"套接字"向网络发出请求或者应答网络请求. 本文介绍的是Qt中采用多线程Socket编程,由于工作的需要,开始 ...
- vue中引入json数据,不用本地请求
1.我的项目结构,需要在Daily.vue中引入daily.js中的json数据 2.把json数据放入一个js文件中,用exports导出,vscode的json格式太严格了,很多数据,调了一个多小 ...