E .Sequence in the Pocket

sol:将数组copy一份,然后sort一下,找寻后面最多多少个元素在原数组中保持有序,用总个数减去已经有序的就是我们需要移动的次数。

  • 思维题

    #include "bits/stdc++.h"
    using namespace std;
    const int MAXN = 1e5 + ;
    int a[MAXN], b[MAXN];
    int main() {
    int t, n;
    scanf("%d", &t);
    while (t--) {
    scanf("%d", &n);
    for (int i = ; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
    }
    sort(b + , b + + n);
    int ans = n;
    for (int i = n; i >= ; i--)
    if (a[i] == b[ans]) ans--;
    printf("%d\n", ans);
    }
    return ;
    }

    一开始我思路错了还浪费了一定时间。后来队友提供了正确思路

F .Abbreviation

sol:首字母不删直接输出,剩下的逐个判断。注意一下‘y’也是要删的

  • 带坑的签到题

    #include "bits/stdc++.h"
    using namespace std;
    const int MAXN = ;
    char s[MAXN];
    int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
    scanf("%s", s);
    putchar(s[]);
    for (int i = ; s[i]; i++)
    if (s[i] != 'a' && s[i] != 'e' && s[i] != 'i' && s[i] != 'o' && s[i] != 'u' && s[i] != 'y')
    putchar(s[i]);
    puts("");
    }
    return ;
    }

G .Lucky 7 in the Pocket

sol:这题只要找7的倍数,所以可以直接暴力,如果是1e9 + 7这种比较大的数就不行了。既然可以暴力,那就采取最省时间的做法来一波暴力。

  • 暴力签到题

    #include "bits/stdc++.h"
    using namespace std;
    int main() {
    int t, n;
    scanf("%d", &t);
    while (t--) {
    scanf("%d", &n);
    while (n % != || n % == ) n++;
    printf("%d\n", n);
    }
    return ;
    }

H .Singing Everywhere

sol:遍历每个数,检查删除这个数可以减少多少高音。最后减一下就是结果

  • 暴力

    #include "bits/stdc++.h"
    using namespace std;
    typedef long long LL;
    const int MAXN = 1e5 + ;
    const LL INF = 1LL << ;
    LL arr[MAXN];
    int t, n;
    int getSub(int i) {
    int a = , b = ;
    if (i != && arr[i - ] > arr[i - ] && arr[i - ] > arr[i]) a++;
    if (arr[i] > arr[i - ] && arr[i] > arr[i + ]) a++;
    if (i != n && arr[i + ] > arr[i + ] && arr[i + ] > arr[i]) a++;
    if (i != && arr[i - ] > arr[i - ] && arr[i - ] > arr[i + ]) b++;
    if (i != n && arr[i + ] > arr[i + ] && arr[i + ] > arr[i - ]) b++;
    return a - b;
    }
    int main() {
    scanf("%d", &t);
    while (t--) {
    scanf("%d", &n);
    int ans = , sub = ;
    for (int i = ; i <= n; i++)
    scanf("%lld", &arr[i]);
    arr[] = arr[n + ] = INF;
    for (int i = ; i <= n; i++) {
    if (arr[i] > arr[i - ] && arr[i] > arr[i + ]) ans++;
    sub = max(sub, getSub(i));
    }
    printf("%d\n", ans - sub);
    }
    return ;
    }

    因为题目的范围完全就是int的极限范围。一开始在两边补INF防越界的时候采用的0x3f3f3f3f不够大还导致了一次wa,后来全部改成了long long。INF也改成了1LL << 60

I .Fibonacci in the Pocket

sol:因为fibonacci的奇偶性是三个一循环都是奇奇偶。而奇奇偶相加为偶数不影响结果。所以可以将a映射到1 - 3,b映射到4 - 6;然后从a加到b;

  • 数学+规律

    #include "bits/stdc++.h"
    using namespace std;
    const int MAXN = ;
    char s1[MAXN], s2[MAXN];
    bool is_odd[] = {, , , , , , };
    int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
    scanf("%s%s", s1, s2);
    int a = , b = , c = ;
    for (int i = ; s1[i]; i++) a += s1[i] ^ '';
    for (int i = ; s2[i]; i++) b += s2[i] ^ '';
    a = (a - ) % + ;
    b = (b - ) % + ;
    for (int i = a; i <= b; i++)
    c += is_odd[i];
    printf("%d\n", c & );
    }
    return ;
    }

    3是一个神奇的数字。一个数模3等于这个数所有位数和模3。所有我们先把a和b所有位数和求出来。

