慢慢来。

题目册

题目 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)补题的更多相关文章

  1. Educational Codeforces Round 78 (Rated for Div. 2) --补题

    链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...

  2. Educational Codeforces Round 68 (Rated for Div. 2)补题

    A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...

  3. 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 ...

  4. 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 ...

  5. 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. ...

  6. 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 ...

  7. Educational Codeforces Round 74 (Rated for Div. 2)

    传送门 A. Prime Subtraction 判断一下是否相差为\(1\)即可. B. Kill 'Em All 随便搞搞. C. Standard Free2play 题意: 现在有一个高度为\ ...

  8. Educational Codeforces Round 74 (Rated for Div. 2)【A,B,C【贪心】,D【正难则反的思想】】

    A. Prime Subtractiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inpu ...

  9. 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[ ...

随机推荐

  1. Java分布式互联网架构/微服务/高性能/springboot/springcloud2018年10月16日直播内容

    2018年10月16日直播内容 架构师揭秘springboot对springmvc的自动配置原理 直播地址:https://ke.qq.com/course/179440?tuin=9b386640 ...

  2. Ubuntu 14.04 网卡网关配置修改

    #添加网关route add default gw 192.168.5.1#强制修改网卡地址ifconfig eth0 192.168.5.40 netmask 255.255.255.0. 服务器需 ...

  3. Python2.7编码问题:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position...解决方法

    解决方法: 在Python程序最前面加上以下语句: import sys reload(sys) sys.setdefaultencoding('utf-8')

  4. 【做题记录】Codeforces做题记录

    最近决定写一些CF Div.1的题,练习一下速度和代码能力. 暂定从中考后的Codeforces Round #572开始. 大部分比较简单的题直接把题解写在这里,不单独开文章了. Codeforce ...

  5. POJ 1661 Help Jimmy ——(记忆化搜索)

    典型的记忆化搜索问题,dfs一遍即可.但是不知道WA在哪里了= =,一直都没找出错误.因为思路是很简单的,肯定是哪里写挫了,因此不再继续追究了. WA的代码如下,希望日后有一天能找出错误= =: —— ...

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

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

  7. jenkins权限问题

    今天用jenkins的时候,构建失败,看了下控制台输出,提示是缺少权限,以前也遇到过这个问题,当时是通过把相关文件夹权限设置为777解决的,这种办法有两个不好的地方,一是这样一来任何用户都能操作这个文 ...

  8. mysql 给用户设置权限

    grant   all   on   wordpress.*   to  wordpress@'10.0.0.%'  identified  by  'wordpress'; all    全部权限 ...

  9. Android Popwindow使用总结

    Android Popwindow使用总结 转 https://www.jianshu.com/p/3812ff5ef272 1.基本使用方法 View view = getLayoutInflate ...

  10. linux 测试磁盘iops 方法详解

    一.FIO安装  wget http://brick.kernel.dk/snaps/fio-2.0.7.tar.gz  yum -y install libaio-devel  tar -zxvf ...