cf goodbye 2023(A-C)

发布时间 2024-01-06 16:37:04作者: 月下~观星

cf goodbye 2023(A-C)

A - 2023

算法分析

多组答案输出一组即可

先累乘,如果不是2023的除数也就是2023的因子就直接no

如果是2023的因子

先输出1

再输出2023/累乘的除数

#include<bits/stdc++.h>
using namespace std;
int t,n,k;
int a[10];
typedef long long ll;
#define x first
#define y second
map<int,int>p;
bool sovle()
{
  cin>>n>>k;
  ll res=1;
   for(int i=1;i<=n;i++){cin>>a[i];res*=a[i];}
   ll cnt=res;
   int u=2023;
      if(res>2023||2023%res!=0)return false;
      cout<<"yes\n";
    u/=res;
      for(int i=1;i<k;i++)
      cout<<"1 ";
      cout<<u<<endl;
      return true;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie();cout.tie();
    int u=2023;
    cin>>t;
    while(t--)
       if(!sovle())
       cout<<"no\n";
    return 0;
}

B - Two Divisors

算法分析

观察

1.含有1

含有1的时候答案就是两者乘积

2.不含1

往gcd和lcm想---原因:出现除数和乘积的描述

尝试可以发现答案就是lcm

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t,n,m;
bool su(ll a)
{
    for(int i=2;i<=a/i;i++)
    if(a%i==0)return false;
    return true;
}
ll gcd(ll x,ll y)
{
    return y?gcd(y,x%y):x;
}
void sovle()
{
     cin>>n>>m;
     if(n==1)
     cout<<m*m<<endl;
     else
     {
            
            ll g=gcd(m,n);
             if(m%n==0)
             cout<<m*(m/n)<<endl;
             else
                cout<<(m*n)/g<<endl;
     }
}
int main()
{
    ios::sync_with_stdio(false);cin.tie();cout.tie();
    cin>>t;
    while(t--)
    sovle();
    return 0;
}

C - Training Before the Olympiad

算法分析:

不开ll*祖宗

想要尽可能大就会凑出偶数---奇+奇/偶+偶

小-------奇+偶

出现一组奇数+偶数最后见过一次操作就会使得他整体-1

特判只有一个没有选择

1.下标为1

2.下标为其他

{

看奇数个数分析

第一个人想要结果大就会故意多选掉奇数使第二个人没有选择

所有第一个人会尽量奇+奇(sum为前缀和)

奇数为1----一种奇+偶 sum-1(1%3==1)

奇数为2----奇+奇 sum-0(2/3=0)

奇数为3-----奇+奇 奇+偶 sum-1(3/3=1)

奇数为4------奇+奇 奇+偶 奇+偶(还有一个奇数肯定会在某个人手中选出) sum-2(需要特判) sum-2(4%3==1)

奇数为5------一套3奇数组合和两个单独奇数 sum-1(5/3=1)

奇数为6------刚好2套3奇数组合 sum-2(6/3==2)

就此完整得到结论

}

#include<bits/stdc++.h>
using namespace std;
int t,n;
typedef long long ll;
const int N=1e5+10;
ll  a[N];
void sovle()
{
  cin>>n;
//ll s,ss;
  ll res=0,s;
  cin>>a[1];
  cout<<a[1]<<' ';
 if(a[1]%2!=0)res++;
 for(int i=2;i<=n;i++){
    cin>>a[i];
  if(a[i]%2!=0)res++;
  a[i]+=a[i-1];
s=a[i]-(res/3)-(res%3==1);
cout<<s<<' ';
  }
   cout<<endl;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie();cout.tie();
    cin>>t;
    while(t--)
    sovle();
    return 0;
}