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[ ...
随机推荐
- 使用Python建模量子隧穿
引言 量子隧穿是量子力学中的一个非常有趣且令人神往的现象.在经典物理学中,我们通常认为粒子必须克服一个势垒才能通过它.但是,在量子力学中,粒子有时可以"穿越"一个势垒,即使它的能量 ...
- Jmeter接口关联总结
1.新建测试计划 输入相关接口如下: 本文以接口A(Phone Login)和接口B(Get ticket)两个接口为例进行关联 这两个接口的关系是:先执行接口A获取token作为参数,然后执行接口B ...
- ReentrantLock底层源码分析
一.简单使用 在聊它的源码之前,我们先来做个简单的使用说明.当我在IDEA中创建了一个简单的Demo之后,它会给出以下提示 提示文字 在使用阻塞等待获取锁的方式中,必须在try代码块之外,并且在加锁方 ...
- Mybatis-Plus中的@TableId
简介 在 MyBatis Plus 中,@TableId 注解是用于标记实体类中的主键字段.它可以更方便地处理主键相关的操作,如自动填充主键值或识别主键字段. 用法 public class User ...
- mysql、PikaDB的使用方法和优化策略
Mysql 字段选择 尽量选用INT,BIGINT,4字节8字节的消耗小于varchar.字符串选择VARCHAR增加拓展性. 时间应使用时间戳BIGINT存储,不使用DATETIME. 不使用BLO ...
- DNS滥用如何进行防范?
在当今数字化浪潮汹涌的时代,域名系统宛如互联网的基石,稳稳承载着将人们日常使用的便捷域名,精准转换为计算机能够识别与处理的IP地址这一关键任务.其重要性不言而喻,然而,随着DNS在全球范围内的广泛普及 ...
- 微信支付功能的设计实现与关键实践(UniApp+Java)全代码
感觉本篇对你有帮助可以关注一下我的微信公众号(深入浅出谈java),会不定期更新知识和面试资料.技巧!!! 温馨提醒:阅读时可打开导航栏 概述 在移动互联网时代,支付功能已成为应用开发的核心能力之一. ...
- EFCore——树形结构篇
1.整体数据量不大的场景 参照:EntityFramework Linq 查询数据获得树形结构-YES开发框架网 (yesdotnet.com) 核心方法GetChildData,特点将所有的数据查到 ...
- ElasticSearch学习文档
中文文档:https://doc.codingdict.com/elasticsearch/ Elastic 官方网站:Free and Open Search: The Creators of El ...
- 通过IP计算分析归属地
在产品中可能存在不同客户端,请求同一个服务端接口的场景. 例如小程序和App或者浏览器中,如果需要对请求的归属地进行分析,前提是需要先获取请求所在的国家或城市,这种定位通常需要主动授权,而用户一般是不 ...