2018/8/21 qbxt测试

      2018/8/21 qbxt测试

期望得分:0? 实际得分:0

思路:manacher   会写模板但是不会用 qwq

听了某人的鬼话,直接输出0,然后就gg了

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = (int)2e6 + 10;
typedef long long ll;

char S[N];
int R[N], lf[N], rt[N];
int n;

void init() {
    scanf("%s", S + 1), n = strlen(S + 1) << 1 | 1;
    for (int i = n; i >= 1; --i) S[i] = i & 1 ? ‘#‘ : S[i >> 1];
}

void manacher() {
    int k = 1, p = 1;
    R[1] = 1, lf[1] = 0;
    for (int i = 2; i <= n; ++i) {
        int j = 2 * k - i;
        R[i] = min(R[j], p - i + 1);
        for ( ; i + R[i] <= n && i - R[i] >= 1 && S[i + R[i]] == S[i - R[i]]; ++R[i]);
        if (i + R[i] - 1 > p) {
            for (int j = p + 1; j <= i + R[i] - 1; ++j)
                lf[j] = j - i;
            k = i, p = i + R[i] - 1;
        }
    }

    k = n, p = n;
    rt[n] = 0;
    for (int i = n - 1; i >= 1; --i) {
        if (i - R[i] + 1 < p) {
            for (int j = p - 1; j >= i - R[i] + 1; --j)
                rt[j] = i - j;
            k = i, p = i - R[i] + 1;
        }
    }

    for (int i = 3; i <= n; i += 2) lf[i] = max(lf[i], lf[i - 2]);
    for (int i = n - 2; i >= 1; i -= 2) rt[i] = max(rt[i], rt[i + 2]);

    int ans = 0;
    for (int i = 1; i <= n; i += 2)
        if (lf[i] + rt[i] > ans)
            ans = lf[i] + rt[i];
    printf("%d\n", ans);
}

int main() {
    freopen("string.in", "r", stdin);
    freopen("string.out", "w", stdout);

    init();
    manacher();

    return 0;
}

std

期望得分:20?40?  实际得分:20

考场思路:树上两点间的最短路应该要求LCA,那就用树剖求吧  只会用树剖 qwq

欸?让着求路径乘积是什么鬼??线段树?? 那就树剖+线段树吧

这个区间怎么合并??不会       这题不会要用倍增LCA吧 不会啊  咕咕咕~

那就换暴力吧   枚举,然后乘起来

嗯。。答案好像不大对啊,这个样例是不是错了啊

20min 后。。。kao,我题目读错了

最后改了改,20分 qwq

正解:

#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>

using namespace std;
typedef long long LL;
const int M = 100005;
const int Mod = 1e9 + 7;

LL S, T, G;
int tot, n, m, k, t;
int a[M], sum[M];
int to[M*2], net[M*2], head[M];
int deep[M], top[M], dad[M], size[M];

inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while(ch<‘0‘ || ch>‘9‘) {
        if(ch == ‘-‘) f = -1;
        ch = getchar();
    }
    while(ch>=‘0‘ && ch<=‘9‘) x = x * 10 + ch - 48, ch = getchar();
    return x * f;
}

inline void add(int u, int v) {
    to[++tot] = v; net[tot] = head[u]; head[u] = tot;
    to[++tot] = u; net[tot] = head[v]; head[v] = tot;
}

inline void dfs(int now) {
    size[now] = 1;
    deep[now] = deep[dad[now]] + 1;
    for(int i = head[now]; i; i = net[i])
        if(dad[now] != to[i]) {
            dad[to[i]] = now;
            dfs(to[i]);
            size[now] += size[to[i]];
        }
}

inline void dfsl(int now) {
    int t = 0;
    if(!top[now]) top[now] = now;
    for(int i = head[now]; i; i = net[i])
        if(dad[now] != to[i] && size[to[i]] > size[t])
            t = to[i];
    if(t) {
        top[t] = top[now];
        dfsl(t);
    }
    for(int i = head[now]; i; i = net[i])
        if(dad[now] != to[i] && to[i] != t)
            dfsl(to[i]);
}

