Educational Codeforces Round 74 (Rated for Div. 2)补题
慢慢来。
| 题目 | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 状态 | √ | √ | √ | √ | × | ∅ | ∅ |
//√,×,∅
想法
A. Prime Subtraction
res tp A
题意:给定\(x,y(x>y)\),问能否将\(x-y\)拆成任意多个质数之和
1.任意大于\(1\)的整数\(k\)都可以用\(2\)与\(3\)的线性表示
证:
若\(k\)是偶数,显然;
若\(k\)是奇数,则\(k\)可以表示成\(k = 3 + 2*k'\),显然;
毕。
#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 = 2e5+10;
ll x, y;
int t;
int main(){
cin>>t;
while(t--){
cin>>x>>y;
cout<<((x - y <= 1)? "NO":"YES")<<endl;
}
}
B. Kill 'Em All
res tp B
题意:\(x\)轴正半轴上有\(n\)只怪兽,每个怪兽都有它的坐标\(x_i\);负半轴充满陷阱,如果一个怪兽进入\(x \leq0\)的区域,它就会扑街。陷阱可以重复利用。你可以在某个点投弹,直接使该点的怪兽扑街(如果有的话),之后投弹点左侧的怪兽会因为王霸之气而被击退\(r\)的距离,右侧同理。问,至少需要投多少个导弹,才能让所有的怪兽扑街。
一个怪兽要么因直接击中而扑街,要么因踏入陷阱区而扑街。贪心地想,我们想要每个导弹的效益最大化,就将它投到场上怪兽坐标的最大值的位置,这样所有的怪兽都会向陷阱区前进,且在判定是否因陷阱死亡之前,导弹至少消灭掉了一只怪兽,这是一个导弹对总体情况能做的最大的贡献,因为若将导弹投入非最大值位置,那么必定会有怪兽向\(x\)轴正向前进,而它们要么被之后的导弹推回来,要么直接被消灭。
#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 = 1e5+10;
int q,n,r,t,lo,hi,ans,pos;
int x[mn];
int main(){
scanf("%d",&q);
while(q--){
scanf("%d%d",&n,&r);
lo = 1;hi = n;pos = 1;
ans = 0;
rep(i,1,n) scanf("%d",&x[i]);
sort(x+1,x+1+n);
while(lo <= hi){
--hi; ++ans; pos += r;
while(lo <= hi && x[hi] == x[hi+1]) --hi;
while(lo <= hi && x[lo] < pos) ++lo;
}
printf("%d\n",ans);
}
}
C. Standard Free2play
res tp C
题意:有一个长度为\(h\)的尺子,从刻度\(h\)开始出发,每个整数点都有一个特征\(0/1\),每次你需要做的是,将现在的位置特征\(x\)和\(x-1\)的位置取反,之后你可以前进到下一个特征为\(1\)的点,如果那个点与当前位置之间的距离不超过\(2\),很明显有时我们会陷入死路,我们可以花费一个魔力水晶,将任意位置的特征取反(包括\(h\)),问至少需要多少个魔力水晶,才能从\(h\)点走到\(1\)
我们将实的阶梯看作1,虚的阶梯看作0。对于一段连续的\(1\),如果它的长度是奇数,那么可以从高处走到低处而不花费魔力水晶;如果它的长度是偶数,那么就需要花费一个魔力水晶。同时,从一段\(1\)走到下一段\(1\)时,会向下一段传递一个额外的\(1\),最后对最后一段特判能否不花费水晶直接到达高度为\(0\)的阶梯即可。
#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 = 2e5+10;
int q,h,n,ans,cnt;
int p[mn];
int main(){
scanf("%d",&q);
while(q--){
scanf("%d%d",&h,&n);
rep(i,1,n) scanf("%d",&p[i]);
ans = 0;
cnt=1;
rep(i,2,n){
if(p[i-1] == p[i]+1) cnt++;
else{
if(cnt%2 == 0) ans++;
cnt = 2;
}
}
if(cnt%2 == 0){
if(p[n] > 1) ans++;
}
printf("%d\n",ans);
}
}
D. AB-string
res tp D
题意:给定一个字符串,问,有多少个子串是好子串,好子串的定义是,其中的任意一个字符,都属于该子串内的某个长度大于一的回文子串。
要想知道好子串的数量,我们只需要知道坏子串的数量就可以了。
对于所谓的坏子串而言,我们考虑某个串\(s_1……s_k\),对于\(s_2……s_{k-1}\)来说,它们一定都属于某个回文子串,因为,如果某个字符与其左侧或右侧的字符相等,则可以构成一个长度为\(2\)的回文,若都不相等,其左侧与右侧的字符相等,则可以构成一个长度为\(3\)的回文串,所以,一个串是否是坏子串仅仅取决于两端的字符。
我们假设\(s_1\not=s_2\),对于\(s_3\)而言,它不能等于\(s_1\),否则\(s_1\)就包含于回文串\(s_1s_2s_3\),可推\(s_i\not=s_1,i\geq2\),所以,坏子串是形如\(ABB……B\)的串,同理可推\(s_k\not=s_{k-1}\)的情况\(AA……AAB\)
#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;
char s[mn];
ll ans,n;
int l = 1;
int main(){
cin>>n;
cin>>s+1;
ans = n*(n-1)/2;
rep(i,2,n){
if(s[i] == s[l]) continue;
ans -= i - l;
if(l != 1) ans -= i - l - 1;
l = i;
}
if(l != 1) ans -= n - l;
cout<<ans;
}
Educational Codeforces Round 74 (Rated for Div. 2)补题的更多相关文章
- Educational Codeforces Round 78 (Rated for Div. 2) --补题
链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...
- Educational Codeforces Round 68 (Rated for Div. 2)补题
A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...
- Educational Codeforces Round 74 (Rated for Div. 2) D. AB-string
链接: https://codeforces.com/contest/1238/problem/D 题意: The string t1t2-tk is good if each letter of t ...
- Educational Codeforces Round 74 (Rated for Div. 2) C. Standard Free2play
链接: https://codeforces.com/contest/1238/problem/C 题意: You are playing a game where your character sh ...
- Educational Codeforces Round 74 (Rated for Div. 2) B. Kill 'Em All
链接: https://codeforces.com/contest/1238/problem/B 题意: Ivan plays an old action game called Heretic. ...
- Educational Codeforces Round 74 (Rated for Div. 2) A. Prime Subtraction
链接: https://codeforces.com/contest/1238/problem/A 题意: You are given two integers x and y (it is guar ...
- Educational Codeforces Round 74 (Rated for Div. 2)
传送门 A. Prime Subtraction 判断一下是否相差为\(1\)即可. B. Kill 'Em All 随便搞搞. C. Standard Free2play 题意: 现在有一个高度为\ ...
- Educational Codeforces Round 74 (Rated for Div. 2)【A,B,C【贪心】,D【正难则反的思想】】
A. Prime Subtractiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inpu ...
- Educational Codeforces Round 74 (Rated for Div. 2)E(状压DP,降低一个m复杂度做法含有集合思维)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100005];int pos[ ...
随机推荐
- Selenium结合BeautifulSoup4编写简单爬虫
在学会了抓包,接口请求(如requests库)和Selenium的一些操作方法后,基本上就可以编写爬虫,爬取绝大多数网站的内容. 在爬虫领域,Selenium永远是最后一道防线.从本质上来说,访问网页 ...
- Maven依赖传递
依赖传递原则: 1.路径最短原则 2.路径相同是先申明者优先(dependency申明顺序先的优先)
- Flask-login 例子
################################################################################ from flask.ext.logi ...
- 微信小程序开发常见坑
前段时间稍微涉猎了微信小程序开发,踩了一些坑,在此总结出来,希望能为小伙伴们提供一点帮助. 页面跳转 对于页面跳转,可能习惯性想到wx.navigateTo,但是在跳转到目标页面是一个tab时,此接口 ...
- 浏览器环境下的microtaks和macrotasks
带有可视代码执行顺序的原文链接https://jakearchibald.com/201...,此篇文字并非其完整翻译,加入了一部分自己的理解,比如将其中的task替换为macrotask或是删除了可 ...
- ROS 常用命令
1.查看网卡接口: /interface print 2.给网口添加IP地址: /ip address add address=192.168.1.254/24 interface=ether1 3 ...
- C11中的Unicode
在C11(ISO/IEC 9899:2011)标准中引入了对UTF8.UTF16以及UTF32字符编码的支持. 其中,UTF8字符直接通过char来定义,字面量前缀使用u8.比如: char c = ...
- 使用druid连接池带来的坑testOnBorrow=false
首先说一下自己程序中遇到的问题,前一段时间新写了一个项目,主要架构改进,为前端提供接口(spring +springmvc+mybatis) 在新项目中使用的是阿里的druid连接池,配置简单,除了数 ...
- Mybatis 事物回滚最简单的操作方式
简单例子 //假设这是一个service类的片段 try{ //出现异常 } catch (Exception e) { e.printStackTrace(); //设置手动回滚 Transacti ...
- Java NIO学习笔记 三 散点/收集 和频道转换
Java NIO散点/收集 Java NIO带有内置的分散/收集支持.散点/收集是读取和写入渠道过程中使用的概念. 从通道散射读取是将数据读入多个缓冲区的读取操作.因此,数据可以从通道“散布”到多个缓 ...