A. Two Rabbits

思路:

很明显,如果(y-x)%(a+b)==0的话ans=(y-x)/(a+b),否则就为-1

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = +;
int main(){
int k;
scanf("%d",&k);
while(k--){
long long x,y,a,b,ans;
cin>>x>>y>>a>>b;
if((y-x)%(a+b)) ans=-;
else ans=(y-x)/(a+b);
cout<<ans<<endl;
}
}

B. Longest Palindrome

思路:

直接暴力找对于每个串的反串(也就是对于每个i都有a[i]==a[n-i-1]),然后接着再前面没有被找到过的串中找一个自身也是回文串的串放在答案串的中间即可

写的稍稍有一些麻烦

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=;
string s[maxn];
int flag[maxn];
string ans="",temp="";
int main()
{
int n,m,cnt=,x,y;
cin>>n>>m;
for(int i=;i<=n;i++) cin>>s[i],flag[i]=;
for(int i=;i<=n;i++){
if(flag[i]) continue;
for(int j=i+;j<=n;j++){
y=;
for(int k=;k<m;k++){
if(s[i][k]!=s[j][m-k-]){
y=;
break;
}
}
if(!y){
ans+=s[i];
flag[j]=;
flag[i]=;
cnt+=;
break;
}
}
if(!y) continue;
}
for(int i=;i<=n;i++){
if(flag[i]) continue;
int x=;
for(int j=;j<m/;j++){
if(s[i][j]!=s[i][m-j-]){
x=;
break;
}
}
if(!x){
temp+=s[i];
cnt++;
flag[i]=;
break;
}
}
if(cnt==){
cout<<""<<endl<<endl;
return ;
}
cout<<cnt*m<<endl;
cout<<ans<<temp;
for(int i=ans.size()-;i>=;i--) cout<<ans[i];
return ;
}

C. Air Conditioner

思路:

先对顾客到店的时间进行排序,之后对于每一个顾客判断[Li , Ri] 与 [LI - t ,Ri + t] 是否有交集即可

