11月23日题解

J - Justifying the Conjecture

题意:伟大的数学家DreamGrid提出了一个猜想,认为:

每个正整数都可以表示为一个素数和一个复合数的和。

DreamGrid无法证明他的猜测是正确的,所以我们邀请您编写一个程序来验证它。给定一个正整数𝑛, 求素数𝑥 和一个复合数𝑦 以致𝑥+𝑦=𝑛.

素数是大于1的自然数,不能由两个较小的自然数相乘而形成。大于1的非素数称为复合数。请注意,1

既不是质数也不是复合数。

题解:
1.对于小于5等于5的整数,显然无法分成一个质数和一个合数。
2.对于大于5的整数必定可以分成一个质数和一个合数,只需要看他是否是奇数或者偶数即可,如果是奇数分出3,如果是偶数分出2

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <fstream>
#include <climits>

using namespace std;
typedef long long ll;

#define pi acos(-1.0)

#define oula                                                              \
    bool notprime[1000010];                                               \
    int primes[1000010];                                                  \
    void get_prime()                                                      \
    {                                                                     \
        notprime[1] = true;                                               \
        for (int i = 2; i < 1000010; ++i)                                 \
            if (!notprime[i])                                             \
            {                                                             \
                primes[++primes[0]] = i;                                  \
                for (long long j = (long long)i * i; j < 1000010; j += i) \
                    notprime[j] = true;                                   \
            }                                                             \
    };

#define ksm                           \
    inline ll qpow(ll x, ll a)        \
    {                                 \
        ll ret = 1, k = x;            \
        for (; a; a >>= 1, k = k * k) \
            if (a & 1)                \
                ret = ret * k;        \
        return ret;                   \
    }

#define gcdxy                     \
    ll gcd(ll a, ll b)            \
    {                             \
        if (a < b)                \
            swap(a, b);           \
        if (b == 0)               \
            return a;             \
        else                      \
            return gcd(a % b, b); \
    }

#define fread                           \
    inline ll read()                    \
    {                                   \
        char ch = getchar();            \
        ll x = 0, f = 1;                \
        while (ch < '0' || ch > '9')    \
        {                               \
            if (ch == ' - ')            \
                f = -1;                 \
            ch = getchar();             \
        }                               \
        while ('0' <= ch && ch <= '9')  \
        {                               \
            x = x * 10 + int(ch - '0'); \
            ch = getchar();             \
        }                               \
        return x * f;                   \
    }

#define xor_                    \
    ll xor_n(ll n)              \
    {                           \
        ll t = n & 3;           \
        if (t & 1)              \
            return t / 2ll ^ 1; \
        return t / 2ll ^ n;     \
    }

#define exgcd_                         \
    ll exgcd(ll a, ll b, ll &x, ll &y) \
    {                                  \
        if (b == 0)                    \
        {                              \
            x = 1;                     \
            y = 0;                     \
            return a;                  \
        }                              \
        ll r = exgcd(b, a % b, x, y);  \
        ll t = x;                      \
        x = y;                         \
        y = t - a / b * y;             \
        return r;                      \
    }
#define mksm                                \
    int mod = 1e9 + 7;                      \
    inline ll mqpow(ll x, ll a)             \
    {                                       \
        ll ret = 1, k = x;                  \
        for (; a; a >>= 1, k = k * k % mod) \
            if (a & 1)                      \
                ret = ret * k % mod;        \
        return ret;                         \
    }

//oula
ksm

gcdxy

fread

xor_

exgcd_

mksm



ll abs_(ll x) {
    return x < 0 ? -x : x;
}


//int find(int x)
//{
//    if (a[x] != x) a[x] = find(a[x]);
//    return a[x];
//}
//
//void join(int x, int y) {
//    a[find(x)] = find(y);
//}

int main(void) {
    // ifstream cin;
    // fstream cout;
    // cin.open("input.txt", ios::in);
    // cout.open("ans.txt", ios::out);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        if (n <= 5)
            cout << -1 << endl;
        else if (n & 1)
            cout << 3 << " " << n - 3 << endl;
        else
            cout << 2 << " " << n - 2 << endl;
    }
}

/*

4
3
1 3 4
5
1 2 5 7 4
1
1
3
69 6969 696969

-1 1  4  0 -5  1  8 0 -9 1  12  0
1  2  3  4  5  6  7 8 9  10 11 12

3 1 -2 2
1 2  3 4

2 0 -3 1  6 0 -7 1
1 2 3  4  5 6 7 8

3 2 -4 -2 0
7 6 2 4

5 4 2
*/

Keeping Rabbits

题意:DreamGrid是地球的守护者𝑛 兔子。最初𝑖-th(1)≤𝑖≤𝑛) 兔子的体重是𝑤𝑖.

每天早上,DreamGrid都会给兔子一根1磅重的胡萝卜

兔子为唯一的胡萝卜而战。只有一只兔子获胜并吃掉了胡萝卜。之后,获胜者的体重增加1。整个战斗和进食过程在第二天早上之前结束。

