AIsing Programming Contest 2020

本文深入解析AtCoder平台上的六道编程挑战题目,涵盖数学运算、组合计数、动态规划、优先队列等算法技巧,提供了详细的解题思路及代码实现。


A B C D E F

( √:做出; ●:尝试未做出; ○:已补题 )


题目地址:https://atcoder.jp/contests/aising2020



A Number of Multiples

题意:签到题

思路

代码

#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> P;
int read()
{
   
   
    int x=0,flag=1;
    char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {
   
   x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int main()
{
   
   
    int L=read(),R=read(),d=read();
    int ans=0;
    REP(i,L,R) if(i%d==0) ans++;
    cout<<ans;

    return 0;
}



B An Odd Problem

题意:签到题

思路

代码

#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> P;
int read()
{
   
   
    int x=0,flag=1;
    char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {
   
   x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int main()
{
   
   
    int ans=0,n=read();
    REP(i,1,n)
    {
   
   
        int x=read();
        if(i&1 && x&1) ans++;
    }
    cout<<ans;

    return 0;
}



C XYZ Triplets

题意 f ( n ) f(n) f(n) 表示满足以下条件的三元组 ( x , y , z ) (x,y,z) (x,y,z) 的个数:

  • 1 ≤ x , y , z 1\le x,y,z 1x,y,z
  • x 2 + y 2 + z 2 + x y + y z + z x = n x^2+y^2+z^2+xy+yz+zx=n x2+y2+z2+xy+yz+zx=n

给出 N( 1 ≤ N ≤ 1 0 4 1\le N\le 10^4 1N104),输出 f ( 1 ) , f ( 2 ) , . . . , f ( N ) f(1),f(2),...,f(N) f(1),f(2),...,f(N)

思路:根据 N 的范围可以推断出,xyz都不超过100,所以就三重循环更新 f 数组就行了。

代码

#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> P;
int read()
{
   
   
    int x=0,flag=1;
    char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {
   
   x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int f[10005];

int main()
{
   
   
    REP(i,1,100) REP(j,1,100) REP(k,1,100)
    {
   
   
        int x=i*i+j*j+k*k+i*j+i*k+j*k;
        if(x<=10000) f[x]++;
    }
    int N=read();
    REP(i,1,N) printf("%d\n",f[i]);

    return 0;
}



D Anything Goes to Zero

题意 f ( n ) f(n) f(n) 表示把一个非负整数 n 经过若干次这样的操作——把 n 替换成 n   m o d   p o p c o u n t ( n ) n \ mod \ popcount(n) n mod popcount(n) ——最后变成 0 所需要操作的次数。现在给出有 N( 1 ≤ N ≤ 2 × 1 0 5 1\le N\le 2\times10^5 1N2×10

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值