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[ ...
随机推荐
- 【概率论】2-1:条件概率(Conditional Probability)
title: [概率论]2-1:条件概率(Conditional Probability) categories: Mathematic Probability keywords: Condition ...
- 又见回文 (SDUT 2560)
Problem Description "回文串"是一个正读和反读都一样的字符串,比如"level"或者"noon"等等就是回文串.现在呢, ...
- yquery-操作样式属性
前几天回家,参加了全国的成人高考,都说学历是找工作的敲门砖,其实一点都不假,尤其是现在的社会竞争力那么强,你不学就会被淘汰.像要过自己想要的生活,就必须努力学习,努力赚钱,买自己想买的,过自己想过的. ...
- sql mode 问题及解决 错误代码:1055 this is incompatible with sql_mode=only_full_group_by
数据库升级到5.7.21后,一个正常的分组后按日期排序,并返回数据的语句开始报错: 语句如下: SELECT id,title,add_time FROM `message` GROUP BY add ...
- PHP 之快递100接口封装
<?php /** * Created by PhpStorm. * User: Yang * Date: 2019/8/23 * Time: 10:38 */ class Kuaidi_Que ...
- vs.net2017在编辑的wpf的xaml文件引用本程序集下的类提示“找不到”
local对应就是当前exe程序下的类,会提示“...命令空间...找不到...” 因为我调整过生成的,于是尝试调回来anyCPU 问题解决. 看了一下vs.net2017的所在目录"C:\ ...
- 表单事件集锦-input
最近在写一个手机端提交表单的项目,里面用了不少input标签,因为项目不太忙,所以,想做的完美点,但是遇到了一些问题,比如:页面中的必填项如果有至少一项为空,提交按钮就是不能提交的状态,所以需要对所有 ...
- Python 上下文管理器模块--contextlib
在 Python 处理文件的时候我们使用 with 关键词来进行文件的资源关闭,但是并不是只有文件操作才能使用 with 语句.今天就让我们一起学习 Python 中的上下文管理 contextlib ...
- 安装VMware虚拟机和centos操作系统
1,安装包:百度网盘: 2,安装教程:https://blog.csdn.net/qq_31362105/article/details/80706096 配置好操作系统,内存,网络等: 3,Cen ...
- R-CNN/Fast R-CNN/Faster R-CNN
一.R-CNN 横空出世R-CNN(Region CNN,区域卷积神经网络)可以说是利用深度学习进行目标检测的开山之作,作者Ross Girshick多次在PASCAL VOC的目标检测竞赛中折桂,2 ...