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. CYPHER 语句(Neo4j)

    CYPHER 语句(Neo4j) 创建电影关系图 新增 查找 修改 删除 导入 格式转换 创建电影关系图 CREATE (TheMatrix:Movie {title:'The Matrix', re ...

  2. one_day_one_linuxCmd---tar命令

    <坚持每天学习一个 linux 命令,今天我们来学习 tar 命令> 摘要:tar 命令是一个 Linux 下的打包程序,通常在 Linux 下,打包和压缩是不同的程序,打包通过 tar ...

  3. puts函数出现warning: passing argument 1 of ‘puts’ from incompatible pointer type(警告:从不兼容的指针类型传递“puts”的参数1)

    代码: /************************************************************************* > File Name: ptr_v ...

  4. runlevel 运行级别

    linux启动过程 关于Ubuntu 12.04修改默认运行级别,启动字符界面的个人理解   网上通常的做法是:(亲自试验,不管用),如果想直接操作请看绿色字体部分 (1)第一种方法:   由于Red ...

  5. linux 解压命令总结

    常用Linux 命令: [转自]https://www.jianshu.com/p/ca41f32420d6 解压缩 .tar 解包:tar xvf FileName.tar 打包:tar cvf F ...

  6. linux 离线安装mysql7或者8

    安装方式:官网下载压缩包进行安装 1.下载jdk8 登录网址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-download ...

  7. 为什么在SSM中的dao层不用写@Repository注解

    1.  Mybatis 接口编程中dao 层接口没有注解和 为什么能被实例化为bean? 在Spring配置Mybatis的文件中我们可以看到如下代码: <bean class="or ...

  8. JavaScript详解(一)

    简介: Javascript是一个脚本语言,弱类型的编程语言,简称js,被称为网站开发的行为.它的作用是增加页面特效.前后台交互以及应用于后台开发.它即可写在HTML的script标签里,也可写在外部 ...

  9. 023.Python的随机模块和时间模块

    一 random 随机模块 1.1 获取随机0-1之间的小数(左闭右开)  0<= x < 1 import random res = random.random() print(res) ...

  10. goweb-文本处理

    文本处理 Web开发中对于文本处理是非常重要的一部分,我们往往需要对输出或者输入的内容进行处理,这里的文本包括字符串.数字.Json.XML等等.Go语言作为一门高性能的语言,对这些文本的处理都有官方 ...