#include <bits/stdc++.h>
#define maxn 1000010
using namespace std;
#define ll long long
struct node{
ll t,l,h;
}costomer[];
int main() {
int t;
scanf("%d",&t);
while(t--){
int n;
ll m;
scanf("%d%lld",&n,&m);
ll mi=m,ma=m,tmp=;
int kk=;
for (int i = ; i <n ; ++i) {
cin>>costomer[i].t>>costomer[i].l>>costomer[i].h;
mi-=(costomer[i].t-tmp);
ma+=(costomer[i].t-tmp);
if(ma<costomer[i].l||mi>costomer[i].h){kk=;}
else {
mi=max(mi,costomer[i].l);
ma=min(ma,costomer[i].h);
tmp=costomer[i].t;
}
}
if(kk)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return ;
}

D. Shortest and Longest LIS

思路:

直接贪心即可,最短序列的话,对于一串大于号,我们把当前未使用过的数尽可能的放在左边

最长序列就是反过来,尽可能的放未使用过的小的数即可

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=2e5+;
int ans[maxn];
int main()
{
int t,n;
cin>>t;
string s;
while(t--){
cin>>n>>s;
int num=n,las=;
for(int i=;i<n;i++){
if(s[i]=='>'||i==n-){
for(int j=i;j>=las;j--)
ans[j]=num--;
las=i+;
}
}
for(int i=;i<n;i++) printf("%d ",ans[i]);
cout<<endl;
num=,las=;
for(int i=;i<n;i++){
if(s[i]=='<'||i==n-){
for(int j=i;j>=las;j--)
ans[j]=num++;
las=i+;
}
}
for(int i=;i<n;i++) printf("%d ",ans[i]);
cout<<endl;
}
return ;
}

E. 1-Trees and Queries

思路:

只要找到,a到b的最短路径跟k的关系就好了

这个关系就是:只要最短路径长度小于K,并且奇偶性跟K相同即可

证明的话很简单:如果走到终点还没到路径长度还没到k的话,就可以不停的往回走一次,再走向终点,这样路程的长度就为dis+2i,要想最后能回到终点很明显x要与k同奇偶

最短只需要通过求两点的LCA就可以求出,当然新加进来的一条边会对路径产生影响

但是我们只要再判断dis(a,x)+dis(b,y)+1 与 dis(a,y)+dis(b,x)+1 即可

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 100005
using namespace std;
struct edge{
int next,v;
}edges[maxn*];
int head[maxn],cnt,dep[maxn],f[maxn][],n,q;
void init()
{
memset(head,-,sizeof(head));
cnt=;
}
void addedge(int u,int v)
{
edges[cnt].next=head[u];
edges[cnt].v=v;
head[u]=cnt++;
}
void dfs(int u,int fa)
{
dep[u]=dep[fa]+;
for(int i=;i<=;i++)
f[u][i+]=f[f[u][i]][i];
for(int i=head[u];i!=-;i=edges[i].next)
{
int v=edges[i].v;
if(v==fa)
continue;
f[v][]=u;
dfs(v,u);
}
}
int lca(int x,int y)
{
if(dep[x]<dep[y])
swap(x,y);
for(int i=;i>=;i--)
{
if(dep[f[x][i]]>=dep[y])
x=f[x][i];
if(x==y)
return x;
}
for(int i=;i>=;i--)
{
if(f[x][i]!=f[y][i])
{
x=f[x][i];
y=f[y][i];
}
}
return f[x][];
}
int getdis(int a,int b){return dep[a]+dep[b]-*dep[lca(a,b)];}
int main()
{
scanf("%d",&n);
init();
int u,v,q,a,b,x,y,k;
for(int i=;i<n;i++){
scanf("%d%d",&u,&v);
addedge(u,v),addedge(v,u);
}
dfs(,);
scanf("%d",&q);
while(q--){
int flag=;
scanf("%d%d%d%d%d",&x,&y,&a,&b,&k);
int len1=getdis(a,b),len2=getdis(a,x)+getdis(b,y)+,len3=getdis(a,y)+getdis(b,x)+;
if(len1<=k&&(k-len1)%==) flag=;
if(len2<=k&&(k-len2)%==) flag=;
if(len3<=k&&(k-len2)%==) flag=;
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}

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

  1. Codeforces Round #620 (Div. 2)

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

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. Hyperledger Fabric 踩坑汇总

    搭建基础环境 阿里云安装出现的一些问题解决 1. [signal SIGSEGV: segmentation violation code=0x1 addr=xxx pc=xxx] 类似的错误:原始错 ...

  2. IIS-URL重写模块配置参考

    本文提供了URL重写模块的概述,并解释了该模块使用的配置概念. 功能概述URL重写模块将请求URL重写为显示给用户或Web应用程序的简单,用户友好和搜索引擎友好的地址.URL重写使用定义的规则进行评估 ...

  3. Go之第三方日志库logrus使用

    文章引用自 第三方日志库logrus使用 日志是程序中必不可少的一个环节,由于Go语言内置的日志库功能比较简洁,我们在实际开发中通常会选择使用第三方的日志库来进行开发.本文介绍了logrus这个日志库 ...

  4. 【Hibernate QBC】

    HibernateQBC public class HibernateQBC { //演示离线查询 @Test public void testSelect6() { SessionFactory s ...

  5. C语言:将字符串中的字符逆序输出,但不改变字符串中的内容。-在main函数中将多次调用fun函数,每调用一次,输出链表尾部结点中的数据,并释放该结点,使链表缩短。

    //将字符串中的字符逆序输出,但不改变字符串中的内容. #include <stdio.h> /************found************/ void fun (char ...

  6. 【代码审计】VAuditDemo 后台登录功能验证码绕过

    在 admin/logCheck.php中 $_POST['user']和$_POST['pass'] 未经过任何过滤或者编码处理就传入到$query中,可能存在万能密码绕过机制 但是$pass经过了 ...

  7. PHP弱类型(一)

    如图,id的值必须满足上述表达式,才能返回想要的值 与运算,只要出现false,整个表达式返回false 看见后面的==就想尝试一下弱类型绕过,参考资料:https://www.cnblogs.com ...

  8. Spring Boot 2.x 缓存应用 Redis注解与非注解方式入门教程

    Redis 在 Spring Boot 2.x 中相比 1.5.x 版本,有一些改变.redis 默认链接池,1.5.x 使用了 jedis,而2.x 使用了 lettuce Redis 接入 Spr ...

  9. mysql修改字符集为utf8

    https://zhidao.baidu.com/question/1642165712897935220.html

  10. 自定义配置 const

    自定义常量配置文件:settings/const.py # 自定义的常量配置文件,在settings中 from 该文件 import *,将名字全部丢给settings BANNER_COUNT = ...