ccpc女生赛题目总结

第一场:2017年ccpc女生赛

 分类: a) 数论&数学,a) 矩阵快速幂,a) 模拟,a) 找感觉题,a) 动态规划

题解:https://www.cnblogs.com/zhangmingzhao/p/7256603.html

第一题:Automatic Judge http://acm.hdu.edu.cn/showproblem.php?pid=6023 水题

第二题:Easy Summation   http://acm.hdu.edu.cn/showproblem.php?pid=6027快速幂或者暴力||(k最大就5不用快速乘法吧。。。。。每次相乘就取模,每次运算取一下摸,能取就取,避免出现高精度运算,暴力ll肯定能过。)分块打表

第三题:1002 Building Shops  http://acm.hdu.edu.cn/showproblem.php?pid=6024动态规划,dp,状态转移

第四题:1008 Happy Necklace  http://acm.hdu.edu.cn/showproblem.php?pid=6030   规律+矩阵快速幂

第五题:6025  枚举(暴力)

第六题:6029  找规律

 第七题:6026  最短路+计数

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x, y) memset(x, y, sizeof(x))
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 55, M = N * N, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
int casenum, casei;
int n;
char s[N][N];
struct node
{
    int x;        //x表示当前点的编号
    int dis;    //dis表示从起点到当前点的距离,注意有时需要LL
    bool operator < (const node&b)const
    {
        return dis > b.dis;
    }
};
struct Dijkstra
{
    int first[N], id;
    struct Edge
    {
        int w, c, nxt;
    }edge[M];
    int f[N];    //f[x]表示从ST到x的最短路
    bool e[N];    //e[x]表示我们是否更新过从ST到x的最短路
    priority_queue<node>q;
    void init()
    {
        for (int i = 1; i <= n; ++i)first[i] = 0;
        id = 1;
    }
    void ins(int x, int y, int z)
    {
        edge[++id] = { y,z,first[x] };
        first[x] = id;
    }
    void inq(int y, int dis)
    {
        if (dis >= f[y])return;
        f[y] = dis;
        q.push({ y,dis });
    }
    void dijkstra()
    {
        LL ans = 1;
        for (int i = 1; i <= n; ++i)
        {
            f[i] = inf;
            e[i] = 0;
        }
        int finish = 0;
        while (!q.empty())q.pop(); inq(1, 0);
        while (!q.empty())
        {
            int x = q.top().x; q.pop();
            if (e[x])continue; e[x] = 1; ++finish;
            if (x != 1)
            {
                int cnt = 0;
                for (int y = 1; y <= n; ++y)if (y != x && e[y] && s[y][x] != '0' && f[y] + s[y][x] - 48 == f[x])++cnt;
                ans = ans * cnt % Z;
            }
            for (int z = first[x]; z; z = edge[z].nxt)
            {
                inq(edge[z].w, f[x] + edge[z].c);
            }
        }
        if (finish != n)ans = 0;
        printf("%lld\n", ans);
    }
}dij;
int main()
{
    while (~scanf("%d", &n))
    {
        dij.init();
        for (int i = 1; i <= n; ++i)
        {
            scanf("%s", s[i] + 1);
            for (int j = 1; j <= n; ++j)if (s[i][j] != '0')
            {
                dij.ins(i, j, s[i][j] - 48);
            }
        }
        dij.dijkstra();
    }
    return 0;
}
/*
【题意】
让你把一个图删成一棵树,使得1到每个点的最短路保持不变
【分析】
我们可以直接求出1到每个点的最短路,然后看看每个点的前驱边可能是有几条(显然对于每一条合法前驱边,以任何一条作为前缀都是等价的)
所有点可能的前驱边数量,乘起来就是最后的答案啦!
【时间复杂度&&优化】
O(nlogn)
*/
View Code

第八题:6032  DP博弈

全部题解:https://blog.csdn.net/snowy_smile/article/details/71305032

 第二场:2018ccpc女生赛:暑假群里有题解

1.二分

2.二分

3. 动态规划

4.最短路径——堆优化的Dijkstra算法(SPFA,加了SLF优化的SPFA,加了SLF和LLL优化的SPFA都会时间超出,是因为数据比较强,而这些算法的复杂度不正确)

5.(可持久化权值)线段树+二分

6.水题

7.仿造Kruskal算法,与最小树类似,都是拟阵

8.水题

9.枚举+双指针

10.

11.水题

第三场:

题解:

第一题:https://blog.csdn.net/WilliamSun0122/article/details/71430344  水题

猜你喜欢

转载自www.cnblogs.com/Aiahtwo/p/10630739.html
今日推荐