2021广东省省赛

87 阅读2分钟

B

Fibonacci Sequence:

f0=1 f1=1 fi=fi−1+fi−2,i≥2

Fibonacci representation F(x): Any natural number x​ can be expressed as the sum of a set of different Fibonacci numbers.

In particular: f0​ and f1​ are two different Fibonacci numbers.

For example:7=5+2=f4+f2, 7=3+2+1+1=f3+f2+f1+f0​ indicates that 7​ corresponds to at least two Fibonacci representations.

The value of the Fibonacci representation w(F(x))w(F(x))_{}w(F(x))​: defined as the product of the Fibonacci numbers in the representation .

For example: 7=3+2+1+1=f3+f2+f1+f0. In this representation, the value w(F(x))​ is: 3∗2∗1∗1=6​.

With the above definitions, now, find the sum of all Fibonacci representations’ value of a given number x​.

To simplify the question, please output the answer modulo lovely 998244353​.

其实就是一个01背包的模板

#include<bits/stdc++.h>
using namespace std;
const int N = 1e7 +10, mod = 998244353;
vector<int> a(50);
int f[N];

void solve()
{
    int n;
    cin >> n;
    cout << f[n] << '\n';
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie();
    a.push_back(0);
    a[1] = 1, a[2] = 1;
    for (int i = 3; i <= 50; i ++)
    {
        a[i] = (a[i - 1] + a[i - 2]) % mod;
    }
    f[0] = 1;
    for (int i = 1; i <= 35; i ++)
    {
        for (int j = 1e7; j >= a[i]; j --)
        {
            f[j] = (f[j] + f[j - a[i]] * a[i]) % mod;
        }
    }
    int T = 1;
    cin >> T;
    while(T --)
    {
        solve();
    }
    
    return 0;
}

G

Alice and Bob are playing a game. Initially there are n​ positive numbers, the i​-th number is ai​. In one turn, Alice can choose an odd number and divide it into two positive numbers, or delete a number equals to 1. Bob can choose an even number and divide it into two positive numbers. Two players move in turns, and Alice move first. In one's turn, if he or she can't move, he or she lose the game. If two player move optimally, please find out who the winner is.

You need to answer T​ queries.

签到题没有什么好说的

#include<bits/stdc++.h>
#define int long long
void solve()
{
    int n,aa = 0, bb = 0;
    cin >> n;
    int flag = 0,ff = 0;
    for (int i = 1; i <= n; i ++) 
    {
        cin >> a[i];
        if(a[i] & 1) ff = 1;
        if (a[i] % 2 != 0) flag = 1;
    }
    rep(i,1,n)
    {
        if(a[i] > 2 && a[i] % 2 == 0)
        {
            bb += a[i] / 2 - 1;
        }
        if(a[i] & 1) aa += (a[i]+1) / 2;
    }
    
    if (flag == 0 || aa == 0) {cout << "Bob" << '\n';return;}
    if(aa > bb) cout << "Alice" <<endl;
    else cout << "Bob" << endl;
}

I

Giant Kingdom creates tons of drinkable water, and will discharge the water into an ocean. The ocean can be simplified to a 3-dimensional space. Because of some magic, there are 3 surfaces, 1000∣x∣=y2+z2,1000∣y∣=x2+z2,1000∣z∣=x2+y2 and water can't pass through any of the surfaces. Baby Kingdom is worried about whether the drinkable water can reach their country.

Given are two coordinates (x1,y1,z1),(x2,y2,z2) indicate the position of Giant Kingdom and the position of Baby Kingdom. Please find out weather the drinkable water can reach Baby Kingdom. It is guaranteed that both countries do not located in any of the surfaces.

You need to answer T​ queries.

思路:暴力,但是要考虑清楚这六种情况

bool pd(int a, int b, int c)
{
    return a * a + b * b < 1000 * c;
}

bool pdd(int x1,int y1,int z1,int x2,int y2,int z2)
{
    if(pd(x1,y1,(z1)) != pd(x2,y2,(z2)) ) return false;
    if(pd(x1,y1,(-z1)) != pd(x2,y2,(-z2)) ) return false;
    if(pd(x1,z1,(y1)) != pd(x2,z2,(y2)) ) return false;
    if(pd(x1,z1,(-y1)) != pd(x2,z2,(-y2)) ) return false;
    if(pd(z1,y1,(x1)) != pd(z2,y2,(x2)) ) return false;
    if(pd(z1,y1,(-x1)) != pd(z2,y2,(-x2)) ) return false;
    return true;
}

void solve()
{
    int x1,y1,z1,x2,y2,z2;
    cin >> x1 >> y1 >> z1 >> x2 >>y2 >> z2;
    if(pdd(x1,y1,z1,x2,y2,z2)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Although Jerry is a mouse, he likes perfect square numbers. If a number can be expressed as the square of an integer, it is called perfect square numbers. Jerry can use magic to move forward or backward a distance of any perfect square numbers, which costs a grain of rice each time. And the position after each use of magic can not be behind the initial position or more than 10510^5105 distance in front of the initial position. Next, there are qqq questions, each time asking how much rice at least it takes for Jerry to move forward di​.Note that each question is an independent one.

思路:找最少要多少步到达,注意不能超过1500,我们可以发现一共只有四种情况,平方数本身,+1,或者+2,+3

代码

#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(int i = a; i <= b; i ++)
#define dec(i,a,b) for(int i = a; i >= b; i --)
#define alls(x) x.begin(),x.end()
#define xx first
#define yy second

using namespace std;
const int N = 1e5 +10;
int a[N];
map<int, int> mp;

void solve()
{
    int n;
    cin >> n;
    int cnt = sqrt(n);
    if (cnt * cnt == n) cout << 1 << '\n';
    else if (mp[n]) cout << 2 << '\n';
    else 
    {
        for (int i = 1; i <= 400; i ++)
        {
            if (a[i] > 100000) break;
            
            if (n - a[i] > 0 && mp[n - a[i]]) {cout << 3 << '\n';return;}
            if (n + a[i] <= 100000 && mp[n + a[i]])
            {
                cout << 3 << '\n';
                return;
            }
        }
        cout << 4 << '\n';
        return;
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie();
    for (int i = 1; i <= 400; i ++)
    {
        a[i] = i * i;
    }
    for (int i = 1; i <= 400; i ++)
    {
        if (a[i] > 100000) break;
        for (int j = 1; j <= 400; j ++)
        {
            if (a[j] > 100000) break;
            mp[a[i] + a[j]] = 1;
            mp[a[j] - a[i]] = 1;
        }
    }
//     cout << mp[100000] << '\n';
    int T = 1;
    cin >> T;
    while(T --)
    {
        solve();
    }
    return 0;
}