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. python,获取当前日期且以当前日期为名称创建文件名

    爬虫爬取信息时,需要把爬取的内容存到txt文档中,且爬虫是每天执行,以日期命名能避免出现名称重复等问题,解决方法如下 import time import os import sys path = o ...

  2. 康谋分享 | aiSim5 物理相机传感器模型验证方法(一)

    摘要: aiSim5可以实时模拟复杂的传感器配置,在多GPU分布式渲支持的支持下,aiSim可以渲染20多个摄像头.10多个雷达和10多个激光雷达在同一环境下运行.aiSim5独有的实时渲染引擎能够满 ...

  3. 一、C语言概述

    声明 本文内容大多取自<高级语言程序设计一书>,为本人学习笔记记录,切勿用于商业用途. 第一节 计算机发展 电子计算机已经历的四个发展时代: 第一代:20 世纪 50 年代,主要采用真空电 ...

  4. PC端自动化测试实战教程-3-pywinauto 启动PC端应用程序 - 下篇(详细教程)

    1.简介 经过上一篇的学习.介绍和了解,pywinauto的强大,不言而喻吧!宏哥讲解和分享的是电脑自带和安装的应用程序.有些小伙伴或者童鞋们已经迫不及待地私信宏哥,如果在电脑中这个应用程序已经启用了 ...

  5. Java中的位运算符、移位运算符

    目录 1 概述 2 位运算符 2.1 $(与) 2.2 |(或) 2.3 ^(异或) 2.4 ~(非) 3 移位运算 3.1 左移运算符:<< 3.2 右移运算符:>> 3.3 ...

  6. 4G模块——大夏龙雀DX-CT511-A使用记录

    4G模块--大夏龙雀DX-CT511-A使用记录 加回车换行 115200波特率 重启: AT+RESET 6.关闭HTTP服务: AT$HTTPCLOSE 关闭网路 AT+NETCLOSE 1.TC ...

  7. Vue 3中的ref和template refs详解(含Vue2迁移到Vue3方法)

    Vue 3中的ref和template refs详解 在Vue 3中,ref和模板引用(template refs)是两个相关但不同的概念,它们在组合式API(Composition API)中扮演着 ...

  8. dom操作补充

    s5.html <!DOCTYPE html> <html lang="en"> <head>     <meta charset=&qu ...

  9. ESP32 MQTT对接巴法云平台

    ESP32 MQTT对接巴法云平台 MQTT(Message Queuing Telemetry Transport)是一种轻量级的 发布/订阅(Publish/Subscribe) 消息传输协议,专 ...

  10. React错误边界:原理、实现与应用

    @charset "UTF-8"; .markdown-body { line-height: 1.75; font-weight: 400; font-size: 15px; o ...