杭电acm部分答案文档格式.docx
《杭电acm部分答案文档格式.docx》由会员分享,可在线阅读,更多相关《杭电acm部分答案文档格式.docx(39页珍藏版)》请在冰豆网上搜索。
#include<
stdio.h>
voidmain()
{
inta,b;
while(scanf("
%d%d"
&
a,&
b)!
=EOF)
{
printf("
%d\n"
a+b);
}
}
Hey,welcometoHDOJ(HangzhouDianziUniversityOnlineJudge).
Inthisproblem,yourtaskistocalculateSUM(n)=1+2+3+...+n.
Theinputwillconsistofaseriesofintegersn,oneintegerperline.
Foreachcase,outputSUM(n)inoneline,followedbyablankline.Youmayassumetheresultwillbeintherangeof32-bitsignedinteger.
1
100
5050
intn,sum,i;
%d"
n)!
{
sum=0;
for(i=0;
i<
=n;
i++)
sum+=i;
%d\n\n"
sum);
Ihaveaverysimpleproblemforyou.GiventwointegersAandB,yourjobistocalculatetheSumofA+B.
ThefirstlineoftheinputcontainsanintegerT(1<
=T<
=20)whichmeansthenumberoftestcases.ThenTlinesfollow,eachlineconsistsoftwopositiveintegers,AandB.Noticethattheintegersareverylarge,thatmeansyoushouldnotprocessthembyusing32-bitinteger.Youmayassumethelengthofeachintegerwillnotexceed1000.
Foreachtestcase,youshouldoutputtwolines.Thefirstlineis"
Case#:
"
#meansthenumberofthetestcase.Thesecondlineistheanequation"
A+B=Sum"
SummeanstheresultofA+B.Notetherearesomespacesinttheequation.Outputablanklinebetweentwotestcases.
12
112233445566778899998877665544332211
Case1:
1+2=3
Case2:
112233445566778899+998877665544332211=111111*********1110
#include<
string.h>
intmain(){
charstr1[1001],str2[1001];
intt,i,len_str1,len_str2,len_max,num=1,k;
scanf("
&
t);
getchar();
while(t--){
inta[1001]={0},b[1001]={0},c[1001]={0};
scanf("
%s"
str1);
len_str1=strlen(str1);
for(i=0;
i<
=len_str1-1;
++i)
a[i]=str1[len_str1-1-i]-'
0'
;
str2);
len_str2=strlen(str2);
=len_str2-1;
b[i]=str2[len_str2-1-i]-'
if(len_str1>
len_str2)
len_max=len_str1;
else
len_max=len_str2;
k=0;
=len_max-1;
++i){
c[i]=(a[i]+b[i]+k)%10;
k=(a[i]+b[i]+k)/10;
}
if(k!
=0)
c[len_max]=1;
printf("
Case%d:
\n"
num);
num++;
%s+%s="
str1,str2);
if(c[len_max]==1)
printf("
1"
);
for(i=len_max-1;
i>
=0;
--i){
c[i]);
if(t>
=1)
}
return0;
}
Givenasequencea[1],a[2],a[3]......a[n],yourjobistocalculatethemaxsumofasub-sequence.Forexample,given(6,-1,5,4,-7),themaxsuminthissequenceis6+(-1)+5+4=14.
=20)whichmeansthenumberoftestcases.ThenTlinesfollow,eachlinestartswithanumberN(1<
=N<
=100000),thenNintegersfollowed(alltheintegersarebetween-1000and1000).
#meansthenumberofthetestcase.Thesecondlinecontainsthreeintegers,theMaxSuminthesequence,thestartpositionofthesub-sequence,theendpositionofthesub-sequence.Iftherearemorethanoneresult,outputthefirstone.Outputablanklinebetweentwocases.
56-154-7
706-11-67-5
1414
716
注:
最大子序列是要找出由数组成的一维数组中和最大的连续子序列。
比如{5,-3,4,2}的最大子序列就是{5,-3,4,2},它的和是8,达到最大;
而{5,-6,4,2}的最大子序列是{4,2},它的和是6。
你已经看出来了,找最大子序列的方法很简单,只要前i项的和还没有小于0那么子序列就一直向后扩展,否则丢弃之前的子序列开始新的子序列,同时我们要记下各个子序列的和,最后找到和最大的子序列
inta[100005],str[100005],start[100005];
intmain()
{
intt,n,i,num=1,end,max,k;
while(t--)
n);
for(i=1;
i++)
{
scanf("
a[i]);
str[1]=a[1];
start[1]=1;
for(i=2;
if(str[i-1]>
=0)
{
str[i]=str[i-1]+a[i];
start[i]=start[i-1];
}
else
str[i]=a[i];
start[i]=i;
max=str[1];
end=1;
for(k=2;
k<
k++)
if(str[k]>
max)
max=str[k];
end=k;
num);
%d%d%d\n"
max,start[end],end);
if(t)
Contesttimeagain!
Howexciteditistoseeballoonsfloatingaround.Buttotellyouasecret,thejudges'
favoritetimeisguessingthemostpopularproblem.Whenthecontestisover,theywillcounttheballoonsofeachcolorandfindtheresult.
Thisyear,theydecidetoleavethislovelyjobtoyo