您的位置:首页 > 其它

STL的应用 multiset bitset next_permutation

2011-09-04 18:19 369 查看
multiset的应用 toj 2196 Nuanran's Idol II

/*
* toj2196.cpp
*
*  Created on: 2011-9-4
*      Author: bjfuwangzhu
*/

#include<iostream>
#include<stdio.h>
#include<set>
#include<algorithm>
#include<functional>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int n, i, num;
char c;
multiset<int, less<int> > mset;
while (scanf("%d", &n) != EOF,n) {
mset.clear();
for (i = 0; i < n; i++) {
scanf(" %c", &c);
if (c == 'B') {
scanf("%d", &num);
mset.insert(num);
} else {
printf("%d\n", *mset.begin());
mset.erase(mset.begin());
}
}
}
return 0;
}


multiset的应用 uestc1224 合并果子

/*
* uestc1224.cpp
*
*  Created on: 2011-9-4
*      Author: bjfuwangzhu
*/

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<set>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
multiset<int> mset;
int n, i, num, res, temp, numa, numb;
while (scanf("%d", &n) != EOF) {
mset.clear();
for (i = 0; i < n; i++) {
scanf("%d", &num);
mset.insert(num);
}
res = 0;
while (mset.size() != 1) {
numa = *mset.begin();
mset.erase(mset.begin());
numb = *mset.begin();
mset.erase(mset.begin());
temp = numa + numb;
res += temp;
mset.insert(temp);
}
printf("%d\n", res);
}
return 0;
}


bitset的应用 poj 2443 Set Operation

/*
* poj2443.cpp
*
*  Created on: 2011-9-4
*      Author: bjfuwangzhu
*/

#include<iostream>
#include<stdio.h>
#include<bitset>
using namespace std;
const int N = 1001;
const int nmax = 10001;
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int N, i, j, C, Q, num, nnum, k;
while (scanf("%d", &N) != EOF) {
bitset<nmax> bset
;
for (i = 0; i < N; i++) {
scanf("%d", &C);
for (j = 0; j < C; j++) {
scanf("%d", &num);
bset[i].set(num);
}
}
scanf("%d", &Q);
for (i = 0; i < Q; i++) {
scanf("%d %d", &num, &nnum);
for (j = 0, k = 1; j < N; j++) {
if (bset[j].test(num) && bset[j].test(nnum)) {
puts("Yes");
k = 0;
break;
}
}
if (k) {
puts("No");
}
}
}
return 0;
}


next_permutaion的用法 poj 1256 Anagram

/*
* poj1256.cpp
*
*  Created on: 2011-9-4
*      Author: bjfuwangzhu
*/

#include<algorithm>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
using namespace std;
const int nmax = 14;
int cmp(const char &a, const char &b) {
if (a == b || (b - a) == 32 || (b - a) == 32) {
return a < b;
}
return toupper(a) < toupper(b);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int T, i, clen;
char ch[nmax];
while (scanf("%d", &T) != EOF) {
for (i = 0; i < T; i++) {
scanf("%s", ch);
clen = strlen(ch);
sort(ch, ch + clen, cmp);
do {
puts(ch);
} while (next_permutation(ch, ch + clen, cmp));

}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: