A. Two Rabbits

题意:数轴上有x,y,且x<y。x可以每次+a,y可以每次-b。问能否xy相遇。

思路:只要xy差值是a+b的倍数即可。

view code
#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, a, b;
cin>>x>>y>>a>>b;
if((y-x)%(a+b)==0) cout<<(y-x)/(a+b)<<endl;
else cout<<-1<<endl;
}
return 0;
}

B. Longest Palindrome

题意:给n个不同的字符串,问你删除掉若干个之后,然后把这些字符串任意拼接,能否组成一个回文串。

思路:一开始以为各个字符也能打乱卡了一下,后面才发现只是字符串直接打乱重组。

这样其实很好想了。首先我们考虑如果这个字符串本身是回文串的话,因为n个字符串互不相同,那么肯定找不出另一个跟它匹配的。所以如果存在,只能放在中间。

其次就是两两搭配,如果串a和串b放在两边能构成回文,就加进去。写的时候用一个head和tail的vector存一下结果就行了。

view code
#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} }; bool vis[505]; bool check(string s)
{
for(int i=0, j=s.size()-1; i<=j; i++, j--)
if(s[i]!=s[j]) return false;
return true;
} int main()
{
ll n, m;
cin>>n>>m;
vector<string> s;
vector<string> head;
vector<string> tail;
int flag = 1;
int cnt = 0;
string mid;
rep(i,1,n)
{
string item;
cin>>item;
s.pb(item);
if(check(item))
cnt++, mid = item;
}
for(int j=0; j<n; j++)
{
if(vis[j]) continue;
for(int k=j+1;k<n;k++)
{
if(vis[k]) continue;
string tmp = s[j] + s[k];
if(check(tmp))
{
head.pb(s[j]), tail.pb(s[k]), vis[j] = vis[k] = 1;
break;
}
}
}
if(cnt) head.pb(mid);
int len = 0;
for(int i=0; i<head.size(); i++) len += head[i].size();
for(int i=0; i<tail.size(); i++) len += tail[i].size();
cout<<len<<endl;
for(int i=0; i<head.size(); i++) cout<<head[i];
for(int i=tail.size()-1; i>=0; i--) cout<<tail[i];
cout<<'\n';
return 0;
}

C. Air Conditioner

题意:给你n个区间,每个区间有一个时刻,刚开始你的数为m,你可以每过1个单位时间就+1或-1,问你能否使得每个区间时刻到达时满足m在区间范围里。

思路:贪心。我们遍历到每个区间的时候,就先得到在满足前面所有区间的情况下,能达到的最短点最小值和右端点最大值。

然后看看当前区间与能得到的区间有无交集即可。满足的话继续更新这个最大范围区间

view code
#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} }; typedef struct Information
{
ll t;
ll l;
ll r;
}I;
I a[500]; int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read(), m = read();
rep(i,1,n) a[i].t = read(), a[i].l = read(), a[i].r = read();
int flag = 1;
ll mi = m, ma = m; //mi和ma记录当前区间能达到的最大范围的左右端点
ll t = 0; //刚开始时刻为0
for(int i=1;i<=n;i++)
{
ll curL = a[i].l, curR = a[i].r; //当前时刻的满足约束的最大区间
rep(j,i+1,n)
{
if(a[i].t != a[j].t)
{
i = j-1;
break;
}
curL = max(curL,a[j].l), curR = min(curR, a[j].r); //更新约束
}
if(a[i].t==a[n].t) i=n; //后面都是一个时刻了
if(curL>curR||curL>ma+a[i].t - t||curR<mi - a[i].t + t) //如果当前约束区间合法且能够由之前的满足题意区间达到就行(有交集),不然就直接break。
{
flag = 0;
break;
}
mi = max( mi - a[i].t + t, curL), ma = min(ma + a[i].t - t, curR); //更新最大范围
t = a[i].t;
}
puts(flag?"YES":"NO");
}
return 0;
}

Codeforces Round #620 (Div. 2) ABC 题解的更多相关文章

  1. Codeforces Round #312 (Div. 2) ABC题解

    [比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...

  2. Codeforces Round #620 (Div. 2)

    Codeforces Round #620 (Div. 2) A. Two Rabbits 题意 两只兔子相向而跳,一只一次跳距离a,另一只一次跳距离b,每次同时跳,问是否可能到同一位置 题解 每次跳 ...

  3. # Codeforces Round #529(Div.3)个人题解

    Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...

  4. Codeforces Round #557 (Div. 1) 简要题解

    Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...

  5. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  6. Codeforces Round #538 (Div. 2) (A-E题解)

    Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...

  7. Codeforces Round #531 (Div. 3) ABCDEF题解

    Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...

  8. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

  9. Codeforces Round #499 (Div. 1)部分题解(B,C,D)

    Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...

  10. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. java基础之Scanner类、 Random类

    一.使用Scanner类,完成接收键盘录入数据 格式: Scanner sc = new Scanner(System.in) sc.nextInt(); 二.获取1-n之间的随机数 格式: Rand ...

  2. macOS终端修改DNS

    以WiFi为例 networksetup -listallnetworkservices networksetup -setdnsservers Wi-Fi 8.8.8.8 networksetup ...

  3. EF Core 中避免 SQL 注入的三种写法

    SQL 注入攻击可能会对我们的应用程序产生严重影响,导致敏感数据泄露.未经授权的访问和应用程序受损.EF Core 提供了三种内置机制来防止 SQL 注入攻击. 1.利用 LINQ 查询语法和参数化查 ...

  4. Windows下将QT打包为可执行文件(exe)的完整流程,包含第三方库。

    打包我的 Qt/C++ 视觉应用:从依赖部署到单文件 EXE 的踩坑之旅 一.前言 最近完成了一个基于 Qt/C++ 的桌面视觉应用项目(proj_ai_vision_app).这个项目功能还挺复杂, ...

  5. centos7-NFS-网络文件系统

    NFS(network file system)网络文件系统 pdf文档下载链接 https://files.cnblogs.com/files/duxingren/NFS.zip 服务器192.16 ...

  6. Servlet创建的三种方式

    目录 1 实现Servlet接口 2 继承GenericServlet 3 继承HttpServlet 4 web.xml配置 关于servlet的创建,我们有三种方式. 实现Servlet接口 继承 ...

  7. 如何反向绘制出 .NET程序 异步方法调用栈

    一:背景 1. 讲故事 这个问题源于给训练营里的一位朋友分析的卡死dump,在分析期间我需要知道某一个异步方法的调用栈,但程序是 .framework 4.8 ,没有sos后续版本独有的 !dumpa ...

  8. AI 技术发展简史

    AI 智能体开发指南 AI技术发展简史 一.AI的定义与核心目标 人工智能(Artificial Intelligence,AI)自诞生以来,一直是计算机科学和软件工程领域的重要研究方向.随着计算能力 ...

  9. 保姆式Win11安装教程|Rufus工具制作U盘+绕过限制+驱动安装全解析(附资源包)

    Windows 11 简介 Windows 11是微软推出的全新一代操作系统,以直观交互和AI技术为核心升级.其界面采用圆角设计和居中任务栏布局,支持多窗口贴靠分屏与虚拟桌面功能,提升多任务处理效率. ...

  10. 总决赛定档!“天翼云息壤杯”高校AI大赛巅峰之战即将打响!

    近日,为梦想添翼,让AI发光--"天翼云息壤杯"高校AI大赛总决赛时间正式揭晓.总决赛将于2025年7月1日至7月17日在北京举办.届时,来自全国各地上百支成功晋级的优秀队伍和特邀 ...