J .Welcome Party

sol:简单来说这题就是联通块和字典序,可以用并查集解决联通块,优先队列解决字典序。

  • 图算法

    #include "bits/stdc++.h"
    using namespace std;
    const int MAXN = 1e6 + ;
    vector<int> edge[MAXN];
    priority_queue<int, vector<int>, greater<int> > que;
    int pre[MAXN]; bool vis[MAXN];
    void init(int n) {
    memset(pre, -, sizeof(int) * (n + ));
    memset(vis, false, sizeof(bool) * (n + ));
    for (int i = ; i <= n; i++) edge[i].clear();
    }
    int find(int k) {
    if (pre[k] == -) return k;
    return pre[k] = find(pre[k]);
    }
    void bfs() {
    bool head = true;
    while (!que.empty()) {
    int k = que.top();
    que.pop();
    if (vis[k]) continue;
    vis[k] = true;
    if (head) {
    printf("%d", k);
    head = false;
    } else printf(" %d", k);
    for (int i = ; i < edge[k].size(); i++)
    que.push(edge[k][i]);
    }
    puts("");
    }
    int main() {
    int t, n, m;
    scanf("%d", &t);
    while (t--) {
    scanf("%d%d", &n, &m);
    init(n);
    int a, b, fa, fb;
    while (m--) {
    scanf("%d%d", &a, &b);
    edge[a].push_back(b);
    edge[b].push_back(a);
    fa = find(a);
    fb = find(b);
    if (fa == fb) continue;
    if (fa < fb) pre[fb] = fa;
    else pre[fa] = fb;
    }
    for (int i = ; i <= n; i++)
    if (pre[i] == -) que.push(i);
    printf("%d\n", que.size());
    bfs();
    }
    return ;
    }

    第一发提交PE了,以为都是最后判PE的,改了PE就能AC了。然后第二发因为没有排字典序wa。之后又因为没明白“It is guaranteed that neither the sum of n nor the sum of m of all cases will exceed 1e6.”而各种超时。(处理pre和vis的时候清空了整个数组)其实最后也没明白这句话。后来一通乱改在最后8分钟AC了。错失冠军;

K .Strings in the Pocket

sol:如果两个串相同,可以视为找回文串个数。如果不同,先判断删除左边连续相同部分和右边连续相同部分后能否通过反转使两串相等,如果不行结果为0,如果可行不断往两边延伸。

  • 思维+回文串

    #include "bits/stdc++.h"
    using namespace std;
    typedef long long LL;
    const int MAXN = 2e6 + ;
    char s1[MAXN << ], s2[MAXN];
    int p[MAXN << ];
    LL manacher(char* s, int* p) {
    int n = strlen(s);
    for (int i = n; i >= ; i--) {
    s[i + << ] = s[i];
    s[i << | ] = '#';
    }
    n = n + << ;
    s[] = '$';
    int k = ; LL ans = ;
    for (int i = ; i < n; i++) {
    if (i >= k + p[k]) p[i] = ;
    else p[i] = min(p[ * k - i], p[k] + k - i);
    while (s[i + p[i]] == s[i - p[i]]) p[i]++;
    if (p[i] + i > p[k] + k) k = i;
    ans += p[i] >> ;
    }
    return ans;
    }
    int getAns(char* s1, char* s2) {
    int n = strlen(s1);
    int l = , r = n - ;
    while (s1[l] == s2[l]) l++;
    while (s1[r] == s2[r]) r--;
    int a = l, b = r;
    while (a <= r) {
    if (s1[a] != s2[b]) return ;
    a++, b--;
    }
    int ans = ;
    do {
    ans++;
    l--, r++;
    } while (l >= && r < n && s1[l] == s1[r]);
    return ans;
    }
    int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
    scanf("%s%s", s1, s2);
    if (strcmp(s1, s2)) printf("%d\n", getAns(s1, s2));
    else printf("%lld\n", manacher(s1, p));
    }
    return ;
    }

    可能是自信不够,压根不相信专科能做那么多题,不相信这题这么简单。思维部分队友已经讲透了,算法部分我也会敲。然而就是没做出来,错失特奖。

