A. Bad Ugly Numbers

思路

  • 题意: 给我们一个k,让我们用 0~9 之间的数字构成一个 k位数a,a不能被组成a的每一位数字整除。
  • 分析:首先 k等于1,无论我们怎么配都会被整除;当k > 1 的时候,a的组成位数中肯定不能有1,那么只能在 2~9,之间选择,剩下我们可以选择两个不能互相整除的数如 2、7,,我们可以让2作为第一位,剩下的位数全是7,,,,例如我们求一个k = 3 时我们构成的数a,a = 277

代码

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<string>
using namespace std; int main()
{
/* freopen("A.txt","r",stdin); */
/* freopen("Res.txt","w",stdout); */
int t;
scanf("%d", &t);
while(t --)
{
int n;
scanf("%d", &n); if(n == 1)
{
printf("-1\n");
continue;
} printf("2");
for(int i = 2; i <= n; i ++)
printf("%d", 9);
printf("\n");
} return 0;
}
  • 注意:做题认真

B. Maximums(多观察)

思路

  • 题意

    有一个序列长度为n的序列a1,a2,,,an a_1,a_2,,,a_n~a1​,a2​,,,an​  ,有给了我们另一个序列x1,x2,x3...xn x_1,x_2,x_3...x_n~x1​,x2​,x3​...xn​ ,在这个序列中xix_ixi​为序列a从1~i-1 的前缀最大值,注意:x1=0x_1 = 0x1​=0,又给了我们一个 b1,b2...bnb_1,b_2...b_nb1​,b2​...bn​,其中bi=ai−xib_i = a_i - x_ibi​=ai​−xi​, 题上给我们了 序列b的值,让我们逆向求序列a的值
  • 分析:由于 xix_ixi​是前缀1~(i - 1)位置序列a最大值,而且x1=0x_1 = 0x1​=0, 我们要求的ai=bi+xia_i = b_i + x_iai​=bi​+xi​, 当i = 1,x1,b1x_1, b_1x1​,b1​均为已知值,这样我们可以求出 a1a_1a1​, 这样我们在维护 x1x_1x1​的最大值,那么相当于x1x_1x1​也是已知值,这样在不断求解每一位的时候,维护前缀最大值xix_ixi​就行了

代码

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<string>
using namespace std; const int Len = 2e5 + 10;
int ar[Len], br[Len]; int main()
{
/* freopen("A.txt","r",stdin); */
/* freopen("Res.txt","w",stdout); */
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%d", &br[i]);
int pri_mx = 0;
for(int i = 1; i <= n; i ++)
{
ar[i] = br[i] + pri_mx;
pri_mx = max(pri_mx, ar[i]);
}
for(int i = 1; i <= n; i ++)
printf("%d ", ar[i]); return 0;
}

C. Permutation Partitions(思维)

思路

  • 题意:给我们一个有1~n之间的数字组成的序列,让我们把这个序列分割成 k 段,是这k段中的最大值相加和最大,问我和的最大值是多少,并且得到这个最大值的分割方法有多少种。

  • 分析:由于组成序列p是 1~n之间的数字,有很明显 和的最大值就是 n-k+1 ~ n 之间的所有数字和,这题就是难在这个分割方法,我们可以用插板法去解决这个分割方法,我们加上 前k大数字在原序列p中的位置为x1,x2...xkx_1,x_2...x_kx1​,x2​...xk​, 那么我们可以在 相邻的 两个属于前k大的数字之间进行插板,那么只需要查 k-1个板子就可解决问题了,对其中一个板子,插大位置的方案数是 x_i - x_i-1 ,那么我们把所有板子插入的位置方案数相乘就能得到ans了, ⚠️用 long long,防止相乘的时候溢出

代码

#include<iostream>
using namespace std;
typedef long long ll;
const int mod=998244353; int n, k;
ll ans = 1, sum = 0, p = -1; //p存储的是上一个前k大的数的位置 int main()
{
/* freopen("A.txt","r",stdin); */
scanf("%d %d", &n, &k);
int x;
for(int i = 1; i <= n; i ++)
{
scanf("%d", &x);
if(x >= n - k + 1)
{
sum += x;
if(p != -1)
ans = ans * (i - p) % mod;
p = i;
}
}
printf("%lld %lld\n", sum, ans); return 0;
}
  • 收获:收获的肯定是,这个“插板法”来求解分割成连续k段的思路,真实考思维啊。。。。。

D2. Prefix-Suffix Palindrome (Hard version)(马拉车)

