Educational Codeforces Round 74 (Rated for Div. 2) ABC 题解
A. Prime Subtraction
题意:问你能不能找到一个质数p,使得 b = a - np, 其中a、b给出。
思路:
1.若a - b本身就是质数,那肯定可以。
2.若a - b本身是合数,由唯一分解定理可知该合数可以写成p\({_1 ^x}\) * p\({_2 ^y}\) * ... * p\({_n ^z}\),此时提取一个p来就可以写成np的形式了。
所以除了a - b = 1的情况不行,其他均可以
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll x, y;
cin>>x>>y;
puts(x-y==1?"NO":"YES");
}
return 0;
}
B. Kill 'Em All
题意:一维坐标正半轴上有若干怪物,在x上放个炸弹,能炸死x上的怪物,同时让x左边的怪物位置全部-r,右边的全部+r,怪物到小于等于0的位置时也会死。问最少放多少个炸弹搞定所有怪兽。
思路:贪心一下。既然爆炸点位置右边的会往右偏,那我们就每次都在最右边存在的怪物放炸弹,把前面的怪物往负半轴推就行了。所以用双指针L,R,L代表前L-1个怪物已经被消灭了,R代表目前要炸的那个怪兽编号。每次放一个炸弹就二分一下[L,R]区间内能把多少个数减到小于等于0,同时R--。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <unordered_map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline int read(){ int f = 1; int x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int a[maxn];
unordered_map<int,int> Map;
int main()
{
FAST;
cin.tie(0), cout.tie(0);
int kase;
scanf("%d",&kase);
while(kase--)
{
Map.clear();
int n = read(), r = read();
int p = 0;
rep(i,1,n)
{
int x = read();
if(!Map[x]) a[++p] = x;
Map[x] ++;
}
if(n==1&&r==1)
{
cout<<1<<'\n';
continue;
}
sort(a+1,a+1+p);
int L = 1, R = p;
int cur = 1;
int cnt = 0;
while(L<=R)
{
int id = upper_bound(a+L,a+R+1,cur*r) - a;
id--;
cnt++;
cur++;
L = id+1;
R--;
}
cout<<cnt<<'\n';
}
return 0;
}
C. Standard Free2play
题意:下台阶,每个高度都有台阶,只不过有的显形有的隐形,并且刚开始给出n个显形的台阶。每次站到一个显形台阶上时,x-1的位置的台阶如果是隐形的就会变成显形的,如果是显形的就会变成隐形的。在每次下降不能超过2个单位的情况下,问最少改变多少个台阶的状态才能到达位置0。
脑补一下下台阶的过程:
1.当前我站的这个位置肯定是显形的(废话)
2.如果脚下的台阶本身是隐形的,那交换完状态后显形,就直接下去。
3.如果脚下的台阶是显形的,若x-2的位置还有一个显形的,那就不慌,直接到x-2的位置。但是x-2的位置是隐形的话,那没办法了,只能用一次魔法,到哪里呢?到x-1或x-2都行,因为这两个地方本身就没有台阶,就算x-3有显形台阶,从这两个状态下去也是一样的(照样x-3台阶会消失)。
所以,我们发现对答案有贡献的只有在x+1本身有台阶而x+2没有的情况。所以我们就遍历一遍数组,看a[i]!=a[i+1]的有多少对即可(从n=2开始),相等的时候就i再移动一位。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <unordered_map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 2e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline int read(){ int f = 1; int x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int a[maxn];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
int h = read(), n = read();
rep(i,1,n) a[i] = read();
a[n+1] = 0;
int cnt = 0;
rep(i,2,n) if(a[i] != a[i+1] + 1) cnt ++; else i++;
cout<<cnt<<'\n';
}
return 0;
}
Educational Codeforces Round 74 (Rated for Div. 2) ABC 题解的更多相关文章
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Educational Codeforces Round 59 (Rated for Div. 2) DE题解
Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...
- 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)补题
慢慢来. 题目册 题目 A B C D E F G 状态 √ √ √ √ × ∅ ∅ //√,×,∅ 想法 A. Prime Subtraction res tp A 题意:给定\(x,y(x> ...
- 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[ ...
随机推荐
- Clion配置Fortran环境
1.安装CLion 下载链接:https://www.jetbrains.com/ 下载好后安装到指定目录即可 2.安装Fortran插件 3.编写程序 1)打开CLion,新建一个Fortran项目 ...
- Golang从0到1实现简易版expired LRU cache带图解
1.支持Put.Get的LRU实现 想要实现一个带过期时间的LRU,从易到难,我们需要先学会如何实现一个普通的LRU,做到O(1)的Get.Put. 想要做到O(1)的Get,我们很容易想到使用哈希表 ...
- .net6 api添加接口注释
参照: .NET 6 Swagger添加xml注释 - 凡尘一叶~ - 博客园 (cnblogs.com)[这个比较准] .net core的Swagger接口文档使用教程(一):Swashbuckl ...
- Java Objects.equals(a,b)的说明
一:值是null的情况: a.equals(b), a 是null, 抛出NullPointException异常. a.equals(b), a不是null, b是null, 返回false Obj ...
- Go-Spring v1.2.0 版本简介
引言 随着微服务和云原生架构的普及,Go 语言以其高并发.低延迟和简洁语法在后端开发领域迅速崛起.然而,原生 Go 在项目结构.依赖管理.配置热更新等方面相比 Java Spring 生态尚有短板.G ...
- 【经验】you-get + ffmpeg|b站音频下载
一.原理: you-get下载,ffmpeg音视频分离. 这两个都是命令行工具. you-get安装(无python环境请参考python详细安装教程): pip3 install --upgrade ...
- 探秘Transformer系列之(32)--- Lookahead Decoding
探秘Transformer系列之(32)--- Lookahead Decoding 目录 探秘Transformer系列之(32)--- Lookahead Decoding 0x00 概述 0x0 ...
- vue3 基础-API-响应式 ref, reactive
上篇咱介绍了 CompositionAPI, 其核心思想是直接在函数作用域内定义响应式状态变量,并将从多个函数中得到的状态组合起来处理复杂问题. 然后初介绍了 setup 函数的作用, 即其是在 cr ...
- 入门神经网络-Python 实现(下)
回顾 紧接着上篇, 整到了, MES的公式和代码的实现. \(MSE = \frac {1}{n} \sum\limits_{i=1}^n (y_i - \hat y_i)^2\) n 表示样本数, ...
- Beautiful code and beautiful life
You may ask me why do i strive constantly, what i am striving for? Yep, the same question haunts me ...