acm入门基础题解一Word格式.docx

上传人:b****2 文档编号:15166961 上传时间:2022-10-28 格式:DOCX 页数:16 大小:345.49KB
下载 相关 举报
acm入门基础题解一Word格式.docx_第1页
第1页 / 共16页
acm入门基础题解一Word格式.docx_第2页
第2页 / 共16页
acm入门基础题解一Word格式.docx_第3页
第3页 / 共16页
acm入门基础题解一Word格式.docx_第4页
第4页 / 共16页
acm入门基础题解一Word格式.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

acm入门基础题解一Word格式.docx

《acm入门基础题解一Word格式.docx》由会员分享,可在线阅读,更多相关《acm入门基础题解一Word格式.docx(16页珍藏版)》请在冰豆网上搜索。

acm入门基础题解一Word格式.docx

=1;

i--)

if(b[i+1][j+1]>

b[i+1][j])

b[i][j]=b[i+1][j+1]+a[i][j];

else

b[i][j]=b[i+1][j]+a[i][j];

printf("

%d\n"

b[1][1]);

intmain(){

while(scanf("

n)!

=EOF&

&

n!

=0){

data_set();

solve();

return0;

ProblemB:

去北京看奥运

string.h>

constintinf=200000000;

inta[maxn],b[maxn][maxn],dp[maxn][maxn],n;

for(intj=0;

maxn;

for(intk=0;

k<

k++)

dp[k][j]=inf;

dp[0][1]=0;

ints,e,l;

n);

a[0]=1;

a[n+1]=1;

i++)scanf("

a[i]);

for(inti=0;

for(intk=1;

b[k][j]=inf;

while

(1){

s);

if(s==0)break;

%d%d"

e,&

l);

b[s][e]=l;

=a[i+1];

=a[i];

k++){

if(dp[i+1][j]>

dp[i][k]+b[k][j]&

b[k][j]!

=inf)

dp[i+1][j]=dp[i][k]+b[k][j];

dp[n+1][1]);

intmain(void){

intt;

t);

while(t--)

ProblemC:

计算直线的交点数

#include<

iostream>

set>

usingnamespacestd;

intmain()

{

intn,tmp;

set<

int>

s[21];

s[0].insert(0);

s[1].insert(0);

for(inti=2;

21;

i++)

{

i;

:

iteratorit;

for(it=s[j].begin();

it!

=s[j].end();

it++)

tmp=*it+(i-j)*j;

s[i].insert(tmp);

while(cin>

>

n)

for(it=s[n].begin();

=s[n].end();

if(it!

=s[n].begin())cout<

<

"

"

;

cout<

*it;

endl;

ProblemD:

免费馅饼

inta[100050][11];

inti,j,n,p,q,x,m;

&

=EOF)

if(n==0)break;

m=0;

memset(a,0,sizeof(a));

for(i=1;

q,&

p);

a[p][q]++;

if(p>

m)m=p;

for(i=m;

=0;

for(j=0;

11;

intx=a[i+1][j];

if(j>

0&

a[i+1][j-1]>

x)x=a[i+1][j-1];

if(j<

10&

a[i+1][j+1]>

x)x=a[i+1][j+1];

a[i][j]+=x;

a[0][5]);

ProblemE:

地道战

intn,m,a[maxn][maxn],r[maxn][maxn],d[maxn][maxn];

intmin(inta,intb){

returna<

b?

a:

b;

m;

r[i][j]);

=m;

n;

d[j][i]);

a[i][j]=inf;

a[1][1]=0;

i++)a[1][i]=a[1][i-1]+r[1][i-1];

i++)a[i][1]=a[i-1][1]+d[i-1][1];

for(intj=2;

a[i][j]=min(a[i][j-1]+r[i][j-1],a[i-1][j]+d[i-1][j]);

a[n][m]);

n,&

m)!

=EOF){

ProblemF:

最长不下降序列

constintmaxn=2000;

inti,j,n,t,x,lmax,a[maxn],b[maxn];

intmax;

cin>

a[i];

b[n]=1;

lmax=0;

for(i=n-1;

i--){

max=0;

for(j=i+1;

if(a[i]<

=a[j]&

b[j]>

max)

max=b[j];

b[i]=max+1;

if(b[i]>

lmax)lmax=b[i];

lmax<

 

Substrings

algorithm>

string>

boolcomp(stringstr1,stringstr2){

returnstr1.length()<

str2.length();

stringstr[112];

t;

while(t--){

intn;

inti=0;

for(i=0;

str[i];

sort(str,str+n,comp);

string:

iteratorp1;

iteratorp2;

iteratorp0;

intans=0,max=0;

for(p1=str[0].begin();

p1<

str[0].end();

p1++)

for(p2=str[0].end()-1;

p2>

=p1;

p2--){

stringss1=str[0].substr(p1-str[0].begin(),p2-p1+1);

stringss2;

for(string:

iteratorit=p2;

it>

it--){

ss2+=*it;

ans=ss1.length();

intflag=1;

intx=str[i].find(ss1);

inty=str[i].find(ss2);

if(x==-1&

y==-1){

flag=0;

break;

if(flag==1&

max<

=ans)

max=ans;

ProblemB:

CallingExtraterrestrialIntelligcn

cstdio>

cstring>

#defineN100005

boolno_prim[N];

intm,a,b,p,q;

voidprimetable()

inti,j;

for(i=3;

317;

i+=2)

if(no_prim[i]==false)

inttmp=i<

1;

for(j=i*i;

N;

j+=tmp)

no_prim[j]=true;

primetable();

%d%d%d"

m,&

a,&

b)&

m&

a&

b)

p=q=0;

doublelimit=a*1.0/b;

for(i=2;

if(!

no_prim[i]&

i%2!

=0||i==2)

for(j=2;

=i&

i*j<

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 化学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1