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. PAT Advanced 1064 Complete Binary Search Tree (30) [⼆叉查找树BST]

    题目 A Binary Search Tree (BST) is recursively defined as a binary tree which has the following proper ...

  2. rust 使用国内镜像,快速安装方法

    前言 众所周知的,国内由于防火墙的原因,访问国外的网络比较慢. 如果直接按照rust官网的安装方式安装非常容易失败,即使不失败也非常非常慢 如果用国内的镜像则可以分分钟就搞定 官方安装方法 文档: h ...

  3. 我的第一次JAVA实训——校园公用房管理系统

    老铁们,昨天电脑没电了.这是上周答应的大项目. 别打脸. 详细内容我之后再写,下面是代码地址. Github地址 附:一个寂寞 以上

  4. Django模板渲染——(二)

    模板标签 模板是由HTML代码和一些逻辑控制代码组成的,逻辑控制代码除了前面介绍的变量和过滤器,还要一个非常重要的模板标签.模板标签的语法规则是{% tag %},模板标签在渲染的过程中能提供任意的逻 ...

  5. 通过ES6 封装了一个上传文件的方法 XMLHttpRequest() 通用

    ### 上传进度回显,上传速度回显 ### 源码如下,新建index.js装起来 export class UploadServers { constructor (options) { this.x ...

  6. Python笔记_第四篇_高阶编程_进程、线程、协程_2.线程

    1. 线程概述: 在一个进程的内部,要同时干多件事情,就需要同时运行“多个子任务”,我们把进程内的这些“子任务”叫做线程.也就说线程是进程成的子任务. 线程通常叫做情景的进程.线程是通过向内侧控件的并 ...

  7. eclipse使用jetty服务器

    1.安装Eclipse Jetty插件: 2.下载jetty(9.4.6): 3.配置jetty运行设置: 右键项目 run configurations,选择jetty webapp,新建项目. c ...

  8. 安装使用离线版本的维基百科(Wikipedia)

    1 相关背景 平常大家在上网查询一些基本概念的时候常常会参考维基百科上面的资料,但是由于方校长研制的GFW(长城防火墙系统)强大的屏蔽功能,好多链接打开以后,不出意外会出现著名的“404NOT FOU ...

  9. @EnableWebMvc WebMvcConfigurer

    Spring注解@EnableWebMvc使用坑点解析 https://blog.csdn.net/zxc123e/article/details/84636521 @EnableWebMvc,Web ...

  10. 吴裕雄--天生自然 JAVA开发学习:String 类

    public class StringDemo{ public static void main(String args[]){ char[] helloArray = { 'r', 'u', 'n' ...