inline int lca(int x, int y) {
    while(top[x] != top[y]) {
        if(deep[top[x]] < deep[top[y]])
            swap(x, y);
        x = dad[top[x]];
    }
    return deep[x] > deep[y] ? y : x;
}

inline LL mul(int a, int b) {
    LL res = 0;
    while(b) {
        if(b & 1) res = (res + a) % Mod;
        a = (a + a) % Mod;
        b >>= 1;
    }
    return res;
}

inline LL bl(int tmp) {
    LL ans = 0;
    for(int i = 1; i <= tmp; i++)
        for(int j = i+1; j <= tmp; j++)
            ans = (mul(sum[i], sum[j]) + ans) % Mod;
    return ans;
}

inline void get(int l, int r) {
    if(l == r) return ;
    while(l != r) {
        sum[++t] = a[l];
        l = dad[l];
    }
}

int main() {
    freopen("tree.in","r",stdin);
    freopen("tree.out","w",stdout);
    n = read(), m = read(), k = read();
    for(int i = 1; i <= n; i++)
        a[i] = read();
    for(int i = 1; i < n; i++) {
        int u, v;
        u = read(), v = read();
        add(u, v);
    }
    dfs(1);
    dfsl(1);
    for(int i = 1; i <= m; i++) {
        memset(sum, 0, sizeof sum);
        int u, v;
        t = 0;
        u = read(); v = read();
        if(k == 1) u ^= S, v ^= S;
        T = lca(u, v);
        get(u, T), get(v, T);
        sum[++t] = a[T];
        G = bl(t);
        printf("%lld\n", G);
        if(k == 1) S = G;
    }
    fclose(stdin); fclose(stdout);
    return 0;
}

考场代码

#include <bits/stdc++.h>
using namespace std;

const int N = (int)2e5, mod = (int)1e9 + 7, inv = (mod + 1) >> 1;
typedef int arr[N + 10];
typedef long long ll;

int n, Q, K, ans, tot, j, k;
arr pt, nt, g, d, ls[20], sqs[20], f[20];
arr a;

struct queue {
    arr v;
    int f, r;
}q;

void link(int x, int y) {
    pt[++tot] = y, nt[tot] = g[x], g[x] = tot;
    pt[++tot] = x, nt[tot] = g[y], g[y] = tot;
}

void bfs() {
    q.v[q.f = q.r = 1] = 1, d[1] = 1;
    for ( ; q.f <= q.r; ) {
        int x = q.v[q.f++];
        for (int c = 1; c <= 19; ++c)
            if (d[x] > (1 << c)) {
                f[c][x] = f[c - 1][f[c - 1][x]];
                ls[c][x] = (ls[c - 1][x] + ls[c - 1][f[c - 1][x]]) % mod;
                sqs[c][x] = (sqs[c - 1][x] + sqs[c - 1][f[c - 1][x]]) % mod;
            }
            else break;
        for (int i = g[x]; i; i = nt[i])
            if (!d[pt[i]]) {
                d[pt[i]] = d[x] + 1;
                f[0][pt[i]] = x, ls[0][pt[i]] = a[pt[i]], sqs[0][pt[i]] = (ll)a[pt[i]] * (ll)a[pt[i]] % mod;
                q.v[++q.r] = pt[i];
            }
    }
}

