noip模擬77(三元環待補)
阿新 • • 發佈:2021-10-17
「最大或·答題·聯合權值·主僕見證了 Hobo 的離別」
A. 最大或
簽到題,隨便寫.
A_code
#include<bits/stdc++.h> using namespace std; namespace BSS { #define ll long long int #define ull unsigned ll #define lf long double #define lbt(x) (x&(-x)) #define mp(x,y) make_pair(x,y) #define lb lower_bound #define ub upper_bound #define Fill(x,y) memset(x,y,sizeof x) #define Copy(x,y) memcpy(x,y,sizeof x) #define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) inline ll read() { ll w=0; bool cit=1; char ch; while(!isdigit(ch=getchar())) if(ch=='-') cit=0; while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar(); return cit?w:-w; } } using namespace BSS; const ll Inf=1e18,N=70; ll L,R,cnt; ll val[N]; inline void Pre(){ val[++cnt]=1; for(ll i=1;(1ll<<i-1)<=Inf;i++) val[++cnt]=1ll<<i; } auto Work=[]()->void{ ll res=0,l=read(),r=read(); for(ll i=cnt;i>=0;i--){ if(((1ll<<i-1)&r)==((1ll<<i-1)&l)) res|=((1ll<<i-1)&r); else{ res|=(1ll<<i)-1; break; } } printf("%lld\n",res); }; signed main(){ File(maxor); Pre(); for(int Ts=read();Ts;Ts--) Work(); exit(0); }
B. 答題
簽到題,隨便寫.
B_code
#include<bits/stdc++.h> using namespace std; namespace BSS { #define ll long long #define ull unsigned ll #define lf double #define lbt(x) (x&(-x)) #define mp(x,y) make_pair(x,y) #define lb lower_bound #define ub upper_bound #define Fill(x,y) memset(x,y,sizeof x) #define Copy(x,y) memcpy(x,y,sizeof x) #define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) inline ll read() { ll w=0; bool cit=1; char ch; while(!isdigit(ch=getchar())) if(ch=='-') cit=0; while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar(); return cit?w:-w; } } using namespace BSS; const ll N=45,W=(1ll<<20)+501; lf p; ll m,n,U,cnt1,cnt2,alls; ll val[45],pre[45],dp[40051]; ll bin1[W],bin2[W]; inline void Work1(){ sort(val+1,val+1+n),dp[0]=1; for(ll i=1;i<=n;i++){ for(ll j=pre[i];j>=val[i];j--) dp[j]+=dp[j-val[i]]; } ll res=ceil((1ll<<n)*p); for(ll i=0;i<=pre[n];i++){ if(res<=dp[i]) printf("%lld\n",i),exit(0); res-=dp[i]; } exit(0); } auto check=[](ll x)->bool{ ll res=0; // cout<<"x:"<<x<<endl; for(ll p1=1,p2=cnt2;p1<=cnt1;p1++){ while(p2 and bin1[p1]+bin2[p2]>x) p2--; if(bin1[p1]+bin2[p2]<=x) res+=p2; } return (1.0*res)/((lf)alls)>=p; }; inline void Work2(){ ll mid=n>>1,lft=n-mid,S=(1<<mid)-1,T=(1<<lft)-1,res; for(ll i=0;i<=S;i++){ res=0; for(ll j=1;j<=mid;j++) if((i>>j-1)&1) res+=val[j]; bin1[++cnt1]=res; } for(ll i=0;i<=T;i++){ res=0; for(ll j=1;j<=lft;j++) if((i>>j-1)&1) res+=val[j+mid]; bin2[++cnt2]=res; } sort(bin1+1,bin1+1+cnt1),sort(bin2+1,bin2+1+cnt2); // for(ll i=1;i<=cnt1;i++) cout<<bin1[i]<<' '; puts(" der"); // for(ll i=1;i<=cnt2;i++) cout<<bin2[i]<<' '; puts(" skr"); ll l=0,r=pre[n],mi; res=r,alls=1ll<<n; while(l<=r){ mi=(l+r)>>1; if(check(mi)) res=mi,r=mi-1; else l=mi+1; } printf("%lld\n",res),exit(0); } signed main(){ File(answer); ll flag=1; n=read(),scanf("%lf",&p),U=(1ll<<n)-1,p=min(1.0,p); for(ll i=1;i<=n;i++){ pre[i]=pre[i-1]+(val[i]=read()); flag&=(val[i]<=1000); } Work2() ; exit(0); }
C. 聯合權值
資料水,考場上 \(bitset\) 亂過了,正解還沒打,程式碼就先不粘了.
C_code
D. 主僕見證了 Hobo 的離別
發現自己看懂了題目之後忘了好多條件.
感覺這題並不是特別難寫,考場上仔細思考應該是能想到.
這樣的題畫圖手玩一下就可以了叭..
D_code
#include<bits/stdc++.h> using namespace std; namespace BSS { #define ll int #define ull unsigned ll #define lf long double #define lbt(x) (x&(-x)) #define mp(x,y) make_pair(x,y) #define lb lower_bound #define ub upper_bound #define Fill(x,y) memset(x,y,sizeof x) #define Copy(x,y) memcpy(x,y,sizeof x) #define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) inline ll read() { ll w=0; bool cit=1; char ch; while(!isdigit(ch=getchar())) if(ch=='-') cit=0; while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar(); return cit?w:-w; } } using namespace BSS; const ll N=1e6+21; ll n,m,ops,ts,ids,cnt; ll head[N],dfn[N],F[N],con[N],siz[N]; struct II { ll u,v,nxt; } e[N<<1]; struct III { ll x,y; } q[N]; auto add=[](ll u,ll v)->void{ e[++ts].u=u,e[ts].v=v; e[ts].nxt=head[u],head[u]=ts; }; struct Dsu{ ll fa[N]; ll find(ll x){ return x==fa[x] ? x : (fa[x]=find(fa[x])) ; } }A,B; void dfs(ll u){ dfn[u]=++cnt,siz[u]=1; (con[u]&1) ? A.fa[u]=A.find(F[u]) : A.fa[u]=u ; (con[u]&2) ? B.fa[u]=B.find(F[u]) : B.fa[u]=u ; // cout<<u<<' '<<A.fa[u]<<' '<<B.fa[u]<<' '<<dfn[u]<<endl; for(ll i=head[u];i;i=e[i].nxt){ dfs(e[i].v),siz[u]+=siz[e[i].v]; } } signed main(){ File(friendship); n=read(),ids=n; ll x,y,opt; for(int Ts=read();Ts;Ts--){ if(opt=read()) q[++ops].x=read(),q[ops].y=read(); else{ opt=read(),y=read(),ids++; if(y==1){ x=read(),add(ids,x),F[x]=ids,con[x]=3; continue; } for(ll i=1;i<=y;i++) x=read(),add(ids,x),F[x]=ids,con[x]=opt+1; } } for(ll i=1;i<=ids;i++) if(!F[i]) dfs(i); // for(ll i=1;i<=ids;i++) cout<<dfn[i]<<' '<<siz[i]<<endl; for(ll i=1;i<=ops;i++){ x=q[i].x,y=q[i].y; if(dfn[x]<=dfn[y] and dfn[x]+siz[x]>dfn[y]){ printf("%d\n",(int)(A.find(x)==A.find(y))); continue; } if(dfn[y]<=dfn[x] and dfn[y]+siz[y]>dfn[x]){ printf("%d\n",(int)(B.find(x)==B.find(y))); continue; } puts("0"); } exit(0); }