慢慢来。

题目册

题目 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. 最简单的babel+webpack配置

    首先先介绍一下2个重要的库:core-js 和 regenerator core-js core-js 是用于 JavaScript 的组合式标准化库,它包含 es5 (e.g: object.fre ...

  2. redis详解之cluster模式部署

    一.环境说明 1.Operation OS:CentOS7.22.ruby version >= 2.2.23.openssl zlib gcc>=4.8.5 二.开始部署 1.安装rub ...

  3. XXE外部实体注入漏洞——PHP

    前言 XXE Injection即XML External Entity Injection,也就是XML外部实体注入攻击.漏洞是在对非安全的外部实体数据进行处理时引发的安全问题. 在XML1.0标准 ...

  4. java Date 转mysql timestamp 秒数不一致

    mysql的字段类型是timestamp(0), java的类型的是util.Date, 在插入数据的时候发现, 数据库的实际数据秒数比预想的数据偶尔会大1秒. 问题的原因: mysql的timest ...

  5. Flutter移动电商实战 --(22)JSON解析和复杂数据模型转换技巧

    json转Model类 创建model文件夹,在里面新建category.dart类 主要根据这个json来分析我们要做成类的样子 { "code": "0", ...

  6. CloudFlare 新手入门中文教程

    loudFlare成立于2009年,是国外著名的免费CDN网站加速服务公司,CloudFlare 还提供实时安全保护服务和网络优化等,采用的是免费+增值模式,可以免费使用,也有收费服务.国内也有很多免 ...

  7. flask_security学习笔记

    [Flask Security]当不能通过认证的时候制定跳转   Flask Security这个插件能对用户权限进行很好的控制.通过三个model实现:User,存放用户数据Role,存放角色数据U ...

  8. 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_19-CMS前端页面查询开发-页面原型-Table组件测试

    页面填充内容.用一个表格来显示内容 3.1.2.1 Element-UI介绍 本项目使用Element-UI来构建界面,Element是一套为开发者.设计师和产品经理准备的基于 Vue 2.0 的桌面 ...

  9. Spark中的CombineKey()详解

    CombineKey()是最常用的基于键进行聚合的函数,大多数基于键聚合的函数都是用它实现的.和aggregate()一样,CombineKey()可以让用户返回与输入数据的类型不同的返回值.要理解C ...

  10. nginx反向代理本地 两台web负载均衡 使用ip+端口代理

    环境: 本地外网ip:123.58.251.166 .配置index.html网页 [root@host---- conf.d]# cat /web/sing/index.html <h1> ...