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. 松软科技课堂:JavaScriptDOM - 改变 CSS

    HTML DOM 允许 JavaScript 更改 HTML 元素的样式. 改变 HTML 样式 如需更改 HTML 元素的样式,请使用此语法: document.getElementById(id) ...

  2. VMware安装ACS5.8

    1.所需组件: VMware ACS5.8 iso 2.安装要求: 2 Core Processor 4 GB RAM 60 GB Hard drive 这些要求算是比较低的要求,不能比这个更low了 ...

  3. leetcode929 Unique Email Addresses

    Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...

  4. 对 Element UI table中数据进行二次处理

    (1)<el-table-column>标签加上 :formatter="dateFormat" <el-table-column prop="Star ...

  5. python二维数组的创建

    话不多说,代码伺候 m = [[]*]*3 #创建一个3行5列的二维数组 m[][]= print(m) 输出结果为: 分析: m = [[0]*5]*3只是指向三个空列表的引用. 创建一个二维数组的 ...

  6. try catch和if else

    当错误发生时,当事情出问题时,JavaScript 引擎通常会停止,并生成一个错误消息.描述这种情况的技术术语是:JavaScript 将抛出一个错误. try 语句允许我们定义在执行时进行错误测试的 ...

  7. 嵌入式大赛PPT

    题目:基于SLAM的移动机器人设计 嵌入式PPT应具有的几个部分 1.有哪些硬件 1)小车 2)STM32F429开发板 3)树莓派3b+开发板 4)4g通信模块 5)GPS模块 6)Kinect摄像 ...

  8. Emprie 使用基础笔记

    0x01 简介 empire 是一个后渗透攻击框架,具有加密通信和灵活框架的功能.Empire可以在不需要Powershell.exe的情况下执行PowerShell代理,后期利用的模块很强大,如sc ...

  9. windows下如何快速删除大文件

    rmdir  磁盘:\文件夹的名字  /s /q; eg:rmdir E:\vue_workspace\KB\day08    /s/q /S 表示除目录本身外,还将删除指定目录下的所有子目录和文件. ...

  10. Unity中调用Windows窗口选择文件

    1.OpenFileName数据接收类,如下: using UnityEngine; using System.Collections; using System; using System.Runt ...