HDU 4399 Query multiset 解法
来源:互联网 发布:csdn修改博客域名 编辑:程序博客网 时间:2024/04/28 02:08
网上看到的multiset解法。就是把每个不同的位置放到multiset里面,然后查询的时候找到比他大的第一个数 即lower_bound(); 更新的是在集合里面插入和删除就行了 。
不知道为什么用的multiset ,位置是没有重复的啊 然后换成 set后也可以AC。
1 #include <cstdio> 2 #include <vector> 3 #include <algorithm> 4 #include <cstring> 5 #include <map> 6 #include <queue> 7 #include <set> 8 9 using namespace std;10 11 #define SI(a) scanf("%d", &(a))12 #define SS(a) scanf("%s", (a))13 #define SC(a) scanf("%c", &(a));14 #define Max(a, b) (a > b ? a : b)15 #define Min(a, b) (a < b ? a : b)16 17 const int maxn = 1000000 + 50;18 19 set<int> S;20 set<int>::iterator it;21 char s[3][maxn];22 int n;23 24 int hx[maxn], hy[maxn];25 26 27 int main() {28 int T;29 30 SI(T);31 for(int kase=1; kase<=T; kase++) {32 S.clear();33 SS(s[1]);34 SS(s[2]);35 36 printf("Case %d:\n", kase);37 n = Min(strlen(s[1]), strlen(s[2]));38 for(int i=0; i<n; i++) if(s[1][i] != s[2][i])39 S.insert(i);40 S.insert(n);41 42 int q;43 SI(q);44 while(q--) {45 int type, a, i;46 char c;47 SI(type);48 if(type == 1) {49 SI(a); SI(i);50 getchar(); SC(c);51 52 if(s[a][i] != s[3-a][i] && c == s[3-a][i])53 S.erase(i);54 if(s[a][i] == s[3-a][i] && c != s[3-a][i])55 S.insert(i);56 s[a][i] = c;57 58 } else {59 SI(i);60 it = S.lower_bound(i);61 printf("%d\n", *it - i);62 }63 64 }65 }66 67 return 0;68 }
- HDU 4399 Query multiset 解法
- hdu 4339 Query (set解法)
- HDU 2275 multiset
- hdu 4302 STL multiset
- 【map】【multiset】hdu 4022
- hdu 4022 multiset
- hdu 5875 Function(multiset)
- hdu 2275 multiset
- hdu 6180 贪心+multiset
- HDU 4022 Boming (Map , multiset)
- HDU 5289 单调队列,multiset
- hdu 6180 Schedule (multiset)
- hdu 6180 Schedule(贪心 multiset)
- Twelves Monkeys (multiset解法 141 - ZOJ Monthly, July 2015 - H)
- multiset
- multiset
- multiset
- multiset
- arcgis 10 server 和desktop 安装注意总结
- SqlServer 事务与锁
- 教育办公系统的OpenSessionInView,通用翻页的实现
- test
- UVA 11520 Fill the Square
- HDU 4399 Query multiset 解法
- Ubuntu Eclipse 提示颜色
- LA 3902 UVA 1267 - Network
- linux 防火墙
- LA 3177 UVA 1335 - Beijing Guards
- UVA 11039 - Building designing
- UVA 1339 - Ancient Cipher
- Linux RedHat下添加自启动脚本的几种方式
- 将博客搬至CSDN