Codeforces Round #699 (Div. 2) ABC题解
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题解的更多相关文章
- Codeforces Round #312 (Div. 2) ABC题解
[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #499 (Div. 1)部分题解(B,C,D)
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
- 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 ...
- Codeforces Round #545 (Div. 1) 简要题解
这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...
随机推荐
- Spring底层AOP代码实现
一. AOP功能测试 ①. pom.xml 依赖导入 ②. 目标类 ③. 切面类 ④. 配置类 ⑤. 测试类 二. AOP原理-@EnableAspectJAutoProxy AOP原理:[看给容器中 ...
- TGCTF2025 部分题目WP
TGCTF 2025 Web AAA偷渡阴平 ?tgctf2025=eval(end(current(get_defined_vars())));&b=system('cat /flag'); ...
- 7 个最近很火的开源项目「GitHub 热点速览」
可能很多人昨天都刷到了消息:GitHub 抽风,导致中国区未登录的用户无法访问,现在问题已经修复. 看到这个消息时,我的第一反应也是"被制裁了?"从震惊到平静,不过短短几分钟,随即 ...
- 定时任务Cron表达式工具类Cron Util
依赖 cron-utils的github地址:https://github.com/jmrozanec/cron-utils <dependency> <groupId>com ...
- TextBox输入法控制,进入输入框则启用或禁用输入法(ime),禁用后只能输入英文
有的场景需要禁止用户打开ime模式(禁止输入法输入),所以 TextBox 支持默认属性配置,效果如下: <Window x:Class="切换输入法.MainWindow" ...
- 全局搜索——Lucene.net 项目
1.GitHub - LonghronShen/Lucene.Net.Analysis.PanGu at netcore 2.Net Core使用Lucene.Net和盘古分词器 实现全文检索 - t ...
- EFCore 实体追踪
理解: EFCore通过一种机制实时追踪实体的属性是否有改变的一种机制,比如下方代码 通过EFCore查出来的数据List集合里的实体,在item.Manager = "菲菲";属 ...
- Sentinel——流控规则
目录 流控规则 QPS 设置流控规则 api设置流控规则 资源实体指定流控规则 并发线程数 Sentinel 隔离方案 流控模式-关联 流控模式-链路 控制效果 快速失败 Warm Up 排队等待 三 ...
- Java--事务,操作数据库,实现转账
更新:2019/3/29 目录 简介 事务的四个特性 一个小Demo 目录结构 jdbc.properties JDBCUtil.java TestTransaction.java[核心代码] 数据库 ...
- Vue技术之“关于sortable排序的使用”
Vue关于sortable排序的使用 方案1 在使用sortable后要注意给el-table-column中加入prop="overdueDays"参数,不然会找不到需要排序的数 ...