思路

  • 题意:给我们一个字符串s,让我们从这个字符串中找到一个“前缀字符a串”(从s字符串开始的第一个字符为开头的子串) 和一个“后缀字符串b”(以s最后一个字符结尾的子串),把a 、b子串拼接起来,问能组成的最大回文字符串是多长。

  • 分析:首先我们从s串中前后两端进行匹配,如果前后字符相同就继续向中间匹配,这样我们的到两端已经匹配好的子串设为x,y,把匹配剩下的一个连续的子串str,我们 “马拉车”算法跑一边,去求以str中第一个字符开头的回文子串的的最大长度或者以str最后一个字符为结尾的回文子串的最大长度,得到的这个最大长度的回文子串的设为mid,那么最终答案就是 x + mid + z (把这三段拼接起来)

  • ⚠️:在用马拉车求解 mid最大回文子串 的时候,有以下代码片段需要注意:

      //如果回文串从开头或者结尾出发 && 当前找到的这个回文串的长度大于 以前符合题意的回文串的长度
    if(Len[i] - 1 > mx_ans && (i - Len[i] == 0 || i + Len[i] == tot))
    {
    if(i - Len[i] == 0)
    is_front = 1;
    else
    is_front = 0;
    mx_ans = Len[i] - 1;
    }

代码

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std; const int maxn = 5e6 + 5;
char ar[maxn], br[maxn], cr[maxn];
int Len[maxn];
bool is_front = 1; int trans(int cnt)
{
int tot = 0;
cr[tot ++] = '@';
for(int i = 0; i < cnt; i ++)
cr[tot ++] = '#', cr[tot ++] = br[i];
cr[tot ++] = '#';
cr[tot] = '$';
return tot;
} int Manacher(int tot)
{
int mid = 0, mxR = 0;
int mx_ans = 0;
for(int i = 1; i < tot; i ++)
{
if(i < mxR) Len[i] = min(mxR - i, Len[2*mid - i]);
else Len[i] = 1; while(cr[i + Len[i]] == cr[i - Len[i]]) Len[i] ++; if(mxR < i + Len[i])
{
mid = i;
mxR = i + Len[i];
}
//如果回文串从开头或者结尾出发 && 当前找到的这个回文串的长度大于 以前符合题意的回文串的长度
if(Len[i] - 1 > mx_ans && (i - Len[i] == 0 || i + Len[i] == tot))
{
if(i - Len[i] == 0)
is_front = 1;
else
is_front = 0;
mx_ans = Len[i] - 1;
}
}
return mx_ans;
} int main()
{
/* freopen("A.txt","r",stdin); */
/* freopen("Res.txt","w",stdout); */
int t;
scanf("%d", &t);
while(t --)
{
is_front = 1;
scanf("%s", ar + 1);
int n = strlen(ar + 1);
int len1 = 0;
int cnt = 0;
for(int i = 1, j = n; i <= j; i ++, j --)
{
if(ar[i] == ar[j] && i != j)
len1 ++;
else
{
while(i <= j)
{
br[cnt ++] = ar[i];
i ++;
}
break;
}
}
int len2 = Manacher(trans(cnt)); for(int i = 1; i <= len1; i ++)
printf("%c", ar[i]);
if(is_front)
{
for(int i = 0; i < len2; i ++)
printf("%c", br[i]);
}
else
{
for(int i = cnt - len2; i < cnt; i ++)
printf("%c", br[i]);
}
for(int i = n - len1 + 1; i <= n; i ++)
printf("%c", ar[i]);
printf("\n");
} return 0;
}

*收获:“马拉车”,这个神奇的以O(n)求回文的子串的算法。其次还是要好好读好题,把题意理解正确

E. Bombs(真思维 + 线段树)

思路

代码