int query(int x, int y) {
    if (d[x] > d[y]) swap(x, y);
    int sq = 0, l = 0;
    for (int c = 19; c >= 0; --c)
        if (d[y] - (1 << c) >= d[x])
            (l += ls[c][y]) %= mod, (sq += sqs[c][y]) %= mod, y = f[c][y];
    if (x == y) {
        l = (l + a[y]) % mod, (sq += (ll)a[y] * (ll)a[y] % mod) %= mod;
        l = (ll)l * (ll)l % mod;
        return (ll)(l + mod - sq) * (ll)inv % mod;
    }

    for (int c = 19; c >= 0; --c)
        if (f[c][x] != f[c][y]) {
            (l += (ls[c][x] + ls[c][y]) % mod) %= mod, (sq += (sqs[c][x] + sqs[c][y]) % mod) %= mod;
            x = f[c][x], y = f[c][y];
        }

    (l += (ls[0][x] + ls[0][y]) % mod) %= mod, (sq += (sqs[0][x] + sqs[0][y]) % mod) %= mod;
    y = f[0][y];
    (l += a[y]) %= mod, (sq += (ll)a[y] * (ll)a[y] % mod) %= mod;
    l = (ll)l * (ll)l % mod;
    return (ll)(l + mod - sq) * (ll)inv % mod;
}

int main() {
    freopen("tree.in", "r", stdin);
    freopen("tree.out", "w", stdout);

    scanf("%d %d %d", &n, &Q, &K);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1; i < n; ++i) {
        scanf("%d %d", &j, &k);
        link(j, k);
    }

    bfs();
    ans = 0;

    for ( ; Q--; ) {
        scanf("%d %d", &j, &k);
        if (K) j ^= ans, k ^= ans;
        printf("%d\n", ans = query(j, k));
    }

    return 0;
}

std

期望得分:0  实际得分:0

思路:没有思路   期望是什么??不知道

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;

const int N = 1000;
typedef int arr[N + 10][N + 10];

int n, m, k, t, u, v;
arr s, c;

int Sum(int l1, int r1, int l2, int r2) {
    return s[l2][r2] - s[l1 - 1][r2] - s[l2][r1 - 1] + s[l1 - 1][r1 - 1];
}

long double Pow(long double x, int y) {
    long double t = x, r = 1;
    for ( ; y; y >>= 1, t = t * t)
        if (y & 1) r = r * t;
    return r;
}

int main() {
    freopen("swap.in", "r", stdin);
    freopen("swap.out", "w", stdout);

    scanf("%d%d%d%d\n", &n, &m, &k, &t);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            s[i][j] = c[i][j] = 1;

    ll tot = n * m;
    for (int i = 1; i <= t; ++i) {
        scanf("%d%d\n", &u, &v);
        s[u][v] = c[u][v] = 0, --tot;
    }
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];

    if (!tot) return printf("%.12lf\n", 0.), 0;
    long double exp = tot;
    tot *= tot;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (c[i][j]) {
                ll cx = Sum(1, 1, i, j), cy = Sum(i, j, n, m), ans = cx * cy;
                cx = Sum(1, j, i, m), cy = Sum(i, 1, n, j);
                ans += cx * cy;
                cx = Sum(1, j, i, j), cy = Sum(i, j, n, j);
                ans -= cx * cy;
                cx = Sum(i, 1, i, j), cy = Sum(i, j, i, m);
                ans -= cx * cy;
                ans = ans * 2LL + 1LL;
                long double e = (long double)1 - (long double)2 * (long double)ans / (long double)tot;
                exp += Pow(e, k);
            }
        }
    }
    exp /= (long double)2;
    printf("%.12Lf\n", exp);
    return 0;
}

std

原文地址:https://www.cnblogs.com/v-vip/p/9514442.html

时间: 2024-07-29 05:53:28

2018/8/21 qbxt测试的相关文章

三级菜单-2018.2.21

根据老男孩课程以及网上的代码,自行打出的代码,虽然参照的比较多,嘿嘿嘿 #_author_:"Bushii" #data:2018/2/21 menu= { '山东' : { '青岛' : ['四方','黄岛','崂山','李沧','城阳'], '济南' : ['历城','槐荫','高新','长青','章丘'], '烟台' : ['龙口','莱山','牟平','蓬莱','招远'] }, '江苏' : { '苏州' : ['沧浪','相城','平江','吴中','昆山'], '南京' :

