Codeforces Round #253 (Div. 1)-A,B
阿新 • • 發佈:2017-05-22
clas efi 狀態 ng- char oid out urn esp
B題:
A題:
由題意可知,最多翻10次就能夠(事實上8次就夠了)。那麽我們就用狀態壓縮表示狀態。
對於某種狀態,假設某一位為0,那麽代表這一位不翻,否則代表這一位翻。
對於某一種翻的狀態:
假設牌中有G3,那麽就把G和3進行連邊。
其它的連邊類似。不要重邊。
對於隨意一條邊的兩個端點。分三種情況討論:
1。兩個端點都翻了,那麽非常明顯,這張牌被表示出來了。
2,兩個端點中僅僅有一個端點被翻。那麽這個相應的num加1.
3,兩個端點都沒有被翻,計數器tt加1。
對於隨意一種狀態:
1,假設計數器tt大於1,那麽肯定不能推斷出全部的牌。
2。假設隨意一個端點的num數大於1。那麽也肯定不能推斷出全部的牌。
3。否則的話,這樣的狀態能夠表示出全部的牌。
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<vector> using namespace std; #define LL __int64 #define maxn 2201 int num[20]; int pan[220]; int name[22001]; vector<int>vec; int map[110][110]; void dos(int x) { while(x) { cout<<x%2; x=x/2; } cout<<endl; } int main() { int n,l,r,x,y; char str[1010]; pan[‘R‘]=6; pan[‘G‘]=7; pan[‘B‘]=8; pan[‘Y‘]=9; pan[‘W‘]=5; while(~scanf("%d",&n)) { memset(num,0,sizeof(num)); memset(name,0,sizeof(name)); memset(map,0,sizeof(map)); l=r=0; for(int i=1; i<=n; i++) { scanf("%s",str); x=pan[str[0]]; y=str[1]-‘1‘; map[x][y]++; map[y][x]++; } int st=0; int minn =10; for(int st=0; st<(1<<10); st++) { int ss=0; for(int j=0; j<10; j++) { if(st&(1<<j))ss++; } if(ss>=minn)continue; int leap=0; int t=0; memset(num,0,sizeof(num)); for(int j=5; j<10; j++) { for(int i=0; i<5; i++) { if(map[i][j]) { if((st&(1<<i))&&(st&(1<<j)))continue; if((st&(1<<i))||(st&(1<<j))) { if(st&(1<<i)) { if(!num[i]) { num[i]++; continue; } } if((st&(1<<j))) { if(!num[j]) { num[j]++; continue; } } } else { if(t==0) { t++; continue; } } leap++; } } } if(!leap) { minn=min(minn,ss); // cout<<" "<<ss<<" "; // dos(st); } } cout<<minn<<endl; } return 0; }
對於當前選擇的狀態,
p0表示0個人告訴答案的概率。
p1表示1個人告訴答案的概率。
對於即將面對的一個人:
a表示0個人告訴答案的概率。
b表示1個人告訴答案的概率。
假設接納這個人之後,p1的值變小了。那麽就不應該接納下去。
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<vector> using namespace std; #define LL __int64 #define maxn 2201 double num[maxn]; int main() { int n; double x; while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) { scanf("%lf",&num[i]); } sort(num+1,num+n+1); double ans=0; double a=1; double c,d; double b=0; for(int i=n;i>=1;i--) { c=a; d=b; b=b+a*num[i]-b*num[i]; a=a-a*num[i]; if(b<d) { b=d; break; } } printf("%.10lf\n",b); } return 0; }
Codeforces Round #253 (Div. 1)-A,B