DreamGrid发现兔子越重,就越容易赢得一场战斗𝑤′1.𝑤′2,…,𝑤′𝑛在一场战斗之前𝑖-这只兔子赢了这场战斗概率
请添加图片描述他想知道每只兔子出生后𝑘 天的预期体重(𝑘 胡萝卜被给予和食用)。

题解:本题是数学期望题,对于每只兔子赢得概率乘上k天加上初始体重就是他的k天后的预期体重

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <fstream>
#include <climits>

using namespace std;
typedef long long ll;

#define pi acos(-1.0)

#define oula                                                              \
    bool notprime[1000010];                                               \
    int primes[1000010];                                                  \
    void get_prime()                                                      \
    {                                                                     \
        notprime[1] = true;                                               \
        for (int i = 2; i < 1000010; ++i)                                 \
            if (!notprime[i])                                             \
            {                                                             \
                primes[++primes[0]] = i;                                  \
                for (long long j = (long long)i * i; j < 1000010; j += i) \
                    notprime[j] = true;                                   \
            }                                                             \
    };

#define ksm                           \
    inline ll qpow(ll x, ll a)        \
    {                                 \
        ll ret = 1, k = x;            \
        for (; a; a >>= 1, k = k * k) \
            if (a & 1)                \
                ret = ret * k;        \
        return ret;                   \
    }

#define gcdxy                     \
    ll gcd(ll a, ll b)            \
    {                             \
        if (a < b)                \
            swap(a, b);           \
        if (b == 0)               \
            return a;             \
        else                      \
            return gcd(a % b, b); \
    }

#define fread                           \
    inline ll read()                    \
    {                                   \
        char ch = getchar();            \
        ll x = 0, f = 1;                \
        while (ch < '0' || ch > '9')    \
        {                               \
            if (ch == ' - ')            \
                f = -1;                 \
            ch = getchar();             \
        }                               \
        while ('0' <= ch && ch <= '9')  \
        {                               \
            x = x * 10 + int(ch - '0'); \
            ch = getchar();             \
        }                               \
        return x * f;                   \
    }

#define xor_                    \
    ll xor_n(ll n)              \
    {                           \
        ll t = n & 3;           \
        if (t & 1)              \
            return t / 2ll ^ 1; \
        return t / 2ll ^ n;     \
    }

#define exgcd_                         \
    ll exgcd(ll a, ll b, ll &x, ll &y) \
    {                                  \
        if (b == 0)                    \
        {                              \
            x = 1;                     \
            y = 0;                     \
            return a;                  \
        }                              \
        ll r = exgcd(b, a % b, x, y);  \
        ll t = x;                      \
        x = y;                         \
        y = t - a / b * y;             \
        return r;                      \
    }
#define mksm                                \
    int mod = 1e9 + 7;                      \
    inline ll mqpow(ll x, ll a)             \
    {                                       \
        ll ret = 1, k = x;                  \
        for (; a; a >>= 1, k = k * k % mod) \
            if (a & 1)                      \
                ret = ret * k % mod;        \
        return ret;                         \
    }

//oula
ksm

gcdxy

fread

xor_

exgcd_

mksm



ll abs_(ll x) {
    return x < 0 ? -x : x;
}


//int find(int x)
//{
//    if (a[x] != x) a[x] = find(a[x]);
//    return a[x];
//}
//
//void join(int x, int y) {
//    a[find(x)] = find(y);
//}

double a[1000010];

int main(void) {
    // ifstream cin;
    // fstream cout;
    // cin.open("input.txt", ios::in);
    // cout.open("ans.txt", ios::out);
    int t;
    cin >> t;
    while (t--) {
        double n = read(), k = read();
        double sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = read();
            sum += a[i];
        }
        for (int i = 0; i < n; i++) {
            a[i] += k * a[i] / sum;
        }
        printf("%.8f", a[0]);
        for (int i = 1; i < n; i++) {
            printf(" %.8f", a[i]);
        }
        printf("\n");
    }
}

/*

4
3
1 3 4
5
1 2 5 7 4
1
1
3
69 6969 696969

-1 1  4  0 -5  1  8 0 -9 1  12  0
1  2  3  4  5  6  7 8 9  10 11 12

3 1 -2 2
1 2  3 4

2 0 -3 1  6 0 -7 1
1 2 3  4  5 6 7 8

3 2 -4 -2 0
7 6 2 4

5 4 2
*/

Fixing Banners

题意:哈尔滨的名字最初是一个满语单词,意思是“晒渔网的地方”,它从松花江上的一个小农村聚落发展成为中国东北最大的城市之一。1898年,随着中国东部铁路的修建,这座城市首先繁荣起来,成为俄罗斯帝国绝大多数移民居住的地区。现在,哈尔滨是黑龙江省省会和中华人民共和国东北地区最大的城市。它是中国东北地区重要的政治、经济、科学、文化和交通枢纽,也是国家重要的工业基地。

今年,由东北林业大学主办的CCPC区域竞赛将在这座美丽的城市举行。为了确保比赛的成功和全国程序员的喜爱,比赛前几个月的准备工作正在顺利进行。

