首页 > 代码库 > 2017 UESTC Training for Math
2017 UESTC Training for Math
2017 UESTC Training for Math
A sg博弈水题
#include<bits/stdc++.h>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")#define rep(i,a,b) for (int i=a; i<=b; ++i)#define per(i,b,a) for (int i=b; i>=a; --i)#define mes(a,b) memset(a,b,sizeof(a))#define INF 0x3f3f3f3f#define MP make_pair#define PB push_back#define fi first#define se secondtypedef long long ll;const int N = 10005;int k, s[N], m, mi, a[N], sg[N];bool vis[N];void getSG(){ mes(sg, 0); rep(i,0,N-1) { mes(vis, 0); rep(j,1,k) if(i-s[j]>=0) vis[sg[i-s[j]]]=1; rep(j,0,N-1) if(vis[j]==0) { sg[i]=j; break; } }}int main(){ scanf("%d", &k); rep(i,1,k) scanf("%d", &s[i]); getSG(); scanf("%d", &m); rep(i,1,m) { scanf("%d", &mi); int ans=0; rep(j,1,mi) { scanf("%d", &a[i]); ans ^= sg[a[i]]; } if(ans==0) puts("lose!"); else puts("win!"); } return 0;}
B 求两圆相交的面积模板
#define PI acos(-1.0)struct Circle { double x, y, r; };double dis(Circle a, Circle b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double IntersectionArea_TwoCircles(Circle c1, Circle c2){ double s = dis(c1,c2); if(c1.r<c2.r) swap(c1, c2); if(c1.r+c2.r <= s) return 0; else if(s <= c1.r-c2.r) return PI*c2.r*c2.r; else { double ang1 = acos((c1.r*c1.r+s*s-c2.r*c2.r)/(2*c1.r*s)); double ang2 = acos((c2.r*c2.r+s*s-c1.r*c1.r)/(2*c2.r*s)); return ang1*c1.r*c1.r + ang2*c2.r*c2.r - c2.r*s*sin(ang2); }}
E 水题
#include<bits/stdc++.h>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")#define rep(i,a,b) for (int i=a; i<=b; ++i)#define per(i,b,a) for (int i=b; i>=a; --i)#define mes(a,b) memset(a,b,sizeof(a))#define INF 0x3f3f3f3f#define MP make_pair#define PB push_back#define fi first#define se secondtypedef long long ll;const int N = 200005;ll A(int n, int m){ ll ans = 1; rep(i,n-m+1,n) ans *= i; return ans;}int main(){ int n; scanf("%d", &n); printf("%lld\n", A(n,n)/n*A(n,n)); return 0;}
L 第二类斯特林数
题意: n 个人放在 k个相同的篝火中,问有多少种方案。
tags:参考大神博客
类似于dp递推,dp[i][j]表示 i 个物体放入 j 个盒子的方案数,则 dp[i][j] = j * dp[i-1][j] + dp[i-1][j-1] 。
#include<bits/stdc++.h>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")#define rep(i,a,b) for (int i=a; i<=b; ++i)#define per(i,b,a) for (int i=b; i>=a; --i)#define mes(a,b) memset(a,b,sizeof(a))#define INF 0x3f3f3f3f#define MP make_pair#define PB push_back#define fi first#define se secondtypedef long long ll;const int N = 1005, mod = 1e9+7;ll dp[N][N], n, k;int main(){ rep(i,1,N-1) dp[i][1]=1; rep(i,2,N-1) rep(j,1,N-1) { dp[i][j] = (j*dp[i-1][j]+dp[i-1][j-1]) %mod; } int T; scanf("%d", &T); while(T--) { scanf("%lld %lld", &n, &k); printf("%lld\n", (dp[n][k]+mod)%mod); } return 0;}
2017 UESTC Training for Math
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。