很简单的题目,直接上代码吧。
题目地址:A. Helpful Maths
AC代码:
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int a[102],len;
char s[500];
int main()
{
int i,p;
while(~scanf("%s",s))
{
p=0;
len=strlen(s);
for(i=0;i<len;i+=2)
a[p++]=s[i]-'0';
sort(a,a+p);
cout<<a[0];
for(i=1;i<p;i++)
cout<<"+"<<a[i];
cout<<endl;
}
return 0;
}
AC代码:
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
__int64 sum,i;
int a,b,x;
int pre;
while(~scanf("%d%d",&a,&b))
{
sum=0;
pre=1;
for(i=1;i<=b;i++)
{
scanf("%d",&x);
if(x>=pre)
sum+=x-pre;
else
sum+=a-(pre-x);
pre=x;
}
printf("%I64d\n",sum);
}
return 0;
}
题目大意:1~10类别的砝码。0表示表示没有,1表示有。然后给你一个数m。每次放砝码的时候放的这个不能跟前一个是一个类别。并且需要放的哪边哪边就重一点。依次是先放左边再放右边。。如此循环。如果能放,输出一组m即可。不能输出No。
解题思路:当时我就觉得每次放的时候如果能选小一点的砝码,就选小一点的。当时先给的几组小测试数据过了,看了下第四题,觉得有点不是很懂。觉得第五题蛮有意思的。后来太困了,就直接关了电脑准备睡了。随手看了下手机,发现群里面boblee说了组数据1110000000 4 正确答案是2 3 2 3。当时12:0x了。我想了下自己的数据,开始选1 然后选2 再选3然后就会输出NO,想算了吧,最后还是忍不住自己在第一次的时候枚举了一下。最后发现A了。详见代码。贪心思想。
题目地址:C. Xenia and Weights
AC代码:
//代码写的有点乱
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
int visi[12];
int wei[12]; //wei里面记录的是拥有的砝码类别
char s[12];
int a[1002]; //存放放的砝码
int main()
{
int i,m,sum1,sum2,p,step,j;
while(~scanf("%s",s))
{
p=0;
memset(visi,0,sizeof(visi));
for(i=0; i<10; i++)
if(s[i]=='1')
{
visi[i+1]=1;
//cnt++;
}
for(i=1; i<=10; i++)
if(visi[i]==1)
{
wei[p++]=i;
//cout<<wei[p-1]<<endl;
}
scanf("%d",&m);
if(p==0) //没有砝码直接输出NO
{
printf("NO\n");
continue;
}
int flag1=0;
int flag,pre;
for(j=0; j<p; j++) //枚举放的第一个砝码
{
flag=0;
pre=wei[j]; //记录上一个放的砝码
a[0]=wei[j]; //第一个
sum1=pre; //左边的总数
step=1; //步数判定放左边还是右边
sum2=0; //右边的总数
while(step<m)
{
if(step&1) //该放右边了
{
for(i=0; i<p; i++)
{
if(wei[i]!=pre)
{
if(sum2+wei[i]>sum1)
{
a[step]=wei[i];
pre=wei[i];
sum2=sum2+wei[i];
break;
}
}
}
if(sum2<=sum1)
{
flag=1;
break;
}
}
else //该放左边了
{
for(i=0; i<p; i++)
{
if(wei[i]!=pre)
{
if(sum1+wei[i]>sum2)
{
a[step]=wei[i];
pre=wei[i];
sum1=sum1+wei[i];
break;
}
}
}
if(sum1<=sum2)
{
flag=1;
break;
}
}
step++;
}
if(flag)
continue;
flag1=1;
break;
}
if(flag1==0) puts("NO");
else
{
puts("YES");
printf("%d",a[0]);
for(i=1; i<m; i++)
printf(" %d",a[i]);
cout<<endl;
}
}
return 0;
}
感觉这应该是最简单的依次codeforces了,听说D题是很水的线段树,我觉得E题还可以看下。
推荐一首很好听的歌:
夜空中最亮的星
来自逃跑计划