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 << "\n";
            continue;
        }
        int i;
        for(i = 1; i <= 15; i ++) {
            if(num[i] > a) break;
        }
        cout << i - 1 << "\n";
    }
    
    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\n", (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\n", Answer);
    }
    
    
    return 0;
}

 

posted @ 2018-08-23 19:16  xayata  阅读(126)  评论(0编辑  收藏  举报