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  second
typedef 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  second
typedef 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  second
typedef 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;
}

时间: 2024-07-29 16:02:19

2017 UESTC Training for Math的相关文章

2017 UESTC Training for Data Structures

2017 UESTC Training for Data Structures A    水,找区间极差,RMQ怼上去. #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&

2017 UESTC Training for Search Algorithm &amp; String

2017 UESTC Training for Search Algorithm & String A   next[]数组应用 题意:求一个字符串所有前缀出现的次数和. tags:  dp[i-1] = dp[next[i]] + 1. D   字符串next[]数组 题意:求给出字符串的最短循环节. tags:看了题解,原来next[]数组可以这样搞.. 思考KMP的next数组的定义:next[j] = i 代表 s[1...(i-1)] = s[j - i, j-1]. 并且i~j之间已

2017 UESTC Training for Dynamic Programming

2017 UESTC Training for Dynamic Programming A    思维, 或 dp, 很有意思 方法1: 构造法:蛇形安排赛程表算法复杂度:O(N^2)将1-N排成两竖列,每一轮同一行的为对手保持1的位置不变,其他位置按顺(逆)时方向依次旋转1    6          1    2          1    3          1    4          1    5      2    5          3    6          4   

2017 UESTC Training for Graph Theory

2017 UESTC Training for Graph Theory A       思维 题意:给你一个有n个点和m条边的无向连通图,每条边都有一个权值w.我们定义,对于一条路径,它的Charm value为该路径上所有边的权值的最大值与最小值的差.询问从1到n的所有路径的Charm value的最小值. tags:有点思维定式了..一条路径里只要最大最小值,所以边可以重复走.这样我们只要把边从小到大枚举,把第 i 条边作为最小边,然后对于每个 i ,我们按顺序逐一加入比它大的边,直到点

2014 UESTC Training for Data Structures H - Cookies Test

H - Cookies Test Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status As chief programmer at a cookie production plant you have many responsibilities, one of them being that the cookies produced and packag

2014 UESTC Training for Data Structures K - 方师傅与栈

K - 方师傅与栈 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status 方师傅有一个1?N的排列,排列的顺序是固定的,他想要把这个排列重新排列成他喜欢的顺序. 于是他买了一个栈,他会按顺序将排列扔进栈内,在某些时刻将栈顶元素取出,这样出栈后的排列就可以重新排序啦. 例如,原序列是1,2,他先将1入栈,再将2入栈,然后将2出栈,最后将1出栈,那么新序列就变

2014 UESTC Training for Data Structures J - 方师傅的01串

J - 方师傅的01串 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status 方师傅过生日啦,于是蟹毛买了N个01串,想送给方师傅. 但是蟹毛觉得这些01串不够美,于是他想从中选出一些送给方师傅. 蟹毛对于p个01串的美值定义为: 这些01串的最长公共前缀的长度×p 所以蟹毛想从N个01串中选出一些,使得这些01串的美值最高. 请告诉蟹毛最好的美值是多少.

2014 UESTC Training for Data Structures C - 东风不与周郎便

C - 东风不与周郎便 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status "揽二乔于东南兮,乐朝夕之与共" 一首铜雀台赋,将愤怒与恐惧散播在了孙吴大军之中. 对抗曹军,万事俱备,只欠东风. 现在已经找到n个风眼,这些风眼的东风有强有弱,诸葛亮说他每次祈风都能够将一段风眼的东风增强,但需人去帮他布阵.同时他需要时刻掌控风眼的状况,以确定下一步的

2014 UESTC Training for Data Structures A - Islands

A - Islands Time Limit: 30000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status Deep in the Carribean, there is an island even stranger than the Monkey Island, dwelled by Horatio Torquemada Marley. Not only it has a re