您的位置:首页 > 游戏 > 游戏 > SMU Summer 2024 Contest Round 7

SMU Summer 2024 Contest Round 7

2024/10/6 22:24:36 来源:https://blog.csdn.net/xiaofu123456789_/article/details/140712211  浏览:    关键词:SMU Summer 2024 Contest Round 7

Bouquet

思路:

总的方案数就是C(n,1)+C(n,2)+ . . . . +C(n,n) = 2^{n}-1;然后不符合的方案数为C(n,a)+C(n,b);

两者相减就是答案;因为算组合数时,数据非常大,所以要用到lucas定理来计算组合数的大小;

当同余定理用于减法的时候尽量在减完之后再加上模数,防止出现负数

由于求组合数的时候最后要除一下,需要使用逆元,由于 mod 是一个质数,a × b^{mod-2} mod 10^9

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
const int p=1e9+7;
int qm(int a,int k){//快速幂int res=1;while(k){if(k&1) res=res*a%p;a=a*a%p;k>>=1;}return res;
}
int getc(int n,int m){//求排列组合cint res=1;for(int i=1,j=n;i<=m;i++,j--){res=res*j%p;res=res*qm(i,p-2)%p;//逆元,由于 mod 是一个质数,a × b^{mod-2} mod 10^9}return res;
}
int lucas(int n,int m){if(n<p&&m<p) return getc(n,m);return lucas(n/p,m/p)*getc(n%p,m%p)%p;
}
void solve()
{int a,b,l;cin>>l>>a>>b;cout<<(qm(2,l)-(lucas(l,a)%p+lucas(l,b)%p)%p-1+p)%p<<endl;
}signed main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int t=1;
//    cin>>t;while(t -- ){solve();}return 0;
}

String Cards

思路:

代码:

Game on Ranges

思路:每次输入时,将该区间中每一个数的价值加一,每个区间,只需要输出价值最小的点,然后不断递推即可。

代码:

#include<bits/stdc++.h>
using namespace std;
int t;
int n;
int p[1010];
void dp(int l,int r,int step)
{if (l == r) {cout<<l<<" "<<l<<" "<<l<<endl; return;}int temp;for (int k = l; k <= r; k++) {if (p[k] == step) {temp = k; break;}}cout<<l<<" "<<r<<" "<<temp<<endl;if (l == temp||r==temp) {if(l==temp&&r==temp)dp(temp, temp, step + 1);else if (temp == l && temp != r)dp(temp + 1, r, step + 1);else if (temp == r && temp != l)dp(l, temp - 1, step + 1);}else {dp(l, temp - 1, step + 1);dp(temp + 1, r, step + 1);}return;
}
int main()
{cin>>t;while (t--) {cin>>n;int tep = n;memset(p, 0, sizeof(p));while (n--) {int a, b;cin>>a>>b;for (int i = a; i <= b; i++)p[i]++;}dp(1,tep,1);}return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com