首页 技术 正文
技术 2022年11月16日
0 收藏 846 点赞 4,073 浏览 4205 个字

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 ;
    }

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896