# TEST2018.4.14(Noip2011提高组Day2)

T1 计算系数：

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define dnt long long
using namespace std;
const dnt MOD=10007;
const int N=1000+23;
dnt ans[N][N];
dnt k,m,n,a,b;

void init() {
ans[0][1]=1;
ans[1][1]=a;ans[1][2]=b;
for(int i=2;i<=k;i++)
for(int j=1;j<=i+1;j++)
ans[i][j]=(ans[i-1][j]*a%MOD+ans[i-1][j-1]*b%MOD)%MOD;
}

int main() {
freopen("factor.in","r",stdin);
freopen("factor.out","w",stdout);
cin>>a>>b>>k>>n>>m;
init();
cout<<ans[k][m+1]<<endl;
return 0;
}

T2 聪明的质检员：

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#define maxn 210000
using namespace std;
long long s1[maxn],s2[maxn];
int l[maxn],r[maxn];
int w[maxn],v[maxn];
int n,m;
long long S;
long long check(int x) {
memset(s1,0,sizeof(s1));
memset(s2,0,sizeof(s2));
for (int i=1;i<=n;i++) {
s1[i]=s1[i-1];s2[i]=s2[i-1];
if (w[i]>=x) {
s1[i]+=1;
s2[i]+=v[i];
}
}
long long res=0;
for(int i=0;i<m;i++)
res+=(s1[r[i]]-s1[l[i]-1])*(s2[r[i]]-s2[l[i]-1]);
return res;
}
int main(){
freopen("qc.in","r",stdin);
freopen("qc.out","w",stdout);
cin>>n>>m>>S;
for(int i=1;i<=n;i++)
scanf("%d%d",&w[i],&v[i]);
for(int i=0;i<m;i++)
scanf("%d%d",&l[i],&r[i]);
int left=0,right=*max_element(w+1,w+n+1);
while(left+1<right){
int mid=(left+right)/2;
if (check(mid)<=S)right=mid;
else left=mid;
}
cout<<min(abs(check(left)-S),abs(S-check(right)));
return 0;
}

T3 观光公交：

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1000+233;
int n,m,k,ans=0;
int arrive[N],leave[N],off[N],d[N],sum[N];
int main() {
//freopen("bus.in","r",stdin);
//freopen("bus.out","w",stdout);
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<n;i++) scanf("%d",d+i);
for(int i=1,a,b,t;i<=m;i++) scanf("%d%d%d",&t,&a,&b),off[b]++,leave[a]=max(leave[a],t),ans-=t;
int now,use;
while(k) {
for(int i=1;i<=n;i++) arrive[i]=max(arrive[i-1],leave[i-1])+d[i-1];
now=0;
for(int i=n;i>1;i--)
if(!d[i-1]) sum[i-1]=0;
else {sum[i-1]=off[i];if(arrive[i]>leave[i]) sum[i-1]+=sum[i];}
for(int i=1;i<n;i++)
if(now<sum[i]) now=sum[i],use=i;
if(!now) break;
d[use]--;k--;
}
for(int i=1;i<=n;i++) arrive[i]=max(arrive[i-1],leave[i-1])+d[i-1];
for(int i=1;i<=n;i++) ans+=arrive[i]*off[i];
printf("%d",ans);
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120