Update 2020.5.13 更新C题
0、前言
比赛链接
人生的第一场Div4!纪念一下!(写的这么烂纪念啥)
从文化课那儿滚回来祭!(又考挂了)
赛时战绩:
两位大佬朋友赛时战绩(差距太明显了)
事实证明,我菜到家了.....
所以来厚脸皮地写个总结
1、A. Sum of Round Numbers
题意:
令 (a*10^b) 为 (round number) , (T) 次询问,每次输入 (n) ,求 (n) 最少要用几个 (round number) 的和来表示,输出要用几个数以及每个数的值。
思路:
最少个数一定为(n)的每位不为(0)个数,所以计数一下即可。
每个值就是当前位置上的数,补相应的$0$即可。
说句闲话:我真是傻到家了,刚开始还傻傻的求(n)的位数......
code:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
int T,len;
string n;
int main()
{
cin>>T;
while(T--)
{
cin>>n;
len=n.length();
int cnt=0;
for(int i=0;i<len;i++)
{
if(n[i]!='0')
cnt++;
}
cout<<cnt<<endl;
for(int i=0;i<len;i++)
{
if(n[i]!='0')
{
cout<<n[i];
for(int j=1;j<=len-i-1;j++)
cout<<"0";
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
2、B. Same Parity Summands
题意:
(T) 次询问,每次输入 (n) ,(k),把 (n) 拆成 (k) 份,要求每份都为奇数或都为偶数,无解输出(-1)。
思路:
蛮分是不行的,考虑前 (k-1) 个数,根据题意,可以全为 (1) 或全为 (2) 。
把剩下的堆在最后一个数上,判断一下剩下的数是否大于 (0),然后如果前面全为 (1) 时,(n-k+1) 是否为奇数,全为 (2) 时,判断(n-2*(k-1)) 是否为偶数即可。
附本题惨烈战绩:
QAQ
code:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
const int N=105;
int T,n,k,a[N];
int main()
{
cin>>T;
while(T--)
{
cin>>n>>k;
memset(a,0,sizeof a);
if((n-k+1)%2==1&&(n-k+1)>0)
{
cout<<"YES"<<endl;
for(int i=1;i<=k-1;i++)
{
cout<<"1"<<" ";
}
cout<<n-k+1<<endl;
}
else if((n-2*(k-1))%2==0&&(n-2*(k-1))>0)
{
cout<<"YES"<<endl;
for(int i=1;i<=k-1;i++)
{
cout<<"2"<<" ";
}
cout<<n-2*(k-1)<<endl;
}
else
cout<<"NO"<<endl;
}
return 0;
}
3、C. K-th Not Divisible by n
题意:
(T) 次询问,每次询问不被 (n) 整除的第 (k) 个数是多少。
思路:
暴力枚举可以发现,从 (n) 的 (a) 倍到 (a+1) 倍范围内有 (n-1) 个不能被 (n) 所整除,利用这个性质,我们便可以得出解了。
code:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
int T,n,k;
long long ans;
int main()
{
cin>>T;
while(T--)
{
ans=0;
cin>>n>>k;
int temp=k/(n-1);
int temp2=k%(n-1);
if(temp2==0)
ans=temp*n-1;
else
ans=temp*n+temp2;
cout<<ans<<endl;
}
return 0;
}
4、D.Alice, Bob and Candies
题意: