这次的题比较简单,所以我做了两题,最后一题我还差一些,可惜!
总分:
100 + 100 + 0 = 200 p t s 100+100+0=200pts 100+100+0=200pts
题解
T1
这道题比较简单,我们直接按照题意模拟就好了。
分三大块,两种情况,每一块的模拟都是一样的,只不过处理的东西不一样,分别是:
1
和
2
,
2
和
3
,
3
和
1
1和2,2和3,3和1
1和2,2和3,3和1。
我们用
1
和
2
1和2
1和2来举例。
- 如果1号牛奶+2号牛奶大于2号可装的牛奶,那就能给多少给多少。
- 如果1号牛奶+2号牛奶小于等于2号可装的牛奶,就全部给2号。
A C C o d e AC~Code AC Code
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int t1,m1,t2,m2,t3,m3;
int fx=1;
int main()
{
freopen("mixmilk.in","r",stdin);
freopen("mixmilk.out","w",stdout);
cin>>t1>>m1;
cin>>t2>>m2;
cin>>t3>>m3;
for(int i=1; i<=100; i++)
{
if(fx==1) //三大块
{
if(m1+m2>t2) //一小块
m1=m1-(t2-m2),m2=t2;
else if(m1+m2<=t2)
m2=m1+m2,m1=0;
}
else if(fx==2)
{
if(m2+m3>t3) //二小块
m2=m2-(t3-m3),m3=t3;
else if(m2+m3<=t3)
m3=m2+m3,m2=0;
}
else if(fx==3)
{
if(m3+m1>t1) //三小块
m3=m3-(t1-m1),m1=t1;
else if(m3+m1<=t1)
m1=m3+m1,m3=0;
}
fx=fx%3+1;
}
cout<<m1<<endl<<m2<<endl<<m3;
return 0;
}
T2
这道题可以用差分,但由于数据水,我就直接打了个暴力。
也很简单,就把输入的位置全部赋为需要的桶数,最后直接一重循环打擂台找最大就好了。
A C C o d e AC~Code AC Code
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int a[1000010],maxn1,ans=-1;
int n,l,r,z;
int main()
{
freopen("blist.in","r",stdin);
freopen("blist.out","w",stdout);
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>l>>r>>z;
maxn1=max(maxn1,r);
for(int i=l; i<=r; i++) //范围内累加
a[i]+=z;
}
for(int i=1; i<=maxn1+1; i++)
if(a[i]>ans) //打擂台
ans=a[i];
cout<<ans;
return 0;
}
T3
这道题是个暴力模拟,准备听完讲解后再做。
我们直接用四重循环暴力枚举即可。
重复怎么办?
我们可以让后两重循环的循环变量从
i
+
1
,
j
+
1
i+1,j+1
i+1,j+1,开始就好了。
A C C o d e AC~Code AC Code
//直接模拟,不多解释
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int a[50],b[50],ans;
int v[10010];
int main()
{
freopen("backforth.in","r",stdin);
freopen("backforth.out","w",stdout);
for(int i=1; i<=10; i++)
cin>>a[i];
for(int i=1; i<=10; i++)
cin>>b[i];
v[1000]=1;
for(int i=1; i<=10; i++)
for(int j=1; j<=10; j++)
v[1000+b[i]-a[j]]=1;
for(int i=1; i<=9; i++)
for(int j=1; j<=9; j++)
for(int k=i+1; k<=10; k++)
for(int l=j+1; l<=10; l++)
v[1000+b[i]-a[j]+b[k]-a[l]]=1;
for(int i=1000-198; i<=1000+198; i++)
if(v[i]==1)
ans++;
cout<<ans;
return 0;
}