• M-SOLUTIONS Programming Contest


      A:签到。我wa了一发怎么办啊。

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define inf 1000000010
    char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
    int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
    int read()
    {
    	int x=0,f=1;char c=getchar();
    	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    	return x*f;
    }
    signed main()
    {
    	int n=read();
    	cout<<(n-2)*180;
    	return 0;
    	//NOTICE LONG LONG!!!!!
    }
    

      B:签到。

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define inf 1000000010
    char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
    int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
    int read()
    {
    	int x=0,f=1;char c=getchar();
    	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    	return x*f;
    }
    char s[20];
    signed main()
    {
    	scanf("%s",s+1);
    	int cnt=0;
    	for (int i=1;i<=strlen(s+1);i++) if (s[i]=='x') cnt++;
    	if (cnt>=8) cout<<"NO";else cout<<"YES";
    	return 0;
    	//NOTICE LONG LONG!!!!!
    }
    

      C:考虑枚举最后两人各胜多少局。注意到期望每100/(100-C)局就会决出一次胜负,于是只需要考虑该种胜负局数出现概率。不妨设第一个人赢了n场输了x场,那么概率就是C(n+x-1,n-1)·An·Bx/(A+B)n+x,累加即可。

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define inf 1000000010
    #define N 100010
    #define P 1000000007
    char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
    int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
    int read()
    {
    	int x=0,f=1;char c=getchar();
    	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    	return x*f;
    }
    int n,A,B,C,f[1000][1000],fac[N<<1],Inv[N<<1],ans;
    int ksm(int a,int k)
    {
    	int s=1;
    	for (;k;k>>=1,a=1ll*a*a%P) if (k&1) s=1ll*s*a%P;
    	return s;
    }
    int inv(int a){return ksm(a,P-2);}
    void inc(int &x,int y){x+=y;if (x>=P) x-=P;}
    int calc(int n,int m){if (m>n) return 0;return 1ll*fac[n]*Inv[m]%P*Inv[n-m]%P;}
    signed main()
    {
    	n=read(),A=read(),B=read(),C=read();A=1ll*A*inv(100-C)%P,B=1ll*B*inv(100-C)%P;
    	fac[0]=1;for (int i=1;i<=2*n;i++) fac[i]=1ll*fac[i-1]*i%P;
    	Inv[0]=Inv[1]=1;for (int i=2;i<=2*n;i++) Inv[i]=P-1ll*(P/i)*Inv[P%i]%P;
    	for (int i=2;i<=2*n;i++) Inv[i]=1ll*Inv[i]*Inv[i-1]%P;
    	for (int i=0;i<n;i++)
    	{
    		int p1=1ll*A%P*calc(n+i-1,n-1)%P*ksm(A,n-1)%P*ksm(B,i)%P;
    		int p2=1ll*B%P*calc(n+i-1,n-1)%P*ksm(B,n-1)%P*ksm(A,i)%P;
    		inc(ans,1ll*(n+i)*100%P*inv(100-C)%P*(p1+p2)%P);
    	}
    	cout<<ans;
    	return 0;
    	//NOTICE LONG LONG!!!!!
    }
    

      D:大胆猜想从小到大填每次选(未被占用)度数最小的点即可。

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define inf 1000000010
    #define N 10010
    char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
    int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
    int read()
    {
    	int x=0,f=1;char c=getchar();
    	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    	return x*f;
    }
    int n,p[N],a[N],degree[N],val[N],t,ans;
    struct data{int to,nxt;
    }edge[N<<1];
    void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
    signed main()
    {
    	n=read();
    	for (int i=1;i<n;i++)
    	{
    		int x=read(),y=read();
    		addedge(x,y),addedge(y,x);
    		degree[x]++,degree[y]++;
    	}
    	for (int i=1;i<=n;i++) a[i]=read();
    	sort(a+1,a+n+1);
    	for (int i=1;i<=n;i++)
    	{
    		int mn=n;
    		for (int j=1;j<=n;j++)
    		if (val[j]==0) mn=min(mn,degree[j]);
    		for (int j=1;j<=n;j++)
    		if (val[j]==0&&degree[j]==mn) {mn=j;break;}
    		val[mn]=a[i];ans+=degree[mn]*a[i];
    		for (int j=p[mn];j;j=edge[j].nxt)
    		degree[edge[j].to]--;
    	}
    	cout<<ans<<endl;
    	for (int i=1;i<=n;i++) cout<<val[i]<<' ';
    	return 0;
    	//NOTICE LONG LONG!!!!!
    }
    

      E:每一项都除掉d。特判d=0。无所事事了1h后在最后20s想到了做法。

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define inf 1000000010
    #define P 1000003
    char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
    int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
    int read()
    {
    	int x=0,f=1;char c=getchar();
    	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    	return x*f;
    }
    int Q,fac[P],inv[P];
    int ksm(int a,int  k)
    {
    	int s=1;
    	for (;k;k>>=1,a=1ll*a*a%P) if (k&1) s=1ll*s*a%P;
    	return s;
    }
    int I(int a){return ksm(a,P-2);}
    signed main()
    {
    	Q=read();
    	fac[0]=1;for (int i=1;i<P;i++) fac[i]=1ll*fac[i-1]*i%P;
    	inv[0]=inv[1]=1;for (int i=2;i<P;i++) inv[i]=P-1ll*(P/i)*inv[P%i]%P;
    	for (int i=2;i<P;i++) inv[i]=1ll*inv[i-1]*inv[i]%P;
    	while (Q--)
    	{
    		int x=read(),d=read(),n=read();
    		if (d==0) {printf("%d
    ",ksm(x,n));continue;}
    		x=1ll*x*I(d)%P;
    		if (x+n-1>=P) printf("%d
    ",0);
    		else printf("%d
    ",1ll*fac[x+n-1]*(x==0?1:inv[x-1])%P*ksm(d,n)%P);
    	}
    	return 0;
    	//NOTICE LONG LONG!!!!!
    } 
    

      result:rank 191 rating +9

  • 相关阅读:
    [ARC117F]Gateau
    [ARC117D]Miracle Tree
    [loj3504]支配
    [gym102511K]Traffic Blights
    [loj3501]图函数
    [loj3503]滚榜
    [loj3500]矩阵游戏
    [loj2135]幻想乡战略游戏
    [cf720D]Slalom
    [cf1349E]Slime and Hats
  • 原文地址:https://www.cnblogs.com/Gloid/p/10962016.html
Copyright © 2020-2023  润新知