题目质量差评!为什么不给数据范围!
A.乘积最大3
题目:http://dev.luogu.org/problem/show?pid=2172
题解:sb题,均值定理。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 10000000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
ll n,m,tmp,a[maxn];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();
for1(i,m)a[i]=n/m;
tmp=n-(n/m)*m;
for3(i,m,m-tmp+)a[i]++;
for1(i,m-)printf("%lld ",a[i]);
printf("%lld\n",a[m]);
return ;
}
B.刮油漆
题目:http://dev.luogu.org/problem/show?pid=U155
题解:先差分算出每个点的高度,然后单调栈搞掉。
不知道哪写残了一直WA,没AK真不爽。。。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 1000000+1000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,ans,mx,top,a[maxn],b[maxn],sta[maxn];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for1(i,n)
{
int x=read(),y=read();
a[x]++,a[y+]--;
if(y+>mx)mx=y+;
}
for1(i,mx)b[i]=b[i-]+a[i];
ans=mx;
sta[top=]=;
for1(i,mx)
{
while(top>&&sta[top]>b[i])top--;
if(sta[top]==b[i])ans--;else sta[++top]=b[i];
}
printf("%d\n",ans);
return ;
}
C.选学霸
题目:http://dev.luogu.org/problem/show?pid=2170
题解:并查集完了之后背包,怎么昨天一天做了两道这种题?
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 1000000+1000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,ans,tot,sum,fa[maxn],a[maxn],s[maxn];
bool f[maxn];
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();k=read();m=read();
for1(i,n)fa[i]=i;
for1(i,m)
{
int x=find(read()),y=find(read());
if(x!=y)fa[x]=y;
}
for1(i,n)s[find(i)]++;
for1(i,n)if(s[i])a[++tot]=s[i];
f[]=;
for1(i,tot)
{
for3(j,sum,)
if(f[j])f[j+a[i]]=;
sum+=a[i];
}
for3(i,k,)if(f[i]){ans=i;break;}
for2(i,k,n)if(f[i]){if(abs(i-k)<k-ans)ans=i;break;}
printf("%d\n",ans);
return ;
}
这场比赛没有好好做,因为看起来都是些sb题。。。