标签:
题目抽象:给你一个字符串,给你一些操作,每个操作将子串[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