慢慢来。

题目册

题目 A B C D
tag math strings greedy dp
状态

//∅,√,×


想法

A. CME

res tp A

题意:有\(n\)根火柴,额外填上\(k(k≥0)\)根火柴棍,使得\(n+k\)能分成三份\(a,b,c\),每份至少有一根火柴,满足\(a+b = c\),问\(k\)最小是多少

满足方程

\(a+b+c = n+k\)

\(a + b = c\)

得\(2*c = n+k\)

若\(n\)是偶数,那么\(k\)为零,反之\(k\)为\(1\)

特别地,\(n\)至少要为\(4\),才能凑出一个等式\(1+1=2\)

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i = (a);i>=(b);--i)
#define fo(i,a,b) for(int i =(a);i<(b);++i)
#define de(x) cout<<#x<<" = "<<x<<endl;
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a));
#define ls(p) ((p)<<1)
#define rs(p) (((p)<<1)|1)
using namespace std;
typedef long long ll;
const int mn = 105; int n,q;
int main(){
cin>>q;
while(q--){
cin>>n;
if(n < 4)
cout<<4 - n<<endl;
else
cout<< (n&1) <<endl;
}
}

B. Strings Equalization

res tp B

题意:给出两个仅包含小写字母的字符串,问是否存在某个字符在两串中都出现过

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i = (a);i>=(b);--i)
#define fo(i,a,b) for(int i =(a);i<(b);++i)
#define de(x) cout<<#x<<" = "<<x<<endl;
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a));
#define ls(p) ((p)<<1)
#define rs(p) (((p)<<1)|1)
using namespace std;
typedef long long ll;
const int mn = 105; char s[mn],t[mn];
int q,m;
bool vis[27],ans;
int main(){
cin>>q;
while(q--){
cin>>s>>t;
ans = 0;
mem(vis,0);
m =strlen(s);
rep(i,0,m-1) vis[ s[i]-'a' ] = 1;
rep(i,0,m-1) if(vis[t[i]-'a']){
ans = 1;break;
}
if(ans) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}

C. Save the Nature

res tp C

题意:给定一个整数序列\(p_i,i\in[1,n]\),你可以对其进行打乱顺序重新排列。定义了一个规则,下标是\(a\)的倍数的,可以有\(x%\)的贡献,下标是\(b\)的倍数的,可以有\(y%\)的贡献,问,在重排之后,按上述规则,从\(1\)开始,最少需要多少个连续的数,使得总贡献不小于\(k\)?

贪心地考虑,下标若既是\(a\)的倍数,又是\(b\)的倍数,那岂不是能贡献两份吗?我们先按从大到小的顺序钦定这类下标的元素值,之后再依照\(x\)与\(y\)的大小关系继续钦定剩下的对答案有贡献的位置,遍历区间\([1,i]\),执行上述操作,直到遇到第一个总贡献不小于\(k\)的下标,而那就是我们想要得到的最终答案。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i = (a);i>=(b);--i)
#define fo(i,a,b) for(int i =(a);i<(b);++i)
#define de(x) cout<<#x<<" = "<<x<<endl;
#define endl '\n'
#define ls(p) ((p)<<1)
#define rs(p) (((p)<<1)|1)
using namespace std;
typedef long long ll;
const int mn = 2e5+10;
int n, q, na, nb, nc, x, y, a, b;
ll p[mn], k;
bool cmp1(ll a,ll b){return a>b;}
int ans;
inline ll gcd(ll x,ll y){
return (y == 0? x:gcd(y,x%y));
}
inline ll solve(int num){
na = num/a;nb = num/b;
nc = na&&nb?num/(a/gcd(a,b)*b):0; nb-=nc;na-=nc;
ll res = 0;
res += (p[nc] - p[0])*(x+y);
if(x > y){
res += (p[nc + na]- p[nc])*x;
res += (p[nc + na + nb] - p[nc + na])*y;
}
else{
res += (p[nc + nb] - p[nc])*y;
res += (p[nc + na + nb] - p[nc + nb])*x;
}
return res/100;
} int main(){
scanf("%d",&q);
while(q--){
scanf("%d",&n);
rep(i,1,n) cin>>p[i];
sort(p+1,p+1+n,cmp1);
rep(i,1,n) p[i] += p[i-1];
scanf("%d%d%d%d",&x,&a,&y,&b);
scanf("%lld",&k);
ans = -1;
rep(i,1,n) if( solve(i) >=k ){
ans = i;
break;
}
printf("%d\n",ans);
}
}

D. Sequence Sorting

res tp D

题意:给定一个序列,可以进行进行一种操作:选定一个x,之后将值为x的所有数字移动到序列的最左端或最右端,问最少进行多少次操作,使得序列满足单调不减

首先取出原序列中我们需要的信息,而其他的信息可以忽略。求出其每种元素的两个特征:初次出现位置和末次出现位置。

按元素值从小到大的序列就是我们最终要得到的序列。为了让操作数尽可能小,我们需要省去一些力气。如果原序列和终序列在某些地方是“相似”的,岂不是可以省去对这部分“相似”的操作吗?

具体地说,对终序列的两个数值紧邻的元素,若他们的分布区间不相交,且保证较小的元素的区间在较大的元素的左侧,那么这两种元素的相对位置在两个序列中是相等的,也就是说,它们对操作数没有贡献。

反之,至少要对其中的一个元素进行操作,同时,这也意味着,被操作元素那一侧的所有元素都要被操作。

