码迷,mamicode.com
首页 > 其他好文 > 详细

Problem 1577 - K-th character 小思维题 逆向查找

时间:2015-05-11 21:36:43      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

                      Problem 1577 - K-th character

题目抽象:给你一个字符串,给你一些操作,每个操作将子串[L,R]反转。所有操作完成后,询问一些位置上的字符。

思路:只需逆向查找就行了。 这样的小思维有时候却想不到。         

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 const int MS=1e5+5;
 8 const int SIZE=1005;
 9 
10 char str[MS];
11 int x[SIZE],y[SIZE];
12 int n,m,q;
13 
14 int main()
15 {
16     while(scanf("%d%d%d",&n,&m,&q)!=EOF)
17     {
18         scanf("%s",str);
19         for(int i=0;i<m;i++)
20             scanf("%d%d",&x[i],&y[i]);
21         int t;
22         for(int i=0;i<q;i++)
23         {
24             scanf("%d",&t);
25             for(int j=m-1;j>=0;j--)
26             {
27                 if(t>=x[j]&&t<=y[j])
28                 {
29                     t=x[j]+y[j]-t;
30                 }
31             }
32             printf("%c",str[t-1]);
33         }
34         printf("\n");
35     }
36     return 0;
37 }

 

Problem 1577 - K-th character 小思维题 逆向查找

标签:

原文地址:http://www.cnblogs.com/hutaishi/p/4495609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!