AcWing 第 95 场周赛 AB(简单数论)C(博弈论)

https://www.acwing.com/activity/content/competition/problem_list/3002/

4873. 简单计算

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN;
const LL N=2e5+10,M=2023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        LL x1,x2,y1,y2;
        cin>>x1>>y1>>x2>>y2;
        cout<<max(abs(x1-x2),abs(y1-y2))<<endl;
    }
    return 0;
}

4874. 约数

题目大意:

问给定n个数,每个数字是不是美丽数(如果一个正整数的约数个数恰好为 3个,则称为美丽数)
输入样例:
3
4 5 6
输出样例:
YES
NO
NO

虽然数据范围很大,在1e12内,但是不要慌,找找规律,开平方一下就可以发现我们只需要质数就行了,所以提前预处理+标记即可。
(筛质数的板子都忘记了,我有错)

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN;
const LL N=2e6+10,M=2023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
int primes[N],cnt=0;
bool st[N];
map<LL,LL> mp;
void get_primes()
{
    for(int i=2;i<=1000000;i++)
    {
        //if(st[i]==true) continue;
        //else
        if(st[i]==false)
        {
            //primes[cnt++]=i;
            mp[i]++;
            for(int j=i+i;j<=1000000;j+=i)
                st[j]=true;
        }
    }
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    get_primes();
    while(T--)
    {
        LL n;
        cin>>n;
        LL idx=(int)sqrt(n);
        if(idx*idx==n)
        {
            if(mp[idx]!=0) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else cout<<"NO"<<endl;
    }
    return 0;
}

4875. 整数游戏

题目大意:

长度为n的正整数数列 a1,a2,…,an ,Alice 先手。

当轮到一人采取行动时,如果 a1=0,则该玩家输掉游戏,否则该玩家需要:

在 [2,n]范围内选择一个整数 i。
将 a1 的值减少 1 。
交换 a1 和 ai 的值。

假设双方都采取最优策略,请你判断谁将获胜。
输入样例:
3
2
1 1
2
2 1
3
5 4 4
输出样例:
Bob
Alice
Alice

没记错的话,应该在cf上做过原题
暴力打个表,找一手规律即可

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN;
const LL N=2e6+10,M=2023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        LL maxn=MAXN;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(i>=2) maxn=min(maxn,a[i]);
        }
        if(a[1]<=maxn) cout<<"Bob"<<endl;
        else cout<<"Alice"<<endl;
    }
    return 0;
}
posted @ 2023-03-20 16:58  高尔赛凡尔娟  阅读(15)  评论(0编辑  收藏  举报