A. Space Navigation

思路:分别统计往px和py方向的步数,看看能不能分别大于等于px和py。

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 endl '\n'
#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 = read(), y = read();
string s;
cin>>s;
ll xx1 = 0, yy1 = 0, xx2 = 0, yy2 = 0;
for(int i=0; i<s.size(); i++)
{
if(s[i]=='L') xx2--;
else if(s[i]=='R') xx1++;
else if(s[i]=='U') yy1 ++;
else yy2++;
}
int flag = 0;
int flag1 = 0;
if(y>=0&&yy1>=y) flag = 1;
else if(y<=0&&abs(yy2)>=abs(y)) flag = 1;
if(x>=0&&xx1>=x) flag1 = 1;
else if(x<=0&&abs(xx2)>=abs(x)) flag1 = 1;
puts(flag&&flag1?"YES":"NO"); }
return 0;
}

B. New Colony

思路:数据量小,直接模拟就行。最坏的情况全部走完也不需要很多k。

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 endl '\n'
#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} }; ll a[maxn]; int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read(), k = read();
rep(i,1,n) a[i] = read();
int pos = 0;
int flag = 0;
while(k>0)
{
k--;
rep(i,1,n)
{
if(i==n)
{
flag = 1;
break;
}
if(a[i]>=a[i+1]) continue;
pos = i;
a[i]++;
break;
}
if(flag) break;
}
if(k||flag) cout<<-1<<endl;
else cout<<pos<<endl;
}
return 0;
}

C. Fence Painting

思路:策略如下:

定义要改的数为\(a[i]!=b[i]\)的。

1.我遍历到当前的c[i],如果这个c[i]就是我要改的数,那优先改。

2.否则,如果当前这个数不是我要改的数,但是它是某个a[i]==b[i]产生的“不用改”,那就可以在对应位置修改。(这个是在不满足条件1的情况下才采取的下策)。

3.若还不满足上述条件,那就说明当前还找不到具体的位置放,那就先存起来,一旦后面遍历到的c[i]满足上述\((1) (2)\)之一,就可以让这些存起来的数放到他们的位置,反正会被覆盖掉。

4.详见代码注释吧。

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 endl '\n'
#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} }; ll a[maxn];
ll b[maxn];
ll c[maxn];
ll Ans[maxn]; int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read(), m = read();
map<ll,stack<ll> > Map; // Map存放需要改变的位置
map<ll,ll> Pos; //Pos记录一下每个b[i]对应的i,多个b[i]取最后那个
rep(i,1,n) a[i] = read();
rep(i,1,n)
{
b[i] = read();
if(a[i]!=b[i]) //只存放需要改变的位置
Map[b[i]].push(i);
Pos[b[i]] = i; //记录b[i]位置
}
rep(i,1,m) c[i] = read();
stack<ll > pre; //pre记录一下前面遇到没地方放的数
int flag = 1;
rep(i,1,m)
{
if(Map[c[i]].size()) //如果当前c[i]有对应需要改变的 ,就优先改
{
ll cur = Map[c[i]].top();
Map[c[i]].pop();
Ans[i] = cur;
a[cur] = b[cur];
while(pre.size()) // 同时把前面没地方放的那些数放到当前这个位置,意思就是前面随便改我这个位置,利用当前c[i]我又改回来
{
ll id = pre.top();
pre.pop();
Ans[id] = cur;
}
}
else //若没有一定要改的位置
{
if(Pos[c[i]]&&pre.size()) //先看看这个数存不存在(Pos[c[i]]),若同时前面有数放,则同上
{
while(pre.size())
{
ll id = pre.top();
pre.pop();
Ans[id] = Pos[c[i]];
Ans[i] = Pos[c[i]];
a[Pos[c[i]]] = b[Pos[c[i]]];
}
}
else if(Pos[c[i]]) Ans[i] = Pos[c[i]]; //前面没有数的但可以放,就放当前
else pre.push(i); //其他就没办法了,只能放进pre,让后面的c[j]来完成
}
}
rep(i,1,n) if(a[i]!=b[i]) flag = 0;
if(pre.size()) flag = 0;
if(flag)
{
cout<<"YES"<<endl;
rep(i,1,m) cout<<Ans[i]<<' '; cout<<endl;
}
else cout<<"NO"<<endl;
}
return 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. 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 ...

  10. Codeforces Round #545 (Div. 1) 简要题解

    这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...

随机推荐

  1. C# LINQ 快速入门实战指南,建议收藏学习!

    前言 因为咱们的.NET EF Core快速入门实战教程经常会用到 LINQ 去查询和操作 MySQL 中的数据,因此我觉得很有必要对 LINQ 的一些使用技巧.常用方法.特性做一个详细的介绍,让大家 ...

  2. Mybatis的关联关系的配置

    例子1. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC &qu ...

  3. 🎀FreeMarker 禁止自动转义标签-noautoesc

    简介 FreeMarker 是一个用 Java 语言编写的模板引擎,它被设计用来生成文本输出(HTML 网页.电子邮件.配置文件等).在 FreeMarker 中,默认情况下,当你在模板中输出变量时, ...

  4. MySQL 中 DATETIME 和 TIMESTAMP 类型的区别是什么?

    在MySQL中,DATETIME和TIMESTAMP都是用于存储日期和时间的类型,但它们有一些关键的区别: 1. 存储方式和范围 DATETIME: 存储的日期和时间值是以"年-月-日 时: ...

  5. 从 MySQL 获取数据,是从磁盘读取的吗?(buffer pool)

    从 MySQL 获取数据,是从磁盘读取的吗?(Buffer Pool) 在 MySQL 中,数据是否从磁盘读取取决于数据是否已经被加载到内存中.MySQL 使用 InnoDB 存储引擎 中的 Buff ...

  6. 【BUG】ELF文件执行时出现段错误Segmentation fault,解决:使用010编辑器修改ELF文件不可执行段权限

    问题:段错误,.eh_frame不可执行. 需求:改执行权限. 工具:010 Editer,我的版本:12.0.1 Windows 10. 工具下载:010编辑器官网下载页. 第一步 查看段的执行权限 ...

  7. tarjan(强连通分量、边双、点双)

    强连通分量 注意到一个强连通分量中 dfn 序最小的点一定有 \(dfn_u=low_u\).因此条件成立时就将自己和栈上方的点全部压入一个强连通分量中. 而如果枚举的 \(v\) 有 \(dfn\) ...

  8. JS函数调用的5种模式

    函数是经常会用的工具, 这里总结一下关于在 js 中的 5种函数调用的模式如下: <!DOCTYPE html> <html lang="en"> < ...

  9. C++ 11 make_shared

    make_shared的使用 shared_ptr<string> p1 = make_shared<string>(10, '9'); shared_ptr<strin ...

  10. C#之Bitmap

    SetPixel和GetPixel private void btnC_Click(object sender, RoutedEventArgs e) { OpenFileDialog dia = n ...