HDU 5821 Ball
记录一下每个位置最终到达的位置。然后每次操作排序。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar(); int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=;
int T,n,m;
int a[maxn],b[maxn],f[maxn];
struct X{int pos;}s[maxn]; bool cmp(X a,X b){return a.pos<b.pos;} int main()
{
// File();
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m); memset(f,,sizeof f);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]); int ans=;
for(int i=;i<=n;i++)
{
s[i].pos=-;
for(int j=;j<=n;j++)
{
if(f[j]) continue;
if(a[i]!=b[j]) continue;
s[i].pos=j; f[j]=; break;
}
if(s[i].pos==-) ans=;
} for(int i=;i<=m;i++)
{
int L,R; scanf("%d%d",&L,&R);
sort(s+L,s+R+,cmp);
} for(int i=;i<=n;i++) if(s[i].pos!=i) ans=; if(ans) printf("Yes\n");
else printf("No\n");
}
return ;
}
HDU 5821 Ball的更多相关文章
- HDU 5821 Ball (排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5821 有n个盒子,每个盒子最多装一个球. 现在进行m次操作,每次操作可以将l到r之间盒子的球任意交换. ...
- HDU 5821 Ball (贪心)
Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...
- hdu 5821 Ball 贪心
Ball 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...
- HDU 5821 Ball (贪心排序) -2016杭电多校联合第8场
题目:传送门. 题意:T组数据,每组给定一个n一个m,在给定两个长度为n的数组a和b,再给定m次操作,每次给定l和r,每次可以把[l,r]的数进行任意调换位置,问能否在转换后使得a数组变成b数组. 题 ...
- hdu 5821 Ball 思维题
Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- hdu 5821 (贪心排序) Ball
题目:这里 题意:T组数据,两个长度都为n的数组,有m次操作,操作是对a数组而言,每次操作给一个区间范围l,r,可以将这个区间内的数任意交换顺序,问经过m次操作后, 是否可以将a数组变为b数组. 输入 ...
- HDU 4811 Ball 贪心
题目链接: 题目 Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 问题描述 ...
- HDU 5391Z ball in Tina Town 数论
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5391 bc: http://bestcoder.hdu.edu.cn/contests/c ...
- HDU 4811 Ball -2013 ICPC南京区域现场赛
题目链接 题意:三种颜色的球,现给定三种球的数目,每次取其中一个放到桌子上,排成一条线,每次放的位置任意,问得到的最大得分. 把一个球放在末尾得到的分数是它以前球的颜色种数 把一个球放在中间得到的分数 ...
随机推荐
- Linux教学辅助训练(第二阶段)
linux教学辅助训练(第二阶段) 标签(空格分隔):Linux辅助训练 ---更多资料点我查看 提示:本阶段性练习题是对<实战教学笔记>相应章节知识的归纳与扩展部分,必须要会,是面试前必 ...
- 算法笔记_014:合并排序(Java)
1 问题描述 给定一组数据,使用合并排序得到这组数据的非降序排列. 2 解决方案 2.1 合并排序原理简介 引用自百度百科: 合并排序是建立在归并操作上的一种有效的排序算法.该算法是采用分治法(Div ...
- Chrome浏览器加载CSS文件TTFB waiting超时的奇葩问题
今天本来调试 requirejs 加载js异常的问题,试了下Chrome浏览器,结果意外发现这个 CSS 加载异常的BUG,非常非常奇怪. 本地测试环境是 wi7x64 安装的 XAMPP 3.2.1 ...
- input失效后,怎么改变它默认就有的灰色
☆☆☆☆☆ input:disabled { -webkit-text-fill-color: rgba(0, 0, 0, 1); -webkit-opacity: 1; } 去掉button/sel ...
- c# PictureBox 的图像上使用鼠标画矩形框
C# 中在图像上画框,通过鼠标来实现主要有四个消息响应函数MouseDown, MouseMove, MouseUp, Paint重绘函数实现.当鼠标键按下时开始画框,鼠标键抬起时画框结束. Poin ...
- 防止sql注入 查询的sql
and userName like concat('%',#{userName},'%')
- python新手 实践操作 作业
#有如下值集合 [11,22,33,44,55,66,77,88,99],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中.即: {'k1': 大于66的所 ...
- Jquery 操作DropDownList 根据条件选中
$("#<%=DDLCounty.ClientID%> option").each(function () { if ($(this).text() == $(&quo ...
- 获取XMLHttpRequest对象
//创建一个XMLHttpRequest对象 ,利用此对象与服务器进行通信 是AJAX技术的核心 /////////////////////////////////////////////////// ...
- RedHat9.0下载地址
RedHat下载:http://archive.download.redhat.com/pub/redhat/linux/9/en/iso/i386/