2020牛客暑期多校训练营(第九场)

A. Groundhog and 2-Power Representation

Groundhog and 2-Power Representation

⭐题意

将一个数表示成全部都时2的次方的形式,求这个数的值

⭐思路

一开始看范围就知道要么高精度,要么上py

而转念一想,不就是在(前加一个**

然后用py自带的eval(evaluate)计算出来嘛🐎

赛后看见一个这么短的代码

print(eval(input().replace('(','**(')))

c++选手骂骂咧咧退出群聊

⭐代码

  1. py
s = input()
x = ''
for i in s:
    if i == '(':
        x += '**'
    x += i
print(eval(x))
  1. C++

I. The Crime-solving Plan of Groundhog

The Crime-solving Plan of Groundhog

⭐题意

给一堆[0, 9]的数,拼接成两个数,使得乘积最小

⭐思路

先取这些数里面最小的一个非零数组成一个数,

再取剩下的组成一个最小的数

规则是,先在剩下的数取一个最小的一个非零数为第一位,

再在后面填0,然后从小到大开始往后填数字

这样可以保证乘积最小

⭐代码

  1. C++
/*************************************************************************
 > FileName:
 > Author:      Lance
 > Mail:        lancelot_hcs@qq.com
 > Date:        9102.1.8
 > Description:
 ************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9 + 7;
#define debug(a) cout << "*" << a << "*" << endl
const int INF = 0x3f3f3f3f;//int2147483647//ll9e18//unsigned ll 1e19
const int maxn = 100005;
//sacnf("%lf") printf("%f")
ll read() {
    ll x = 0,f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
        f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
int t, n;
int a[100005];
int num[11];
vector<int> mul(vector<int> &A, int B) {
    vector<int> C;
    int t = 0;
    for (int i = 0; i < A.size() || t; i++) {
        if (i < A.size()) t += A[i] * B;
        C.push_back(t % 10);
        t /= 10;
    }
    reverse(C.begin(), C.end());
    return C;
}
vector<int> A;
vector<int> ANS;
void solve() {
    t = read();
    while (t--) {
        memset(num, 0, sizeof num);
        A.clear();
        ANS.clear();
        n = read();
        int min1 = INF;
        for (int i = 1; i <= n; i++) {
            a[i] = read();
            if (a[i] != 0) min1 = min(min1, a[i]);
            num[a[i]]++;
        }
        int b = min1;
        num[b]--;
        int fi = INF;
        for (int i = 1; i <= 9; i++) 
            if (num[i] >= 1) {
                fi = i;
                break;
            }
        num[fi]--;
        A.push_back(fi);
        int con0 = num[0];
        if (con0 > 0) while (con0--) A.push_back(0);

        for (int i = 1; i <= 9; i ++) {
            int con = num[i];
            if (num[i] <= 0) continue;
            while (con--) A.push_back(i);
        }
        reverse(A.begin(), A.end());
        ANS = mul(A, b);
        for (auto i : ANS) cout << i;
        puts("");
    }
}

int main()
{

//    freopen("F:/Overflow/in.txt","r",stdin);
//    ios::sync_with_stdio(false);
    solve();
    return 0;
}

  1. py
t=int(input())
for i in range(t):
	n=int(input())
	a=input().split()
	a.sort()
	pos=0
	while a[pos]=='0':
		pos=pos+1
	x=a[pos]
	y=a[pos+1]+'0'*pos+''.join(a[pos+2:])
	print(int(x)*int(y))

c++选手骂骂咧咧退出群聊

join的用法,将一个容器,一般为列表或元组,用''.join()

引号的字符连接起来

>>> seq1 =['hello','good','boy','doiido']
>>> print' '.join(seq1)
hello good boy doiido

F. Groundhog Looking Dowdy

Groundhog Looking Dowdy

⭐题意

emmm

⭐思路

尺取,数据太水,贪心都能过。。

⭐代码

/*************************************************************************
 > FileName:
 > Author:      Lance
 > Mail:        lancelot_hcs@qq.com
 > Date:        9102.1.8
 > Description:
 ************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9 + 7;
#define debug(a) cout << "*" << a << "*" << endl
const int INF = 0x3f3f3f3f;//int2147483647//ll9e18//unsigned ll 1e19
const int maxn = 4000005;
//sacnf("%lf") printf("%f")
ll read()
{
    ll x = 0,f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
        f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
int t, n, m, ans = INF, temp = 0, vis[maxn], all = 0;

struct node {
    int day, dow;
    bool operator < (const node& W) const {return dow < W.dow;}
}N[maxn];

void solve() {
    n = read(), m = read();
    for (int i = 1; i <= n; i++) {
        int te = read();
        for (int j = 1; j <= te; j++) 
            N[all].day = i, N[all++].dow = read();
    }
    
    sort(N, N + all);
    for (int i = 0, j = 0; i < all; i++) {
        if (vis[N[i].day] == 0) temp ++;
        vis[N[i].day] ++;
        while (temp >= m && j <= i) {
            if ((--vis[N[j].day] == 0)) temp--;
            ans = min(N[i].dow - N[j].dow, ans);
            j++;
        }
    }
    
    printf("%d", ans);
}

int main() {

//    freopen("F:/Overflow/in.txt","r",stdin);
//    ios::sync_with_stdio(false);
    solve();
    return 0;
}



E. Groundhog Chasing Death

Groundhog Chasing Death

⭐题意

给定x,y的值以及i,j的范围,求

\[\prod_{i=a}^{b} \prod_{j=c}^{d} g c d\left(x^{i}, y^{j}\right) \% \bmod \]

⭐思路

寻找规律发现,gcd(a, b)实际上是a和b的公共质因数的乘积,而\(b^i\)\(b\)的质因数个数的\(i\)倍,于是问题变成

⭐代码

/*************************************************************************
 > FileName:
 > Author:      Lance
 > Mail:        lancelot_hcs@qq.com
 > Date:        9102.1.8
 > Description:
 ************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 LL; 
typedef pair<int, int> PII;
const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = 998244353;
#define debug(a) cout << "*" << a << "*" << endl
const int INF = 0x3f3f3f3f;//int2147483647//ll9e18//unsigned ll 1e19
const int maxn = 5000005;
//sacnf("%lf") printf("%f")
ll read()
{
    ll x = 0,f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
        f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
ll t, n;

ll  top;

ll p[maxn], ans = 1;
ll num_x[maxn], num_y[maxn];
ll qpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = (res * a) % mod;
        a = (a * a) %mod;
        b >>= 1;
    }
    return res;
}


void solve()
{
    ll a = read(),b = read(),c = read(),d = read(),x = read(),y = read();
    
    ll xx = x, yy = y, e = d - c + 1;
    for (int i = 2; i <= xx / i; i++) {
        if (xx % i == 0 && yy % i == 0) {
            p[top] = i;
            num_x[top] = num_y[top] = 0;
            while (xx % i == 0) {
                num_x[top]++;
                xx /= i;
            }
            while (yy % i == 0) {
                num_y[top]++;
                yy /= i;
            }
            top++;
        }
        while (xx % i == 0) xx /= i;
        while (yy % i == 0) yy /= i;
    }
    
    if (xx != 1 && yy != 1 && max(xx, yy) % min(xx, yy) == 0) {
        ll i = min(xx, yy);
        p[top] = i;
        while (xx % i == 0) {
            num_x[top]++;
            xx /= i;
        }
        while (yy % i == 0) {
            num_y[top]++;
            yy /= i;
        }
        top++;
    }
    ans = 1;
    for (ll i = 0; i < top; i++) {
        ll z = 0;
        ll temx, temy;
//		cout << p[i] << ' ' << num_x[i] << ' ' << num_y[i] << endl;
        for (ll j = a; j <= b; j++) {
            temx = (num_x[i] * j) % mod;
            temy = (num_y[i] * c) % mod;
            if (temx <= temy) z += temx * e;
            else if (temx >= (num_y[i] * d)) z += (num_y[i] * c + num_y[i] * d) * e / 2;
            else {
                ll r = temx / num_y[i];
                z += (d - r) * temx;
                z += (temy + r * num_y[i]) * (r - c + 1) / 2;
            }
            z %= mod - 1;
        }
        ans = (ans * qpow(p[i], z)) % mod;
    }
    
    printf("%lld\n", ans);
}

int main()
{

//    freopen("F:/Overflow/in.txt","r",stdin);
//    ios::sync_with_stdio(false);
    solve();
    return 0;
}

K.The Flee Plan of Groundhog

The Flee Plan of Groundhog

⭐题意

⭐思路

⭐代码


posted @ 2020-08-09 12:25  Lancelot&  阅读(310)  评论(0编辑  收藏  举报