zoukankan      html  css  js  c++  java
  • STL的应用 multiset bitset next_permutation

    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[N];
    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;
    }

  • 相关阅读:
    Hexo 与 Git 集成
    Hexo Next 调优
    【翻译】Django Channels 官方文档 -- Tutorial
    配置环境是程序员的第一步 -- Xshell 6 免费版下载安装
    一步一步理解 python web 框架,才不会从入门到放弃 -- 简单登录页面
    配置环境是程序员的第一步 -- Windows 10 下 MySQL 安装
    一步一步理解 python web 框架,才不会从入门到放弃 -- 开始使用 Django
    一步一步理解 python web 框架,才不会从入门到放弃 -- 启程出发
    生成器
    迭代器
  • 原文地址:https://www.cnblogs.com/xiaoxian1369/p/2166610.html
Copyright © 2011-2022 走看看