Technocup 2020 - Elimination Round 1补题
慢慢来。
题目 | 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补题的更多相关文章
- 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. 题解:很显然只有 \( ...
- 【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)
比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #596 (Div. 1, based on Technocup 2020 Elimination Round 2)
(第一把div1心态崩了,给大家表演了一把上蓝) (看来以后div1需要先读前三题,如果没把握切掉还是不要交了……) A: 题意是求最少用几个形如$2^{t}+p$的数拼出n,给定n和p.$n\leq ...
- 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 ...
- Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)
链接 签到题,求出位数,然后9*(位数-1)+ 从位数相同的全一开始加看能加几次的个数 #include<bits/stdc++.h> using namespace std; int m ...
随机推荐
- LOJ2341. 「WC2018」即时战略 [动态点分治]
LOJ 思路 考虑最蠢的暴力:枚举2~n,从1拉一条到他们的链,需要查询\(n^2\)次,显然不能通过. 考虑优化:如果拉的第一个点已经被访问过了,那么类似二分的做法,一次往那个方向多跳几步. 多跳几 ...
- ipv4保留地址
曾经以为保留地址下面三类.原来使用中还有很多的. A类 10.0.0.0--10.255.255.255 B类 172.16.0.0--172.31.255.255 C类 192.168.0.0--1 ...
- c++ 数组赋值
// generate_n example #include <iostream> // cout #include <algorithm> // generate_n usi ...
- dosbox+masm汇编环境的安装和使用
1. 下载dosbox安装程序:DOSBox0.74-win32-installer.exe 链接:https://pan.baidu.com/s/1gXPKTT-xKb6BpjOJdhmudA 密码 ...
- codeforces#1215E. Marbles(状压dp)
题目链接: http://codeforces.com/contest/1215/problem/E 题意: 至少多少次操作可以使得相同的数都是相邻的 每次操作可以交换两个相邻的数 数据范围: $1\ ...
- vue props传值后watch事件未触发的问题
父组件传值,子组件监听,明明很简单的一个事情,硬是卡了许久(毕竟不是专业搞前端的,还是吃亏在学识浅陋).也和自己钻牛角尖有关,想自己解决问题. 早期我写过一篇vue组件传值的文章,传值方式是这样的: ...
- 设顺序表中的数据元素递增有序,试着写一算法,将x插入到顺序表上的适当位置上,以保持该表的有序性。
原创,转载请注明出处.https://www.cnblogs.com/yangf428/p/11254370.html 天勤例题[2-1]: 设顺序表va中的数据元素递增有序.试写一算法,将x插入到顺 ...
- 在阿里云上挂在/data脚本
在阿里云上加好一块磁盘后,将他分区,挂在在/data,并且设置开机自动挂在/etc/fstab [root@ZHONG-LONG javascripts]# vim mount.sh #!/bin/b ...
- kotlin泛型类型变异
在java泛型中中会有 ? extends E 可以解决类似于List<String> 赋给List<Object> 的问题,但是在kotlin泛型中并没有提供通配符,而是o ...
- 安装SQL server 提示重新启动计算机失败
SQL Server2008是一款功能强大.实用性强的mysql数据库管理系统,因此很多用户都会在Win7系统中安装SQL Server2008,但是不少用户在安装过程中遇到问题,安装SQL Serv ...