Divide by Zero 2017 D&E&F
Posted 弥生三月
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Divide by Zero 2017 D&E&F相关的知识,希望对你有一定的参考价值。
唔,D:概率最多是 $ \frac{1}{2} $ ,在n==1000的时候这个阈值大概是7284,O(7284n)即可
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <algorithm> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <map> 9 #include <stack> 10 #include <set> 11 #include <vector> 12 #include <queue> 13 #include <time.h> 14 #define eps 1e-7 15 #define INF 0x3f3f3f3f 16 #define MOD 1000000007 17 #define rep0(j,n) for(int j=0;j<n;++j) 18 #define rep1(j,n) for(int j=1;j<=n;++j) 19 #define pb push_back 20 #define set0(n) memset(n,0,sizeof(n)) 21 #define ll long long 22 #define ull unsigned long long 23 #define iter(i,v) for(edge *i=head[v];i;i=i->nxt) 24 #define max(a,b) (a>b?a:b) 25 #define min(a,b) (a<b?a:b) 26 #define print_runtime printf("Running time:%.3lfs\n",double(clock())/1000.0) 27 #define TO(j) printf(#j": %d\n",j); 28 //#define OJ 29 using namespace std; 30 const int MAXINT = 100010; 31 const int MAXNODE = 100010; 32 const int MAXEDGE = 2*MAXNODE; 33 char BUF,*buf; 34 int read(){ 35 char c=getchar();int f=1,x=0; 36 while(!isdigit(c)){if(c==‘-‘) f=-1;c=getchar();} 37 while(isdigit(c)){x=x*10+c-‘0‘;c=getchar();} 38 return f*x; 39 } 40 char get_ch(){ 41 char c=getchar(); 42 while(!isalpha(c)) c=getchar(); 43 return c; 44 } 45 //------------------- Head Files ----------------------// 46 int n,k; 47 double dp[7300][1001],prop[20000]; 48 49 void get_input(); 50 void work(); 51 int main() { 52 get_input(); 53 work(); 54 return 0; 55 } 56 void work(){ 57 dp[0][0] = 1; 58 for(int i=1;i<7300;i++){ 59 for(int j=0;j<=n;j++){ 60 dp[i][j]=dp[i-1][j]*j/double(n); 61 if(j!=0) dp[i][j]+=dp[i-1][j-1]*(n-j+1)/double(n); 62 } 63 } 64 rep0(i,7300) prop[i]=dp[i][n]; 65 while(k--){ 66 int p = read(); 67 printf("%d\n",lower_bound(prop,prop+7300,(p-eps)/2000.0)-prop); 68 } 69 } 70 void get_input(){ 71 n=read();k=read(); 72 }
E:考虑一下最原始的nim游戏里每堆石子数量的意义,它的意思是这堆石子可以在1,2,3..n次内取完,并且这个信息支持减法,然后这题里的这个规则好像也是这个意思,事实上每一个有这种限制的石碓可以映射到一个原来的石碓上,即 $ sg(n) = t (\sum_{i=1}^{t} \leqslant n < \sum_{i=1}^{t+1}) $ ,然后直接异或起来即可
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <algorithm> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <map> 9 #include <stack> 10 #include <set> 11 #include <vector> 12 #include <queue> 13 #include <time.h> 14 #define eps 1e-7 15 #define INF 0x3f3f3f3f 16 #define MOD 1000000007 17 #define rep0(j,n) for(int j=0;j<n;++j) 18 #define rep1(j,n) for(int j=1;j<=n;++j) 19 #define pb push_back 20 #define set0(n) memset(n,0,sizeof(n)) 21 #define ll long long 22 #define ull unsigned long long 23 #define iter(i,v) for(edge *i=head[v];i;i=i->nxt) 24 #define max(a,b) (a>b?a:b) 25 #define min(a,b) (a<b?a:b) 26 #define print_runtime printf("Running time:%.3lfs\n",double(clock())/1000.0) 27 #define TO(j) printf(#j": %d\n",j); 28 //#define OJ 29 using namespace std; 30 const int MAXINT = 100010; 31 const int MAXNODE = 100010; 32 const int MAXEDGE = 2*MAXNODE; 33 char BUF,*buf; 34 int read(){ 35 char c=getchar();int f=1,x=0; 36 while(!isdigit(c)){if(c==‘-‘) f=-1;c=getchar();} 37 while(isdigit(c)){x=x*10+c-‘0‘;c=getchar();} 38 return f*x; 39 } 40 char get_ch(){ 41 char c=getchar(); 42 while(!isalpha(c)) c=getchar(); 43 return c; 44 } 45 //------------------- Head Files ----------------------// 46 47 int sg[500],v,n; 48 void get_input(); 49 void work(); 50 int main() { 51 get_input(); 52 work(); 53 return 0; 54 } 55 void work(){ 56 if(v) printf("NO\n"); else printf("YES\n"); 57 } 58 void get_input(){ 59 for(int i=1;i<13;i++){ 60 for(int j=i*(i+1)/2;j<(i+2)*(i+1)/2;j++){ 61 sg[j]=i; 62 } 63 } 64 n=read(); 65 rep0(i,n){ 66 int t=read(); 67 v^=sg[t]; 68 } 69 }
F:唔,枚举架子的数量,然后对于某一个确定的架子数量n,分类大力讨论,插板法计数即可,总数直接插板,合法的数量就是先从w里减掉堆数*h再插板
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <algorithm> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <map> 9 #include <stack> 10 #include <set> 11 #include <vector> 12 #include <queue> 13 #include <time.h> 14 #define eps 1e-7 15 #define INF 0x3f3f3f3f 16 #define MOD 1000000007 17 #define rep0(j,n) for(int j=0;j<n;++j) 18 #define rep1(j,n) for(int j=1;j<=n;++j) 19 #define pb push_back 20 #define set0(n) memset(n,0,sizeof(n)) 21 #define ll long long 22 #define ull unsigned long long 23 #define iter(i,v) for(edge *i=head[v];i;i=i->nxt) 24 #define print_runtime printf("Running time:%.3lfs\n",double(clock())/1000.0) 25 #define TO(j) printf(#j": %d\n",j); 26 //#define OJ 27 using namespace std; 28 const int MAXINT = 100010; 29 const int MAXNODE = 100010; 30 const int MAXEDGE = 2*MAXNODE; 31 char BUF,*buf; 32 int read(){ 33 char c=getchar();int f=1,x=0; 34 while(!isdigit(c)){if(c==‘-‘) f=-1;c=getchar();} 35 while(isdigit(c)){x=x*10+c-‘0‘;c=getchar();} 36 return f*x; 37 } 38 char get_ch(){ 39 char c=getchar(); 40 while(!isalpha(c)) c=getchar(); 41 return c; 42 } 43 //------------------- Head Files ----------------------// 44 45 ll cnt_t,cnt_g; 46 ll fact[100010],df[100010]; 47 ll f,w,h; 48 ll fp(ll b,ll u){ 49 ll ans = 1; 50 for(;u;b=b*b%MOD,u>>=1) if(u&1) ans=ans*b%MOD; 51 return ans; 52 } 53 ll C(ll n,ll m){ 54 if(m>n) return 0; 55 return (fact[n]*df[m]%MOD)*df[n-m]%MOD; 56 } 57 void add(ll &a,ll b){ 58 a=(a+b)%MOD; 59 } 60 void get_input(); 61 void work(); 62 int main() { 63 get_input(); 64 work(); 65 return 0; 66 } 67 void work(){ 68 fact[0]=1; 69 rep1(i,100000) fact[i]=fact[i-1]*i%MOD; 70 rep0(i,100001) df[i] = fp(fact[i],MOD-2); 71 //printf("%lld\n",df[0]); 72 for(int i=1;1;i++){ 73 if(i>f+w||i>min(f,w)*2+1) break; 74 75 if(i==1){ 76 if(f==0||w==0) cnt_t++; 77 if(w==0||(f==0&&w>h)) cnt_g++; 78 }else{ 79 if(i&1){ 80 add(cnt_t,C(f-1,i/2)*C(w-1,i/2-1)); 81 add(cnt_t,C(f-1,i/2-1)*C(w-1,i/2)); 82 add(cnt_g,C(f-1,i/2)*C(w-1-i/2*h,i/2-1)); 83 add(cnt_g,C(f-1,i/2-1)*C(w-1-(i/2+1)*h,i/2)); 84 }else{ 85 add(cnt_t,(C(f-1,i/2-1)*C(w-1,i/2-1)%MOD)*2); 86 add(cnt_g,(C(f-1,i/2-1)*C(w-1-(i/2)*h,i/2-1)%MOD)*2); 87 } 88 } 89 //printf("%d %lld\n",i,cnt_t); 90 } 91 //printf("%lld\n",cnt_t); 92 printf("%lld\n",cnt_g*fp(cnt_t,MOD-2)%MOD); 93 } 94 void get_input(){ 95 f=read();w=read();h=read(); 96 }
以上是关于Divide by Zero 2017 D&E&F的主要内容,如果未能解决你的问题,请参考以下文章
CWE-369:Divide By Zero除数有可能为零缺陷是如何产生的?
Divide by Zero 2021 and Codeforces Round #714 (Div. 2) ABC题解
Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)G - Bandit Blues
Divide by Zero 2021 and Codeforces Round #714 (Div. 2) C Add One题解(预处理)(详细注释)
An error can be caused by attempting to divide by 0的解释
Codeforces Round #479 (Div. 3) D. Divide by three, multiply by two