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. 配置Thymeleaf模板引擎

    1).thymeleaf-starter: 关闭缓存 2).静态资源都放在static文件夹下就可以按照路径直接访问 3).页面放在templates下,直接访问 springboot ,访问项目的时 ...

  2. 🎀dubbo 2.7.2 启动报错【Unsupported generic type false】排查

    1.问题现象 dubbo服务启动时抛出异常Unsupported generic type false,但不影响服务正常发布. Caused by: java.lang.IllegalArgument ...

  3. Eclipse java项目转Maven项目

    1.右键项目->configure->选择maven->配置maven的pom.xml 2.在src/main下新建java文件,将原来src下的java文件夹拷贝至该目录下: 3. ...

  4. SpringBoot整合Redis日志反复提示Redis重连问题

    1. 报错信息如图: 2. 原因: spring boot 2.0之后spring-boot-starter-data-redis默认不再使用jedis连接redis,而是lettuce 这是lett ...

  5. 康谋分享 | 数据隐私和匿名化:PIPL与GDPR下,如何确保数据合规?(二)

    在上期数据隐私和匿名化系列文章中,我们主要分享了<中国个人信息保护法>(PIPL)和<欧盟通用数据保护条例>(GDPR)在涵盖范围.定义.敏感信息等方面的异同点,今天,我们将重 ...

  6. 我也来说说经典面试题目-“OOM异常会导致JVM退出吗?”

    经典面试题目"OOM异常会导致JVM退出吗? 我的回答是"这要分情况看,对于守护线程来说,OOM并不会导致JVM退出:对于非守护线程来说,如果某个线程捕获了OOM异常并正确进行了处 ...

  7. Linux TCP网关的线程结构方案

    如果所示: 无论客户端还是服务端链接网关的socket都拆分为读EPoll.写EPoll分别独立. 有两个线程:线程A(左).线程B(右): 线程A负责服务端Socket的读和客户端socket的写, ...

  8. 操作系统综合题之“银行家算法,计算各资源总数和Need还需要数量和解释什么是安全状态以及银行家进阶题(额外提出资源请求计算是否满足)”

    一.问题:某系统在某时刻的进程和资源状态如下表所示: 进程 Allocation(已分配资源数) (A B C D) Max(最大需要资源数) (A B C D) Avaliable(可用资源数) ( ...

  9. Torch-Pruning工具箱

    Torch-Pruning 通道剪枝网络实现加速的工作. Torch pruning是进行结构剪枝的pytorch工具箱,和pytorch官方提供的基于mask的非结构化剪枝不同,工具箱移除整个通道剪 ...

  10. C++ decltype类型推导

    1.decltype介绍 decltype(declare type,声明类型)为C++11 新增的关键字,和auto功能一样,用于在编译期间进行自动类型推导. auto和decltype关键字都可以 ...