#include<iostream>
using namespace std; #define rl rt << 1
#define rr rt << 1 | 1
#define ms m = (tre[rt].l + tre[rt].r) >> 1
const int maxn = 300005;
struct Node
{
int l, r, mn, lazy;
} tre[maxn << 2]; int p[maxn]; void Push_up(int rt)
{
tre[rt].mn = min(tre[rl].mn, tre[rr].mn);
}
void Push_down(int rt)
{
int ly = tre[rt].lazy;
if(ly) //如果 lazy 不等于0,我们要下推标记
{
tre[rl].lazy += ly;
tre[rl].mn += ly;
tre[rr].lazy += ly;
tre[rr].mn += ly;
tre[rt].lazy = 0; //解除标记
}
} void Build(int rt, int l, int r)
{
tre[rt].l = l, tre[rt].r = r;
tre[rt].mn = tre[rt].lazy = 0;
if(l == r) return;
int m = (l + r) >> 1;
Build(rl, l, m);
Build(rr, m + 1, r);
} void Update(int rt, int s, int e, int val)
{
if(s <= tre[rt].l && tre[rt].r <= e)
{
tre[rt].mn += val;
tre[rt].lazy += val;
return;
} Push_down(rt);
int ms;
if(s <= m) Update(rl, s, e, val);
if(e > m) Update(rr, s, e, val);
Push_up(rt);
} int main()
{
/* freopen("A.txt","r",stdin); */
/* freopen("Ans.txt","w",stdout); */
int n;
scanf("%d", &n);
int x;
for(int i = 1; i <= n; i ++)
scanf("%d", &x), p[x] = i; //存储x这个值所在的位置为 i
Build(1, 1, n);
int ans = n + 1;
int q;
for(int i = 1; i <= n; i ++)
{
scanf("%d", &q);
while(tre[1].mn >= 0) //当tre[1].mn 小于0的时候我们可以确定当前最大值ans没有被没有被当前位置之前的所有炸弹炸掉,所以 最大值还是ans,直接输出就行了;
//如果tre[1].mn >= 0 这个时候 ans 这个序列中的最大值已经被 炸弹炸掉了,所以我们需要 while循环,找符合题意的ans使tre[rt].mn再次小于0,然后再次输出ans
{
ans --;
Update(1, 1, p[ans], -1);
}
Update(1, 1, q, 1);
printf("%d ", ans);
} return 0;
}

Codeforces Global Round 7的更多相关文章

  1. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  2. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  3. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  4. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  5. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  6. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  7. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  8. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  9. 【Codeforces Round 1110】Codeforces Global Round 1

    Codeforces Round 1110 这场比赛只做了\(A\).\(B\).\(C\),排名\(905\),不好. 主要的问题在\(D\)题上,有\(505\)人做出,但我没做出来. 考虑的时候 ...

  10. 树形DP ---- Codeforces Global Round 2 F. Niyaz and Small Degrees引发的一场血案

    Aspirations:没有结果,没有成绩,acm是否有意义?它最大的意义就是让我培养快速理解和应用一个个未知知识点的能力. ————————————————————————————————————— ...

随机推荐

  1. redis实现数据库(一)

    转:https://www.cnblogs.com/beiluowuzheng/p/9738159.html 服务器中的数据库 Redis服务器将所有数据库都保存在服务器状态redis.h/redis ...

  2. js 图片实现无缝滚动

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. Python输出水仙花数,用逗号分隔

    描述 "水仙花数"是指一个三位整数,其各位数字的3次方和等于该数本身.‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪ ...

  4. C/C++、C#、JAVA(二):基本类型和转换操作

    基本类型和转换操作 数据类型 C语言中的基本类型如下. 类型 存储大小 值范围 char 1 字节 -128 到 127 或 0 到 255 unsigned char 1 字节 0 到 255 si ...

  5. ADO.NET 的使用(一)

    一.ADO.NET概要 ADO.NET 是一组向 .NET Framework 程序员公开数据访问服务的类. ADO.NET 为创建分布式数据共享应用程序提供了一组丰富的组件. 它提供了对关系数据.X ...

  6. Data-independent acquisition mass spectrometry in metaproteomics of gut microbiota - implementation and computational analysis DIA技术在肠道宏蛋白质组研究中的方法实现和数据分析 (解读人:闫克强)

    文献名:Data-independent acquisition mass spectrometry in metaproteomics of gut microbiota - implementat ...

  7. 【转】linux中ifconfig 命令详解详解

    1 概述 ifconfig工具不仅可以被用来简单地获取网络接口配置信息,还可以修改这些配置.用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在.要想将上述的配置信息永远的存的电 ...

  8. JavaScript 模式》读书笔记(4)— 函数1

    从这篇开始,我们会用很长的章节来讨论函数,这个JavaScript中最重要,也是最基本的技能.本章中,我们会区分函数表达式与函数声明,并且还会学习到局部作用域和变量声明提升的工作原理.以及大量对API ...

  9. 表格的删除与添加以及id的唯一性

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  10. python环境变量忘记配置

    Python安装没有勾选配置环境变量安装 解决方法一: 于是,便用安装包卸载后重新安装. 重新安装勾选 安装成功 方法二: 配置环境变量 A.右键点击“我的电脑”,点击“属性”: B.在弹出的界面中点 ...