日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Codeforces - 662A 思路巧妙的异或

發布時間:2025/3/21 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces - 662A 思路巧妙的异或 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:給你\(n\)堆石子玩尼姆博弈,每堆石子可以是\(a_i\)也可以是\(b_i\),選擇概率相等且每堆選擇相互獨立,求先手必勝(異或不為0)的概率

首先需要找出一種優雅的策略表示方法(利用異或的思想)
我們需要處理的是\(c_i=a_i \ xor \ b_i\)的線性基,然后用\(S\)代表\(a_i\)的整體異或,那么\(S \ xor \\)(\(c_i\)的任意組合)即可表示原問題的選擇策略
那么原問題首先轉換為\(c_i\)是否可以湊出\(S\)
剩下的我在代碼中已經注釋

PS.窩的天CF才A題就這么可怕的嗎

#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<string> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<bitset> #define rep(i,j,k) for(register int i=j;i<=k;i++) #define rrep(i,j,k) for(register int i=j;i>=k;i--) #define erep(i,u) for(register int i=head[u];~i;i=nxt[i]) #define iin(a) scanf("%d",&a) #define lin(a) scanf("%lld",&a) #define din(a) scanf("%lf",&a) #define s0(a) scanf("%s",a) #define s1(a) scanf("%s",a+1) #define print(a) printf("%lld",(ll)a) #define enter putchar('\n') #define blank putchar(' ') #define println(a) printf("%lld\n",(ll)a) #define IOS ios::sync_with_stdio(0) using namespace std; const int MAXN = 5e5+11; const double EPS = 1e-7; typedef long long ll; typedef unsigned long long ull; const ll MOD = 10086; unsigned int SEED = 17; const ll INF = 1ll<<60; ll read(){ll x=0,f=1;register char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } ll b[66]; int cal(int n,ll a[]){memset(b,0,sizeof b);int cnt=0;rep(i,1,n){rrep(j,62,0){if(a[i]>>j&1){if(b[j]) a[i]^=b[j];else{b[j]=a[i];rrep(k,j-1,0) if(b[k]&&(b[j]>>k&1))b[j]^=b[k];rep(k,j+1,62) if(b[k]>>j&1) b[k]^=b[j];break;}}}}rep(i,0,62) if(b[i]) cnt++;return cnt; } ll A[MAXN],B[MAXN],C[MAXN],n; int main(){while(cin>>n){rep(i,1,n){A[i]=read();B[i]=read();}ll S=0;rep(i,1,n) S^=A[i],C[i]=A[i]^B[i];int cnt=cal(n,C);rep(i,0,62) if(S>>i&1) S^=b[i];//注意如果i位沒有別瞎異或,相當于構造時的插入但不更新的操作if(S){//不在線性基中printf("1/1\n");}else{ll ans=1ll<<cnt; //線性基的所有可能printf("%lld/%lld\n",ans-1,ans); //把唯一存在的異或為S的剔除便是勝率}}return 0; }

轉載于:https://www.cnblogs.com/caturra/p/8975536.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的Codeforces - 662A 思路巧妙的异或的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。