签到 2016.7.26

1、团队程序设计天体赛-练习集-L2-005 集合相似度

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
int N;
int num[60][10010];

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H
    scanf("%d", &N);
    for (int i = 1; i <= N; ++i) {
        scanf("%d", &num[i][0]);
        for (int j = 1; j <= num[i][0]; ++j) {
            scanf("%d", &num[i][j]);
        }
    }
    int K;
    scanf("%d", &K);
    int a, b;
    for (int i = 0; i < K; ++i) {
        scanf("%d%d", &a, &b);
        int ans1 = 0, ans2 = 0;
        sort(num[a]+1, num[a]+1+num[a][0]);
        sort(num[b]+1, num[b]+1+num[b][0]);
        for (int j = 1; j <= num[a][0]; ++j) {
            if (j > 1 && num[a][j] == num[a][j-1]) {
                continue;
            }
            int t = lower_bound(num[b]+1, num[b]+1+num[b][0], num[a][j]) - num[b];
            if (num[b][t] == num[a][j]) {
                ++ans1;
            } else {
                ++ans2;
            }
        }
        for (int j = 1; j <= num[b][0]; ++j) {
            if (j > 1 && num[b][j] == num[b][j-1]) {
                continue;
            }
            ++ans2;
        }
        double ans = ans1 * 100.0 / ans2;
        printf("%.2f%%\n", ans);
    }
    return 0;
}

2、Codeforces_689A Mike and Cellphone

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
int n;
char s[20];
int num[20];

bool Judge(int add);

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H
    scanf("%d", &n);
    scanf("%s", s);
    for (int i = 0; i < n; ++i) {
        num[i] = s[i] - '0';
    }
    bool flag = false;
    for (int i = -4; i <= 4; ++i) {
        if (i != 0 && Judge(i)) {
            flag = true;
            break;
        }
    }
    if (flag) {
        printf("NO\n");
    } else {
        printf("YES\n");
    }
    return 0;
}

bool Judge(int add)
{
    for (int i = 0; i < n; ++i) {
        switch (num[i]) {
            case 0: if (add > -2) return false; break;
            case 1: if (add != 1 && add != 4 && add != 3) return false; break;
            case 2: if (add != -1 && add != 1 && add != 2 && add != 3 && add != 4) return false; break;
            case 3: if (add != -1 && add != 2 && add != 3) return false; break;
            case 4: if (add != -3 && add != -2 && add != 1 && add != 3 && add != 4) return false; break;
            case 6: if (add != -4 && add != -3 && add != -1 && add != 2 && add != 3) return false; break;
            case 7: if (add != -3 && add != -2 && add != 1 && add != 4) return false; break;
            case 8: if (add >= 2 && add != 3) return false; break;
            case 9: if (add != -4 && add != -3 && add != -1 && add != 2) return false; break;
            default: break;
        }
    }
    return true;
}

3、十六进制转十进制

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H
    int T;
    int t;
    scanf("%d", &T);
    while (T--) {
        scanf("%x", &t);
        printf("%d\n", t);
    }
    return 0;
}

4、字符环

描述

有两个由字符构成的环。请写一个程序,计算这两个字符环上最长连续公共字符串的长度。例如,字符串“ABCEFAGADEGKABUVKLM”的首尾连在一起,构成一个环;字符串“MADJKLUVKL”的首尾连在一起,构成一个另一个环;“UVKLMA”是这两个环的一个连续公共字符串。

输入
一行,包含两个字符串,分别对应一个字符环。这两个字符串之间用单个空格分开。字符串长度不超过255,且不包含空格等空白符。
输出
输出一个整数,表示这两个字符环上最长公共字符串的长度。
样例输入
ABCEFAGADEGKABUVKLM MADJKLUVKL
样例输出
6

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int maxn = 255 + 10;
char a[maxn], b[maxn];

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H
    scanf("%s%s", a, b);
    int Max = 0;
    int len_a = strlen(a), len_b = strlen(b);
    int Min_len = min(len_a, len_b);
    for (int i = 0; i < len_a; ++i) {
        for (int j = 0; j < len_b; ++j) {
            if (a[i] == b[j]) {
                int Count = 0;
                int i_t = i, j_t = j;
                while (a[i_t] == b[j_t] && Count < Min_len) {
                    ++Count;
                    i_t = (i_t+1)%len_a; j_t = (j_t+1)%len_b;
                }
                if (Count > Max) {
                    Max = Count;
                }
            }
        }
    }
    printf("%d\n", Max);
    return 0;
}

5、Codeforces 261A Maxim and Discounts

题意:

超市打折,有M种方案,对于每种方案给出一个Qi,你要选出Qi个推车里的商品,放到一个篮子中

然后可以从推车剩余的两种里选出0-2个东西免费,要保证免费的物品比篮子中最便宜的便宜

现在要购买N个商品,每个商品的价格为Ai,问在可以使用无限次推车、折扣的前提下,最小花费

解题思路:

简单贪心

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int maxn = 1e5 + 10;
int m, n;
int q[maxn], a[maxn];

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H
    scanf("%d", &m);
    int Min = INF;
    for (int i = 0; i < m; ++i) {
        scanf("%d", &q[i]);
        if (q[i] < Min) {
            Min = q[i];
        }
    }
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    sort(a, a+n);
    int ans = 0;
    int Count = 0;
    for (int i = n-1; i >= 0; --i) {
        if (Count == Min) {
            Count = 0;
            i -= 2;
        }
        ++Count;
        ans += a[i];
    }
    printf("%d\n", ans);
    return 0;
}


6、HDU 5744 Keep On Movin

题意:

