zoukankan      html  css  js  c++  java
  • hdu 3 * problem

    hdu 6182

    给出 $n$ 

    求 $sum_{i = 1} ^ {infty} (i * i <= n)$

    暴力枚举

    hdu 6186

    给出 $n$ 个数

    $1e6$ 次询问,每次询问这 $n$ 个数不包含第 $p$ 个时的 $xor, or and$ 的值

    前缀 + 后缀处理

    hdu 6188

    给出 $n$ 个数$A_i$

    $a.$ 每两个相同的数对答案的贡献为 $1$

    $b.$ 每相连的 $3$ 个数对答案的贡献为 $1$

    每个数只能使用一次

    最大化答案

    贪心:取 $i,i - 1, i - 2$ 这个顺子的时候先把 $i - 1,i - 2$ 的对子取掉,取完再取 $i$ 的对子

    Code

    6182

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    
    long long Ksm(long long a, long long b) {
        long long ret = 1;
        while(b) {
            if(b & 1) ret = ret * a;
            a = a * a;
            b >>= 1;
        }
        return ret;
    }
    
    #define LL long long
    
    LL num[20];
    
    int main() {
        for(LL i = 1; i <= 15; i ++) num[i] = Ksm(i, i);
        LL a;
        while(cin >> a) {
            if(a == 0) {
                cout << 0 << "
    ";
                continue;
            }
            int i;
            for(i = 1; i <= 15; i ++) {
                if(num[i] > a) break;
            }
            cout << i - 1 << "
    ";
        }
        
        return 0;
    } 

    6186

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    
    #define LL long long
    
    const int N = 1e5 + 10;
    int A[N];
    int And[N], Or[N], Xor[N];
    int And2[N], Or2[N], Xor2[N];
    int n, m;
    
    #define gc getchar()
    
    inline int read() {
        int x = 0; char c = gc;
        while(c < '0' || c > '9') c = gc;
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc;
        return x;
    }
    
    int main() {
        while(scanf("%d%d", &n, &m) == 2) {
            And[0] = And2[n + 1] = ~ 0;
            Xor[0] = Xor2[n + 1] = 0;
            Or[0] = Or2[n + 1] = 0;
            for(int i = 1; i <= n; i ++) A[i] = read(); //cin >> A[i];
            for(int i = 1; i <= n; i ++) And[i] = (And[i - 1] & A[i]);
            for(int i = 1; i <= n; i ++) Or[i] = (Or[i - 1] | A[i]);
            for(int i = 1; i <= n; i ++) Xor[i] = (Xor[i - 1] ^ A[i]);
            for(int i = n; i >= 1; i --) And2[i] = (And2[i + 1] & A[i]);
            for(int i = n; i >= 1; i --) Or2[i] = (Or2[i + 1] | A[i]);
            for(int i = n; i >= 1; i --) Xor2[i] = (Xor2[i + 1] ^ A[i]);
            for(; m; m --) {
                int p = read();
                printf("%d ", (And[p - 1] & And2[p + 1]));
                printf("%d ", (Or[p - 1] | Or2[p + 1]));
                printf("%d
    ", (Xor[p - 1] ^ Xor2[p + 1]));
            }
        }
        
        return 0;
    } 

    6188

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    
    const int N = 1e6 + 10;
    
    #define gc getchar()
    inline int read() {
        int x = 0; char c = gc;
        while(c < '0' || c > '9') c = gc;
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc;
        return x;
    }
    
    int n;
    int T[N];
    
    int main() {
        while(~ scanf("%d", &n)) {
            memset(T, 0, sizeof T);
            int Answer = 0;
            for(int i = 1; i <= n; i ++) T[read()] ++;
            for(int i = 1; i <= (int)1e6; i ++) {
                if(i >= 3 && T[i] && T[i - 1] && T[i - 2]) {
                    Answer ++;
                    T[i] --, T[i - 1] --, T[i - 2] --;
                }
                Answer += (T[i] >> 1);
                T[i] %= 2;
            }
            printf("%d
    ", Answer);
        }
        
        
        return 0;
    }
  • 相关阅读:
    TextBox 只有下划线
    can't find web control library(web控件库)
    DropDownListSalesAC”有一个无效 SelectedValue,因为它不在项目列表中。
    IDE、SATA、SCSI、SAS、FC、SSD 硬盘类型
    如何打印1px表格
    CSS控制打印 分页
    Virtual Server could not open its emulated Ethernet switch driver. To fix this problem, reenable the Virtual Server Emulated Et
    Xml中SelectSingleNode方法中的xpath用法
    热带水果莫入冰箱?水果存放冰箱大法
    探索Asp.net的Postback机制
  • 原文地址:https://www.cnblogs.com/shandongs1/p/9525707.html
Copyright © 2011-2022 走看看