你是一个学生志愿者小组的组长,负责在活动期间制作横幅装饰校园。不幸的是,你的团队犯了一个错误,把其中一个横幅打印错了。确切地说,“哈尔滨”一词在那面旗帜上不见了。因为你没有时间重印,唯一的解决办法是从一些旧的横幅上剪下字母,然后粘贴到打印错误的横幅上。你有六个横幅,出于某种原因,你必须从每个横幅上剪下一个字母。然后,你可以将这六个字母排列并粘贴到印刷错误的横幅上,并尝试将遗漏的单词“哈尔滨”拼成。然而,在开始切割之前,您决定编写一个程序,看看这是否可行。

题解:对于harbin进行全排列,在每一个字符串中寻找相应的字符即可。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <fstream>
#include <climits>

using namespace std;
typedef long long ll;

#define pi acos(-1.0)

#define oula                                                              \
    bool notprime[1000010];                                               \
    int primes[1000010];                                                  \
    void get_prime()                                                      \
    {                                                                     \
        notprime[1] = true;                                               \
        for (int i = 2; i < 1000010; ++i)                                 \
            if (!notprime[i])                                             \
            {                                                             \
                primes[++primes[0]] = i;                                  \
                for (long long j = (long long)i * i; j < 1000010; j += i) \
                    notprime[j] = true;                                   \
            }                                                             \
    };

#define ksm                           \
    inline ll qpow(ll x, ll a)        \
    {                                 \
        ll ret = 1, k = x;            \
        for (; a; a >>= 1, k = k * k) \
            if (a & 1)                \
                ret = ret * k;        \
        return ret;                   \
    }

#define gcdxy                     \
    ll gcd(ll a, ll b)            \
    {                             \
        if (a < b)                \
            swap(a, b);           \
        if (b == 0)               \
            return a;             \
        else                      \
            return gcd(a % b, b); \
    }

#define fread                           \
    inline ll read()                    \
    {                                   \
        char ch = getchar();            \
        ll x = 0, f = 1;                \
        while (ch < '0' || ch > '9')    \
        {                               \
            if (ch == ' - ')            \
                f = -1;                 \
            ch = getchar();             \
        }                               \
        while ('0' <= ch && ch <= '9')  \
        {                               \
            x = x * 10 + int(ch - '0'); \
            ch = getchar();             \
        }                               \
        return x * f;                   \
    }

#define xor_                    \
    ll xor_n(ll n)              \
    {                           \
        ll t = n & 3;           \
        if (t & 1)              \
            return t / 2ll ^ 1; \
        return t / 2ll ^ n;     \
    }

#define exgcd_                         \
    ll exgcd(ll a, ll b, ll &x, ll &y) \
    {                                  \
        if (b == 0)                    \
        {                              \
            x = 1;                     \
            y = 0;                     \
            return a;                  \
        }                              \
        ll r = exgcd(b, a % b, x, y);  \
        ll t = x;                      \
        x = y;                         \
        y = t - a / b * y;             \
        return r;                      \
    }
#define mksm                                \
    int mod = 1e9 + 7;                      \
    inline ll mqpow(ll x, ll a)             \
    {                                       \
        ll ret = 1, k = x;                  \
        for (; a; a >>= 1, k = k * k % mod) \
            if (a & 1)                      \
                ret = ret * k % mod;        \
        return ret;                         \
    }

//oula
ksm

gcdxy

fread

xor_

exgcd_

mksm



ll abs_(ll x) {
    return x < 0 ? -x : x;
}


//int find(int x)
//{
//    if (a[x] != x) a[x] = find(a[x]);
//    return a[x];
//}
//
//void join(int x, int y) {
//    a[find(x)] = find(y);
//}


int main(void) {
    // ifstream cin;
    // fstream cout;
    // cin.open("input.txt", ios::in);
    // cout.open("ans.txt", ios::out);
    int t;
    cin >> t;
    while (t--) {
        int vis[10][30];
        memset(vis, 0, sizeof(vis));
        string harbin = "harbin";
        string s;
        for (int i = 0; i < 6; i++) {
            cin >> s;
            for (int j = 0; j < s.size(); j++)
                vis[i][s[j] - 'a'] = 1;
        }
        sort(harbin.begin(), harbin.end());
        int flag = 0;
        do {
            int flagg = 1;
            for (int i = 0; i < 6; i++)
                if (vis[i][harbin[i] - 'a'] == 0) {
                    flagg = 0;
                    break;
                }
            if (flagg) {
                flag = 1;
                break;
            }
        } while (next_permutation(harbin.begin(), harbin.end()));
        if (flag)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

/*

4
3
1 3 4
5
1 2 5 7 4
1
1
3
69 6969 696969

-1 1  4  0 -5  1  8 0 -9 1  12  0
1  2  3  4  5  6  7 8 9  10 11 12

3 1 -2 2
1 2  3 4

2 0 -3 1  6 0 -7 1
1 2 3  4  5 6 7 8

3 2 -4 -2 0
7 6 2 4

5 4 2
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值