浙江省第十六届大学生ACM程序设计竞赛部分题解的更多相关文章

  1. 第十四届中北大学ACM程序设计竞赛 J.ZBT的游戏

    问题描述 第14届中北大学程序设计竞赛来了,集训队新买了一大堆气球,气球一共有K种颜色(1<=K<=256),气球的颜色从1-K编号. ZBT童心未泯,他发明了一种摆放气球的游戏,规则如下 ...

  2. 希尔加密算法(湖南师范大学第六届大学生计算机程序设计竞赛)hnuoj11552

    解密 Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 2, Accept ...

  3. 湖南省第十三届大学生计算机程序设计竞赛 Football Training Camp 贪心

    2007: Football Training Camp[原创-转载请说明] Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 1 ...

  4. 校第十六届大学生程序设计竞赛暨2016省赛集训队选拔赛(Problem E)

    Problem E Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 第十四届华中科技大学程序设计竞赛决赛同步赛 A - Beauty of Trees

    A - Beauty of Trees 题意: 链接:https://www.nowcoder.com/acm/contest/119/A来源:牛客网 Beauty of Trees 时间限制:C/C ...

  6. 第十四届华中科技大学程序设计竞赛决赛同步赛 F Beautiful Land(01背包,背包体积超大时)

    链接:https://www.nowcoder.com/acm/contest/119/F来源:牛客网 Beautiful Land 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1 ...

  7. 第十四届华中科技大学程序设计竞赛 K Walking in the Forest【二分答案/最小化最大值】

    链接:https://www.nowcoder.com/acm/contest/106/K 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

  8. 第十四届华中科技大学程序设计竞赛 J Various Tree【数值型一维BFS/最小步数】

    链接:https://www.nowcoder.com/acm/contest/106/J 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

  9. 第十四届华中科技大学程序设计竞赛 B Beautiful Trees Cutting【组合数学/费马小定理求逆元/快速幂】

    链接:https://www.nowcoder.com/acm/contest/106/B 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

随机推荐

  1. Java数据的存储

    在JAVA中,有六个不同的地方可以存储数据: 1. 寄存器(register).这是最快的存储区,因为它位于不同于其他存储区的地方——处理器内部.但是寄存器的数量极其有限,所以寄存器由编译器根据需求进 ...

  2. Linux-异步IO

    1.何为异步IO (1).几乎可以这么认为:异步IO就是操作系统用软件实现的一套中断响应系统. (2).异步IO的工作方法:我们当前进程注册一个异步IO事件(使用signal注册一个信号SIGIO的处 ...

  3. Codeforces Round #568 (Div. 2)网卡&垫底记

    这场和div3差不多嘛(后来发现就是div3),就是网太卡10min交一发就不错了,简直自闭. A 签到. B 记录每一段的字母数,满足条件即:段数相同+字母相同+字母数下>=上. #inclu ...

  4. inotifywait命令详解及安装

    https://www.cnblogs.com/pyrene/p/6414724.html     安装 https://www.cnblogs.com/martinzhang/p/4126907.h ...

  5. Vue 源码学习(1)

    概述 我在闲暇时间学习了一下 Vue 的源码,有一些心得,现在把它们分享给大家. 这个分享只是 Vue源码系列 的第一篇,主要讲述了如下内容: 寻找入口文件 在打包的过程中 Vue 发生了什么变化 在 ...

  6. [Algo] 115. Array Deduplication I

    Given a sorted integer array, remove duplicate elements. For each group of elements with the same va ...

  7. 三、VIP课程:并发编程专题->01-并发编程之Executor线程池详解

    01-并发编程之Executor线程池详解 线程:什么是线程&多线程 线程:线程是进程的一个实体,是 CPU 调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.线程自己基本上不拥有系 ...

  8. 题解 P3117 【[USACO15JAN]牛的矩形Cow Rectangles】

    暴力什么的就算了,贪心他不香吗 这题其实如果分开想,就三种情况需要讨论:(由于不会发图,只能手打) 1) 5 . . . . . 4 . . . . . 3 . . . H . 2 . . G . . ...

  9. ubuntu编译caffe遇到的问题及解决方案

    问题1 /usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or ...

  10. Tensorflow学习教程------tfrecords数据格式生成与读取

    首先是生成tfrecords格式的数据,具体代码如下: #coding:utf-8 import os import tensorflow as tf from PIL import Image cw ...