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

  1. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

  2. Educational Codeforces Round 59 (Rated for Div. 2) DE题解

    Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...

  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)补题

    慢慢来. 题目册 题目 A B C D E F G 状态 √ √ √ √ × ∅ ∅ //√,×,∅ 想法 A. Prime Subtraction res tp A 题意:给定\(x,y(x> ...

  10. 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. 🎀SpringBoot项目打包jar 并打包为exe启动

    简介 将SpringBoot项目打包jar并打包为exe启动,在无jdk环境下直接运行. 操作 SpringBoot打包为可执行jar(这里使用maven install) 注:如果存在前端页面需同时 ...

  2. Python爬取任意城市肯德基门店信息(json数据反序列化、提取数据、写入CSV)

    本案关键内容点:json数据反序列化.提取数据.写入CSV 创建csv,写入表头数据,脚本同目录下会创建名称为book的csv文件,且第一行插入表头内容 import csv f = open('bo ...

  3. 【深度学习】MLE视角下的VAE与DDPM损失函数推导

    正文 最大似然估计的由来 VAE和DDPM都是likelihood-based生成模型,都是通过学习分布->采样实现图像生成的: 这类模型最大的特点就是希望实现 \[\theta = \arg\ ...

  4. SpringBoot错误处理

    SpringBoot错误处理 1 SpringMVC写法 1.1 在单独的Controller写一个处理异常的方法处理 @Slf4j @RestController public class Hell ...

  5. 【BUG】C语言|左移之后,最高位的数字还在吗?(整型提升)

    文章目录 问题概述 应用 怀旧 问题概述 这个错是刚学c语言的时候碰到的,突然好想我的c语言老师,所以在此记录一下. #include<stdio.h> void main(){ unsi ...

  6. 【MOOC】华中科技大学计算机组成原理慕课答案-第四章-存储系统(二)

    待整理. 单选 1 32位处理器的最大虚拟地址空间为 A. 2G B. 8G C. 16G √D. 4G 2 在虚存.内存之间进行地址变换时,功能部件 ( )将地址从虚拟(逻辑)地址空间映射到物理地址 ...

  7. VS Code 插件 clangd的用法

    VS Code 插件 clangd的用法 目录 深入理解 VS Code 插件 clangd 的用法 1. clangd 的核心原理:语言服务器协议 (LSP) 与 Clang 分析 关键点: 2. ...

  8. Gin 实现基础 CRUD 接口

    前面2篇讲了关于 gin + mysql + jwt + rbac 等基础 web搭建操作, 主要目的还是学习 go 语言的一些应用工具, 然后本篇继续来实现一个名为 notice 的公告模块, 包含 ...

  9. RPC实战与核心原理之流量回放

    流量回放:保障业务技术升级的神器 回顾 时钟轮在 RPC 中的应用,核心原理就一个关键字"分而治之",我们可以把它用在任何需要高效处理大量定时任务的场景中,最具有代表性的就是在高并 ...

  10. DataFrame.iterrows的一种用法

    import pandas as pd import numpy as np help(pd.DataFrame.iterrows) Help on function iterrows in modu ...