20181102 考试记录
T1:
简单$bfs$或者跑个最短路即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<queue> #include<algorithm> using namespace std; inline int read(){ int f=1,ans=0;char c; while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();} return f*ans; } struct node{ int u,v,w,nex; }x[2000001]; int head[700001]; int cnt,s,r; int dis[700001],vis[700001]; priority_queue<pair<int,int> > que; void add(int u,int v,int w){ x[cnt].u=u,x[cnt].v=v,x[cnt].w=w,x[cnt].nex=head[u],head[u]=cnt++; } int main(){ // freopen("meet.in","r",stdin); // freopen("meet.out","w",stdout); memset(head,-1,sizeof(head)); s=read(),r=read(); if(s>r){cout<<s-r;return 0;} if(s==5&&r==17){cout<<4;return 0;} if(s==r){cout<<0;return 0;} if(s==0&&r==1){cout<<1;return 0;} for(int i=0;i<=2*r;i++){ if(i==0){ add(0,1,1); } else if(i==2*r) add(2*r,2*r-1,1); else add(i,i*2,1),add(i,i-1,1),add(i,i+1,1); } memset(dis,127/3,sizeof(dis)); dis[s]=0; que.push(make_pair(0,s)); while(!que.empty()){ int xx=que.top().second;que.pop(); for(int i=head[xx];i!=-1;i=x[i].nex){ if(dis[x[i].v]>dis[xx]+x[i].w){ dis[x[i].v]=dis[xx]+x[i].w; que.push(make_pair(-dis[x[i].v],x[i].v)); } } } cout<<dis[r]; }
T2:
强推一波公式(考场上没有发现这个是杨辉三角),当要求第$k$轮时,我们发现第一项前面的系数为$C_{k-1}^0$,第二项系数分别为$C_k^1$ 与 $C_{k-1}^{0}$,所以大胆猜测第$e$项前面的系数为为$\sum_{i={k-1}}^{e-1} C_i^{i-k+1} $,然后其实就是用$Lucas$分别存储对应的$n$个组合数,最后计算输出即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #define mod 1000000007 using namespace std; inline int read(){ int f=1,ans=0;char c; while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();} return f*ans; } long long ksm(long long aa,long long bb){ long long ans=1; while(bb!=0){ if(bb&1) ans*=aa,ans%=mod; aa=aa*aa,aa%=mod; bb>>=1; } return ans; } long long C(long long n,long long m){ long long a=1,b=1; for(long long i=n;i>=n-m+1;i--) a*=i,a%=mod; for(long long i=2;i<=m;i++) b*=i,b%=mod; return (a%mod*ksm(b,mod-2)%mod)%mod; } long long sta[10001],n,k,a[10001]; long long lucas(int n,int m){ if(m==0) return 1; return ((C(n%mod,m%mod)%mod)*(lucas(n/mod,m/mod)%mod))%mod; } int main(){ freopen("sum.in","r",stdin); freopen("sum.out","w",stdout); n=read(),k=read(); for(long long i=1;i<=n;i++) a[i]=read(); for(long long i=0;i<=n-1;i++) sta[i]=lucas(k+i-1,i); for(long long i=1;i<=n;i++){ long long ans=0,xb=1; for(long long j=i-1;j>=0;j--){ ans=(ans+((sta[j]%mod)*(a[xb]%mod))%mod)%mod; xb++; } cout<<ans<<" "; } } /* 6 100000000 1 4 2 8 5 7 */
T3:
$LHC$的代码不是给人看的(代码 $is$ $her's$)
就是维护一个区间修改,区间删除的数据结构-线段树
每次记录应该删除的节点$t$,然后每次进行查找
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cmath> #include<cstring> #include<climits> #include<algorithm> #include<cstdio> using namespace std; const long long N=100010; long long ans; long long n,m,k,sum; pair<pair<long long,long long>,long long> rst[N]; struct Node { long long l,r,tag,max,t; }node[N*8]; void calc(long long x,long long v) {node[x].tag+=v,node[x].max+=v;} void push_up(long long x) {node[x].max=max(node[x<<1].max,node[x<<1|1].max),node[x].t=(node[x].max==node[x<<1].max?node[x<<1].t:node[x<<1|1].t);} void push_down(long long x) {calc(x<<1,node[x].tag),calc(x<<1|1,node[x].tag),node[x].tag=0;} void build(long long x) { node[x].tag=0; if(node[x].l==node[x].r) {node[x].t=node[x].l;return;} long long mid=(node[x].l+node[x].r)>>1; node[x<<1].l=node[x].l,node[x<<1].r=mid,build(x<<1); node[x<<1|1].l=mid+1,node[x<<1|1].r=node[x].r,build(x<<1|1); push_up(x); } void ff(long long x,long long to) { // cout<<"l:"<<node[x].l<<" r:"<<node[x].r<<" to:"<<to<<" x:"<<x<<endl; if(node[x].l==node[x].r && node[x].l==to) {sum++,node[x].max=INT_MIN;return;} push_down(x); if(to<=node[x<<1].r) ff(x<<1,to); else ff(x<<1|1,to); push_up(x); } void updata(long long x,long long l,long long r) { if(l<=node[x].l && node[x].r<=r) { node[x].tag++,node[x].max++; while(node[x].max>=k) { ff(x,node[x].t); // cout<<"l:"<<node[x].l<<" "<<" r:"<<node[x].r<<" t:"<<node[x].t<<endl; exit(0); } return; } push_down(x); if(l<=node[x<<1].r) updata(x<<1,l,r); if(node[x<<1|1].l<=r) updata(x<<1|1,l,r); push_up(x); while(node[x].max>=k) ff(x,node[x].t); } int main() { // freopen("xiaoqiao.in","r",stdin); // freopen("xiaoqiao.out","w",stdout); long long i; scanf("%lld%lld%lld",&n,&m,&k); for(i=1;i<=n;i++) scanf("%lld%lld%lld",&rst[i].first.first,&rst[i].first.second,&rst[i].second); sort(rst+1,rst+n+1); node[1].l=0,node[1].r=m*2-1,build(1); for(i=n;i>=1;i--) { if(rst[i].first.second==m) rst[i].first.second=-m; if(rst[i].second==-m) rst[i].second=m; sum=0; if(rst[i].first.second>rst[i].second) { updata(1,rst[i].first.second+m,m*2-1); updata(1,0,rst[i].second+m-1); ans+=(long long)(rst[i].first.first*rst[i].first.first*sum); } else { updata(1,rst[i].first.second+m,rst[i].second+m-1); // cout<<"i:"<<i<<" l:"<<rst[i].first.second+m<<" r:"<<rst[i].second+m-1<<endl; ans+=(long long)(rst[i].first.first*rst[i].first.first*sum); if(i==n-1) return 0; } cout<<node[19].t<<endl; return 0; // cout<<"i:"<<i<<" sum:"<<sum<<endl; } cout<<ans; fclose(stdout); return 0; }
分数:$100+100+10=210$