【NOIp2019模拟】题解
T1
傻逼题,速度的函数是收敛的,一个等比数列求和就完了
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define pb push_back
#define re register
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define cs const
cs double pi=acos(-1);
double thi,v,d,g,vx,vy,t;
int main(){
int T=read();
while(T--){
scanf("%lf%lf%lf%lf",&thi,&v,&d,&g);
thi=thi/180.0;
vx=v*cos(pi*thi),vy=v*sin(pi*thi);
t=vy/(1.0-d*d),t/=g,t=t*2;
printf("%.5lf\n",t*vx);
}
}
T2:
水题
考虑说可以发现我们要把所有奇数拿出来
考虑说一个数不断乘到有几个数
如果是偶数个就给个集合相同的贡献
奇数个就会有一个集合多
最后要2个集合分别是和
选数的方案就是一个组合数
用卢卡斯定理做一下就完了
结果无解的情况少判了一个为负
挂成
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
#define int long long
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define pb push_back
#define re register
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define cs const
cs int mod=10000019;
inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
inline void Add(int &a,int b){(a+=b)>=mod?a-=mod:0;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline void Dec(int &a,int b){(a-=b)<0?a+=mod:0;}
inline int mul(int a,int b){return 1ll*a*b>=mod?1ll*a*b%mod:a*b;}
inline void Mul(int &a,int b){a=1ll*a*b>=mod?1ll*a*b%mod:a*b;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(res=mul(res,a));return res;}
int fac[mod+100],ifac[mod+100];
int n,q,m;
inline void init(){
fac[0]=ifac[0]=1;
for(int i=1;i<mod;i++)fac[i]=mul(fac[i-1],i);
ifac[mod-1]=ksm(fac[mod-1],mod-2);
for(int i=mod-2;i;i--)ifac[i]=mul(ifac[i+1],i+1);
}
inline int C(int n,int m){
return n<m?0:mul(fac[n],mul(ifac[m],ifac[n-m]));
}
inline int Lucas(int n,int m){
if(n<m)return 0;
if(n<mod&&m<mod)return C(n,m);
return mul(Lucas(n/mod,m/mod),C(n%mod,m%mod));
}
int sip,plx;
inline int howmany(int l,int r){
int del=r-l+1;
if(del&1)return (del/2)+((l&1)==1);
return del/2;
}
inline void divid(int x){
int r=x,l,cur=1;
while(r){
l=r/2+1;
if(cur)sip+=howmany(l,r);
else plx+=howmany(l,r);
r=l-1,cur^=1;
}
}
signed main(){
init();
n=read(),q=read();
divid(n);
int bas=ksm(2,plx);
while(q--){
m=read();
int del=sip+m+m-n;
if(del&1){cout<<0<<'\n';continue;}
if(del<0){cout<<0<<'\n';continue;}
del/=2;
cout<<mul(bas,Lucas(sip,del))<<'\n';
}
}
T3:
傻逼题
和二分图差不多,对于连断每次乘逆元就可以了
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define pb push_back
#define re register
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define cs const
cs int mod=1e9+7;
inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
inline void Add(int &a,int b){(a+=b)>=mod?a-=mod:0;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline void Dec(int &a,int b){(a-=b)<0?a+=mod:0;}
inline int mul(int a,int b){return 1ll*a*b>=mod?1ll*a*b%mod:a*b;}
inline void Mul(int &a,int b){a=1ll*a*b>=mod?1ll*a*b%mod:a*b;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(res=mul(res,a));return res;}
cs int N=100005;
int n,m,ans;
int inv[N],anc[N];
inline void init(){
inv[0]=inv[1]=1;
for(int i=2;i<=n;i++)inv[i]=mul(mod-mod/i,inv[mod%i]);
}
namespace Set{
int fa[N],siz[N],top;
pii stk[N];
inline void init(){
for(int i=1;i<=n;i++)fa[i]=i,siz[i]=1;
}
inline int find(int x){
return fa[x]==x?x:find(fa[x]);
}
inline void merge(int u,int v){
int f1=find(u),f2=find(v);
if(f1!=f2){
if(siz[f1]>siz[f2])swap(f1,f2);
Mul(ans,inv[siz[f1]]),Mul(ans,inv[siz[f2]]);
fa[f1]=f2,siz[f2]+=siz[f1];
Mul(ans,siz[f2]);
stk[++top]=pii(f1,f2);
}
}
inline void getback(int pre){
static int u,v;
while(top>pre){
u=stk[top].fi,v=stk[top].se;
Mul(ans,inv[siz[v]]);
fa[u]=u,siz[v]-=siz[u];
Mul(ans,siz[u]),Mul(ans,siz[v]);
top--;
}
}
}
map<pii,int> tt;
vector<pii> e[N<<2];
#define lc (u<<1)
#define rc ((u<<1)|1)
#define mid ((l+r)>>1)
void update(int u,int l,int r,int st,int des,pii k){
if(st<=l&&r<=des){e[u].pb(k);return;}
if(st<=mid)update(lc,l,mid,st,des,k);
if(mid<des)update(rc,mid+1,r,st,des,k);
}
void dfs(int u,int l,int r){
int pre=Set::top;
for(int i=0;i<e[u].size();i++){
pii x=e[u][i];
Set::merge(x.fi,x.se);
}
if(l==r){anc[l]=ans;}
else dfs(lc,l,mid),dfs(rc,mid+1,r);
Set::getback(pre);
}
vector<pii> E;
int main(){
n=read(),m=read();
Set::init();
init(),ans=1;
for(int i=1;i<=m;i++){
int op=read();
if(op==1){
int u=read(),v=read();
if(u>v)swap(u,v);
tt[pii(u,v)]=i;
E.pb(pii(u,v));
}
else{
int u=read(),v=read();
if(u>v)swap(u,v);
update(1,1,m,tt[pii(u,v)],i-1,pii(u,v));
tt.erase(pii(u,v));
}
}
for(int i=0;i<E.size();i++){
pii x=E[i];
if(tt.count(x))update(1,1,m,tt[x],m,x),tt.erase(x);
}
dfs(1,1,m);
for(int i=1;i<=m;i++)cout<<anc[i]<<"\n";
}