A. Space Navigation
水题,确认能走到的区间范围就可。
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PIL pair<int, ll>
#define endl '\n'
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define IOS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define debug(x) cerr << #x << " = " << x << endl
#define debug2(x, y) cerr << #x << " = " << x << " and " << #y << " = " << y << endl
#define Pi acos(-1)
using namespace std;
const int N = 2e5 + 100;
int main()
{
IOS;
int t;
cin >> t;
while(t --)
{
int x, y;
int o1 = 0, o2 = 0, o3 = 0, o4 = 0;
string a;
cin >> x >> y;
cin >> a;
for(int i = 0; i < a.size(); i ++)
{
if(a[i] == 'R') o1 ++;
else if(a[i] == 'L') o2 --;
else if(a[i] == 'U') o3 ++;
else o4 --;
}
if(x >= o2 && x <= o1 && y >= o4 && y <= o3) cout << "YES" << '\n';
else cout << "NO" << '\n';
}
return 0;
}
B. New Colony
试着找了一会儿规律,发现是找不到的,重新看题目数据以后发现n
和h[i]
都只有100,说明最坏的情况下也只要100*100就可以将其变为最终状态,所以可以直接按题意模拟,如果没有变成最终状态的话,直接输出当前k
所对应的位置,一旦变为了可滚下的状态并且k还有剩余的话,就跳出循环并输出-1。
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PIL pair<int, ll>
#define endl '\n'
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define IOS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define debug(x) cerr << #x << " = " << x << endl
#define debug2(x, y) cerr << #x << " = " << x << " and " << #y << " = " << y << endl
#define Pi acos(-1)
using namespace std;
const int N = 2e5 + 100;
int a[N];
int main()
{
IOS;
int t;
cin >> t;
while(t --)
{
int n, k, now = 0, bj = 0;
cin >> n >> k;
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 0; i < k; i ++)
{
int p = 0;
for(int j = 2; j <= n; j ++)
{
if(a[j] > a[j - 1])
{
a[j - 1] ++;
now = j - 1;
p = 1;
break;
}
}
if(!p)
{
bj = 1;
cout << "-1" << '\n';
break;
}
}
if(!bj)
cout << now << '\n';
}
return 0;
}
C. Fence Painting
可以这样考虑,对于每一个 ai != bi
的位置i
,我们都需要一个ci
来改变,而如果当前的 ci
没有对应的位置去进行改变,那么我们就可以将这次改变施加到最后一次会填好正确的颜色的位置上,这样的话相当于可以抵消掉这些多余的ci
。
需要注意的是如果正向染色的话,我们可能会无法确定 cm
所修改的位置是哪。所以需要反向染色,先将 cm
所在的位置确定之后,就可以将多余的ci
染到 cm
应在的位置上了。
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PIL pair<int, ll>
#define endl '\n'
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define IOS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define debug(x) cerr << #x << " = " << x << endl
#define debug2(x, y) cerr << #x << " = " << x << " and " << #y << " = " << y << endl
#define Pi acos(-1)
using namespace std;
const int N = 2e5 + 100;
int a[N], b[N], c[N];
vector<int> G[N], ans;
int main()
{
IOS;
int t;
cin >> t;
while(t --)
{
ans.clear();
int ict = 0;
int n, m;
int xb = 0;
cin >> n >> m;
for(int i = 1; i <= n; i ++) G[i].clear();
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= n; i ++)
{
cin >> b[i];
if(b[i] != a[i])
G[b[i]].push_back(i), ict ++;
}
for(int i = 1; i <= m; i ++) cin >> c[i];
for(int i = 1; i <= n; i ++)
if(b[i] == c[m])
{
xb = i;
break;
}
if(!xb)
{
cout << "NO" << '\n';
continue;
}
for(int i = m; i; i --)
{
if(G[c[i]].empty()) // 如果当前颜色不需要修改的话
{
debug(i);
if(i == m) ans.push_back(xb); //trick,当 cm 不需要修改的时候
else ans.push_back(ans[0]); // 多余的就涂到最后一次涂的位置上
continue;
}
ans.push_back(G[c[i]].back()); //修改
G[c[i]].pop_back(); //删除已修改的位置
ict --;
}
if(!ict)
{
reverse(ans.begin(), ans.end()); //倒序输出
cout << "YES" << '\n';
for(int i = 0; i < ans.size(); i ++) cout << ans[i] << " ";
cout << '\n';
}
else
cout << "NO" << '\n';
}
return 0;
}