A.LCM Problem

题意:最小公倍数LCM(x,y),处于[l,r]之间,并且x,y也处于[l,r]之间,给出l,r找出x,y;

思路:里面最小的最小公倍数就是基于l左端点的,而那个最小公倍数就是2*l,直接判断2*l是否小于r

注意:当时看到最小公倍数,题目中提到了一个LCM(9,6)=18,就只想最大公因子、分解因式之类的问题,就想错了方向,wa的第一个是想的最大的数分解因式,结果TLE了。

 1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstdio>
5 #include<cmath>
6 #include<cstring>
7 using namespace std;
8 int main(){
9 int t;
10 scanf("%d",&t);
11 while(t--){
12 long long int l,r;
13 scanf("%lld %lld",&l,&r);
14 int flag=0;
15 if(l*2<=r){
16 printf("%lld %lld\n",l,l*2);
17 }else{
18 printf("-1 -1\n");
19 }
20
21 }
22 }

B. Array Walk

题意:你的初始分数为a1,当你往左或者右边走的时候总分数就会加上所在位置的分数,不可以连续向左走,现在一共有n个位置,一共走k步,最多向左走z步,问所取得的最大分数是多少

思路:要把这个问题分开来看,你往左走的情况只有:1.往左走一步立即向右一步;2.提供的步数不够满足往左走完再往右走,只能是最后一步往左走一步;遍历找最大值

注意:这题必须用输入输出流的优化,并且定义数组的时候需要在外面,不然数组内放不下这么多数,因为是这样所以在循环内,数组必须每次都重置0再进行计算;

 1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cmath>
5 #include<cstring>
6 using namespace std;
7 const int maxx=2e5+3;
8 long long int a[maxx],b[maxx],sum[maxx];
9 int main(){
10 ios::sync_with_stdio(0);
11 cin.tie(0), cout.tie(0);
12 int t;
13 cin>>t;
14 while(t--){
15 int n,k,z;
16 cin>>n>>k>>z;
17 for(int i=1;i<=n;i++){
18 a[i]=0;
19 b[i]=0;
20 sum[i]=0;
21 cin>>a[i];
22 }
23 for(int i=1;i<=n;i++){
24 sum[i]+=sum[i-1]+a[i];
25 }
26 for(int i=2;i<=n;i++){
27 b[i]=a[i]+a[i-1];
28 }
29 long long int summ=sum[k+1];//第一种是一直向右走的,直接就是前缀和
30 for(int i=2;i<=n;i++){//i向右走,并且i是当前向右的位置坐标
31 for(int j=1;j<=z&&j<=k-i+1;j++){//向左走应该小于剩余步数并且小于z
32 if(j*2<=k-i+1){
33 summ=max(summ,j*b[i]+sum[i+k-i+1-j*2]);
34 //i+k-2*j-i+1 是最后的当前位置
35 }else if(j*2-1<=k-i+1){
36 summ=max(summ,(j-1)*b[i]+a[i-1]+sum[i]);
37 }
38 }
39 }
40 cout<<summ<<endl;
41 }
42 }

C. Good String

题意:字符串有做循环位移和右循环位移两种操作。例如字符串“123456”,如果进行左循环位置后得“234561”,如果进行右循环位移后得“612345”。我们称一个字符串为好的,当且仅当它进行左循环位移和右循环位移后相等。现在给定一个字符串只包含0-9,可以删除字符串中某些字符,要求最少删除多少个字符串可以让字符串边好。

思路:要满足左右循环位移一位后字符串完全相等,那么字符串要么全由一个字符串组成,例如,’111111‘,或者只有两个字符循环出现,例如样例中的“2525252525”。那么我们就可以去构造字符串,然后去判断。只有一个字符的时候只要记录一下每个字符出现的次数即可。如果是两个字符循环出现的话,可以枚举剩下的两个字符,然后去和原字符串匹配。复杂度为10*10*n。

Educational Codeforces Round 92 (Rated for Div. 2)的更多相关文章

  1. Educational Codeforces Round 92 (Rated for Div. 2) B、C题解

    TAT 第一场codeforces B. Array Walk #暴力 #贪心 题目链接 题意 有\(a1, a2, ..., an\) 个格子(每个格子有各自分数),最初为1号格(初始分数为\(a1 ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  4. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  5. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  9. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

随机推荐

  1. kmp&字典树 模板

    kmp: const int maxn=1e5+5; char s[maxn],p[maxn]; int nex[maxn]; int KmpSearch(char* s, char* p) { in ...

  2. HTML总结篇

    一.HTML基本结构标签 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  3. PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...

  4. PAT (Basic Level) Practice (中文) 1050 螺旋矩阵 (25 分) 凌宸1642

    PAT (Basic Level) Practice (中文) 1050 螺旋矩阵 (25 分) 目录 PAT (Basic Level) Practice (中文) 1050 螺旋矩阵 (25 分) ...

  5. 计划任务统一集中管理系统cronsun(替代crontab)

    一.背景 crontab 是 Linux 系统里面最简单易用的定时任务管理工具,相信绝大多数开发和运维都用到过,很多业务系统的定时任务都是通过 crontab 来定义的,时间长了后会发现存在很多问题: ...

  6. MySQL5.7和MySQL8.0通用配置文件

    MySQL5.7 my.cnf配置 [client] port=3306 socket=/log/mysql/mysql.sock [mysql] socket=/log/mysql/mysql.so ...

  7. Node.js核心入门

    前言: 因为以前学习Node.js并没有真正意义上的去学习它,而是粗略的学习了npm的常用命令和Node.js一些模块化的语法,因此昨天花了一天的时间看了<Node.js开发指南>一书.通 ...

  8. 开源服务器设计总计(plain framework2020年总计)

    2020年注定会被历史铭记,世界遭受着一场前所未有的灾难,这种灾难到现在还在持续.还记得19年末的时候,那时候听到一点点消息,哪里想得到年关难过,灾难来的让人猝不及防.由于疫情防控,2020年感觉转瞬 ...

  9. [Fundamental of Power Electronics]-PART I-6.变换器电路-0 序

    6 变换器电路 我们已经分析了包括buck,boost,buck-boost以及cuk电路,电压源逆变器等一系列电路的工作原理.利用这些变换器,可以执行许多不同的功能:降压,升压,极性反转以及直流交流 ...

  10. navcat卸载

    https://www.cnblogs.com/mysterious-killer/p/10416739.html