综上,不需要操作的元素一定在终序列中是连续,于是可以dp出终序列满足条件的最长子区间,再用元素种类数减之即为答案

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i = (a);i>=(b);--i)
#define fo(i,a,b) for(int i =(a);i<(b);++i)
#define de(x) cout<<#x<<" = "<<x<<endl;
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a));
#define ls(p) ((p)<<1)
#define rs(p) (((p)<<1)|1)
using namespace std;
typedef long long ll;
const int mn = 3e5+10;
int q,n;
struct E{
int v,l,r;
}e[mn];
int vis[mn],t,cnt,mdp,dp;
bool cmp(E a,E b){return a.v <b.v;}
int main(){
scanf("%d",&q);
while(q--){
cnt = 1;
scanf("%d",&n);
rep(i,1,n){
scanf("%d",&t);
if(vis[t])
e[vis[t]].r = i;
else{
e[cnt].l = e[cnt].r = i;
e[cnt].v = t;
vis[t] = cnt++;
}
}
sort(e+1,e+cnt,cmp);
mdp = dp = 1;
int cnt1 = cnt - 1;
rep(i,2,cnt1){
if(e[i-1].r <e[i].l) ++dp;
else dp = 1;
mdp = max(mdp,dp);
}
printf("%d\n",cnt - 1 - mdp);
rep(i,1,cnt1) vis[e[i].v] = 0;
}
}

Technocup 2020 - Elimination Round 1补题的更多相关文章

  1. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)

    A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...

  2. 【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

    比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B ...

  3. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水题

    A. Math Problem Your math teacher gave you the following problem: There are n segments on the x-axis ...

  4. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) F. Tree Factory 构造题

    F. Tree Factory Bytelandian Tree Factory produces trees for all kinds of industrial applications. Yo ...

  5. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) A. Forgetting Things 水题

    A. Forgetting Things Kolya is very absent-minded. Today his math teacher asked him to solve a simple ...

  6. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C. p-binary 水题

    C. p-binary Vasya will fancy any number as long as it is an integer power of two. Petya, on the othe ...

  7. Codeforces Round #596 (Div. 1, based on Technocup 2020 Elimination Round 2)

    (第一把div1心态崩了,给大家表演了一把上蓝) (看来以后div1需要先读前三题,如果没把握切掉还是不要交了……) A: 题意是求最少用几个形如$2^{t}+p$的数拼出n,给定n和p.$n\leq ...

  8. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) F2. Wrong Answer on test 233 (Hard Version) dp 数学

    F2. Wrong Answer on test 233 (Hard Version) Your program fails again. This time it gets "Wrong ...

  9. Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

    链接 签到题,求出位数,然后9*(位数-1)+ 从位数相同的全一开始加看能加几次的个数 #include<bits/stdc++.h> using namespace std; int m ...

随机推荐

  1. 在centos7上使用packstack安装openstack

    简介 Packstack主要是由Redhat推出的用于概念验证(PoC)环境快速部署的工具.Packstack是一个命令行工具,它使用Python封装了Puppet模块,通过SSH在服务器上部署Ope ...

  2. node_exporter安装和配置

    1.二进制包安装 mkdir -p /opt/exporter 下载地址: wget https://github.com/prometheus/node_exporter/releases/down ...

  3. ROS机器人开发实践学习笔记3

    摘要: 刚刚开始学习ROS,打算入机器人的坑了,参考教材是<ROS及其人开发实践>胡春旭编著 机械工业出版社 华章科技出品.本来以为可以按照书上的步骤一步步来,但是,too young t ...

  4. WinCE 开发问题:不支持 Open Generic 方法的 GetParameters。

    WinCE中用的是Newtonsoft.Json.Compact.dll序列化Json的, 今天用Json解析类的时候, 提示异常:不支持 Open Generic 方法的 GetParameters ...

  5. SQL-W3School-高级:SQL DEFAULT 约束

    ylbtech-SQL-W3School-高级:SQL DEFAULT 约束 1.返回顶部 1. SQL DEFAULT 约束 DEFAULT 约束用于向列中插入默认值. 如果没有规定其他的值,那么会 ...

  6. 如何在CentOS 7上安装Memcached(缓存服务器)

    首先更新本地软件包索引,然后使用以下yum命令从官方CentOS存储库安装Memcached. yum update yum install memcached 接下来,我们将安装libmemcach ...

  7. JAVA 基础编程练习题22 【程序 22 递归求阶乘】

    22 [程序 22 递归求阶乘] 题目:利用递归方法求 5!. 程序分析:递归公式:fn=fn_1*4! package cskaoyan; public class cskaoyan22 { @or ...

  8. Java8中List的removeif()函数的使用示例

    代码: import java.util.List; import java.util.function.Predicate; import org.springframework.beans.fac ...

  9. STM32第二章I/O端口应用

    STM32F10xxx系列中,有7个I/O端口,每个端口有两个32位配置寄存器(GPIOx_CRL,GPIOx_CRH),两个32位数据寄存器(GPIOx_IDR和GPIOx_ODR),一个32位置位 ...

  10. .Netcore 2.0 Ocelot Api网关教程(7)- 限流

    本文介绍Ocelot中的限流,限流允许Api网关控制一段时间内特定api的总访问次数.限流的使用非常简单,只需要添加配置即可. 1.添加限流 修改 configuration.json 配置文件,对  ...