2018/7/21 Python 爬虫学习

2018/7/21,这几天整理出来的一些Python 爬虫学习代码. import urllib2 response = urllib2.urlopen("http://baidu.com") html = response.read() print html 进一步,可以request import urllib2 req = urllib2.Request("http://www.baidu.com") response = urllib2.urlopen(re

Microsoft Artificial Intelligence Conference(2018.05.21)

时间:2018.05.21地点:北京嘉丽大酒店 原文地址:https://www.cnblogs.com/xuefeng1982/p/10335943.html

2018 1.21测试

套路 文件名:road.cpp(pas) 时间限制:1s 空间限制:512MB 题目描述: 给出1个 N 个点的有向图,每个点的出度恰好为一. 现在希望给这 N 条边重定向,求图中不出现环的方案数(对 109 + 7 取模). 输入格式: 第一行一个正整数 N. 第二行 N 个正整数 Xi,表示存在一条有向边 i 指向 Xi. 输出格式: 一行,一个整数 Ans,表示定向后不出现环的方案数. 样例读入: 5 2 3 1 5 4 样例输出: 12 数据范围: 对于 30% 的数据,保证 N 20 

一次运行多个测试类2-1个测试类重复测试

package com.mengdd.junit; import junit.extensions.RepeatedTest; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; public class TestAll extends TestCase { public static Test suite() { // 创建一个测试套件 TestSuite

2018.4.21 五周第四次课(shell特殊符号,cut截取等命令)

shell特殊符号_cut命令 概念:cut命令用来截取某一个字段 格式:cut -d '分割字符' [-cf] n,这里的n是数字,该命令选项有如下几个: - d 后面跟分割字符,分割字符要用单引号括起来 - c 后面接的是第几个字符 - f 后面接的是第几个区块 cut命令用法如下 [[email protected] do]# cat /etc/passwd |head -2root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/no

2018/5/21~2018/5/25 周记

这周又是自己瞎搞的一周.继上一周的一键生成二维码,然后扫描二维码就会跳转到生成二维码的那个url.测试用的是百度的网址,所以扫描二维码后出现的就是百度首页,当我把url地址改成一段文字时,扫描出来的就是那段文字了.于是我就有了一个大胆的想法,我要扫面二维码然后跳转出来的是一张图片,这样我就可以把自己喜欢的图片全部变成二维码,这样把二维码用来做头像的话,别人可能会因为好奇然后点开二维码,识别二维码出现图片会不会觉得我很厉害..当然,这个只能用来骗骗外行人,敲代码的都知道这个很容易实现的.其实最主要

Windows核心编程之核心总结(第四章 进程(三))(2018.6.21)

学习目标 本章节将学习以后经常用到的CreateProcess函数,听网上的人说有些面试官喜欢问这个函数的大概功能和参数作用哦,可见这个函数是十分重要滴,那我们来详细了解和测试这个函数的功能吧,有些不足的以后有实际经验再来修改和补充.说实话,我现在也只是一名大学生,到了实际开发也许才会用到这本书的内容,但我现在是作为兴趣来学这本书的,因为这本书给我的feel就是自己掌控Windows系统,这感觉太棒了.不管以后用不用的到,我觉得对我的帮助都很大.好了,闲话说到这吧,现在本章节的学习目标如下:1.

2018.8.21 2018暑假集训之滑雪

这个题原来做过 结果现在忘了 再来一遍 试题描述 LYH喜欢滑雪,因为滑雪的确很刺激,可是为了获得速度,滑的区域必须向下倾斜,当LYH滑到坡底,不得不再次走上坡或等着直升机来载他,LYH想知道在一个区域中最长的滑坡.滑坡的长度由滑过点的个数来计算,区域由一个二维数组给出,数组的每个数字代表点的高度.下面是一个例子: 1     2     3     4     5 16    17    18    19    6 15    24    25    20    7 14    23    2