暑假最后一次补题

目录

Ink on paper

GCD Game

Link with Limit

Boring data structure problem

Pty loves lines


Ink on paper

题目链接

GCD Game

题目链接

#include<iostream>
#define maxn 1000005
#define N 10000010
typedef long long int ll;
using namespace std;
int a[maxn];


int vis[10000010], p[10000010], num[10000010];
void init()
{
    int i, j, cnt = 0;
    for (i = 2; i <= N; i++)
    {
        if (!vis[i])
        {
            p[cnt++] = i;
            num[i] = 1;
        }
        for (j = 0; p[j] <= N / i; j++)
        {
            vis[i * p[j]] = 1;
            num[i * p[j]] = num[i] + 1;
            if (i % p[j] == 0)
                break;
        }
    }
}

int main()
{
    init();
    int T;
    cin >> T;
    int cnt1 = 0;
    int cnt2 = 0;
    while (T--)
    {
        int n;
        ll  ans = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &a[i]);
            ans ^= num[a[i]];
        }
        if (ans)
            cout << "Alice" << endl;
        else
            cout << "Bob" << endl;

    }
}

Link with Limit

题目链接

#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<stdio.h>
#define ee 0.0000001
#define eee -0.0000001
typedef long long int ll;
using namespace std;
const ll N = 100005;
ll n, a[N], b[N] = { 0 }, c[N] = { 0 }, id[N] = { 0 };

int main()
{
    ll T;
    scanf("%lld", &T);
    while (T--)
    {
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        memset(c, 0, sizeof(c));
        memset(id, 0, sizeof(id));
        ll tag = 0;
        scanf("%lld", &n);
        for (int i = 1; i <= n; i++)
        {
            scanf("%lld", a + i);
            //a[i] = fopen(in, "r");
            b[a[i]]++;
        }
        for (int i = 1; i <= n; i++)
        {
            if (b[i] == 0&&id[i]==0)
            {
                ll x = i;
                id[x] = 1;
                    do
                    {
                        b[a[x]]--;
                        x = a[x];
                        if (b[x] == 0)
                            id[x] = 1;
                    } while (b[x] == 0&&b[a[x]]>0);
                
            }
        }
        double sum = 0;
        for (int i = 1; i <= n; i++)
        {
            double tempsum = 0;
            ll cnt = 0;
            if (b[i] == 1&&id[i]==0)
            {
                ll x = i;
                while (c[x] < 1)
                {
                    cnt++;
                    tempsum += a[x];
                    id[x] = 1;
                    c[x]++;
                    x = a[x];    
                }
                tempsum /= cnt;
                if (sum == 0)
                    sum = tempsum;
                if ((sum-tempsum)>ee||(sum-tempsum)<eee)
                {
                    tag = 1;
                    break;
                }
            }
        }
        if (tag == 1)
            cout << "NO" << endl;
        else
            cout << "YES" << endl;
    }
}

Boring data structure problem

题目链接

Pty loves lines

题目链接

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值