有 n 种字符,每种字符的个数 为 ai,用所有的字符组成若干个回文串,令每种组法的长度为组成的若干个回文串中最短的回文串的长度

要找到一种长度最长的组法

解题思路:

统计无法进行配对的字符的个数和可以配对的对数,然后将这些可以配对的均分给这些无法配对的字符

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int maxn = 1e5 + 10;
int a[maxn];
int n;

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H
    int T;
    scanf("%d", &T);
    while (T--) {
        int _1_num = 0;
        scanf("%d", &n);
        int Even_sum = 0;
        for (int i = 0; i < n; ++i) {
            scanf("%d", &a[i]);
            if (a[i] & 1) {
                ++_1_num;
                Even_sum += a[i] - 1;
            } else {
                Even_sum += a[i];
            }
        }
        if (_1_num == 0) {
            printf("%d\n", Even_sum);
        } else {
            int t = Even_sum / 2 / _1_num;
            printf("%d\n", 1+t*2);
        }
    }
    return 0;
}


7、HDU 5742 It's All In The Mind

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int maxn = 1e2 + 10;
int a[maxn];
bool vis[maxn];

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H
    int T;
    scanf("%d", &T);
    while (T--) {
        int n, m;
        scanf("%d%d", &n, &m);
        memset(vis, false, sizeof(vis));
        memset(a, 0, sizeof(a));
        int x, y;
        while (m--) {
            scanf("%d%d", &x, &y);
            a[x] = y;
            vis[x] = true;
        }
        for (int i = n-1; i >= 3; --i) {
            if (!vis[i]) {
                a[i] = a[i+1];
            }
        }
        if (!vis[1] && !vis[2]) {
            a[1] = a[2] = 100;
        } else if (!vis[1]) {
            a[1] = 100;
        } else if (!vis[2]) {
            a[2] = a[1];
        }
        int sum = 0;
        for (int i = 1; i <= n; ++i) {
            sum += a[i];
        }
        int t = a[1] + a[2];
        int g = __gcd(sum, t);
        printf("%d/%d\n", t/g, sum/g);
    }
    return 0;
}

8、切割回文


描述

    阿福最近对回文串产生了非常浓厚的兴趣。

    如果一个字符串从左往右看和从右往左看完全相同的话,那么就认为这个串是一个回文串。例如,“abcaacba”是一个回文串,“abcaaba”则不是一个回文串。

    阿福现在强迫症发作,看到什么字符串都想要把它变成回文的。阿福可以通过切割字符串,使得切割完之后得到的子串都是回文的。

    现在阿福想知道他最少切割多少次就可以达到目的。例如,对于字符串“abaacca”,最少切割一次,就可以得到“aba”和“acca”这两个回文子串。
输入
    输入的第一行是一个整数 T (T <= 20) ,表示一共有 T 组数据。
    接下来的 T 行,每一行都包含了一个长度不超过的 1000 的字符串,且字符串只包含了小写字母。
输出
    对于每组数据,输出一行。该行包含一个整数,表示阿福最少切割的次数,使得切割完得到的子串都是回文的。
样例输入

    3
    abaacca
    abcd
    abcba

样例输出

    1
    3
    0

提示
    对于第一组样例,阿福最少切割 1 次,将原串切割为“aba”和“acca”两个回文子串。
    对于第二组样例,阿福最少切割 3 次,将原串切割为“a”、“b”、“c”、“d”这四个回文子串。
    对于第三组样例,阿福不需要切割,原串本身就是一个回文串。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int maxn = 1e3 + 10;
char s[maxn];

bool IsMirror(int low, int high);

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H
    int T;
    scanf("%d", &T);
    while (T--) {
        scanf("%s", s);
        int len = strlen(s);
        int Count = 0;
        for (int i = 0, t; i < len; i = t) {
            t = i;
            for (int j = len-1; j >= i+1; --j) {
                if (s[j] == s[i] && IsMirror(i, j)) {
                    t = j;
                    break;
                }
            }
            if (t != len-1) {
                ++Count;
            }
            ++t;
        }
        printf("%d\n", Count);
    }
    return 0;
}

bool IsMirror(int low, int high)
{
    while (low < high) {
        if (s[low] != s[high]) {
            return false;
        }
        ++low, --high;
    }
    return true;
}

9、HDU 5747 Aaronson

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
ll n, m;
ll num[40];

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H
    int T;
    num[0] = 1;
    num[1] = 2;
    for (int i = 2; i < 40; ++i) {
        num[i] = num[i-1] << 1;
    }
    scanf("%d", &T);
    while (T--) {
        scanf("%I64d%I64d", &n, &m);
        if (m > 32) {
            m = 32;
        }
        int Count = 0;
        for (int i = m; i >= 0; --i) {
            while (n >= num[i]) {
                n -= num[i];
                ++Count;
            }
        }
        printf("%d\n", Count);
    }
    return 0;
}

10、HDU 5752 Sqrt Bo

刚开始还以为边界为 2^(2*5),然而事实是 2^(2^5),为什么会有窝这么菜的人。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> Pair;

const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
char s[1000];

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H
    while (scanf("%s", s) != EOF) {
        int len = strlen(s);
        if (strcmp(s, "0") == 0 || len > 10) {
            printf("TAT\n");
        } else {
            int Count = 1;
            ll ans = 0;
            for (int i = 0; i < len; ++i) {
                ans = ans*10 + s[i] - '0';
            }
            ans = floor(sqrt(ans));
            while (ans != 1) {
                ans = floor(sqrt(ans));
                ++Count;
            }
            if (Count <= 5) {
                printf("%d\n", Count);
            } else {
                printf("TAT\n");
            }
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值