题目链接:Dashboard - Codeforces Round 996 (Div. 2) - Codeforces
A. Two Frogs
思路
小博弈,可以发现把其中一个青蛙逼到墙角就行,谁会赢取决于初始时这两个青蛙相距的距离
代码
#include<bits/stdc++.h>
using namespace std;
#define vcoistnt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ull unsigned long long
#define bit __builtin_popcountll
#define lowbit(x) ((x)&-(x))
#define vi vector<int>
#define vb vector<bool>
typedef pair<int,int> pll;
const int N=2e5+10;
const int inf=1e18;
const int mod=998244353;
void solve(){
int n,a,b;
cin>>n>>a>>b;
int t=abs(a-b)-1;
if(t%2){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
signed main() {
vcoistnt
int _=1;
cin>>_;
while(_--) solve();
return 0;
}
B. Crafting
思路
题意是要使所有a[i]>=b[i],要a[i]+1的话那么其他的要-1,可以发现,如果a[i]<b[i]的数量大于1的话是永远不能够完成的,那么我们只需要考虑1个或0个的情况即可
代码
#include<bits/stdc++.h>
using namespace std;
#define vcoistnt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ull unsigned long long
#define bit __builtin_popcountll
#define lowbit(x) ((x)&-(x))
#define vi vector<int>
#define vb vector<bool>
typedef pair<int,int> pll;
const int N=2e5+10;
const int inf=1e18;
const int mod=998244353;
void solve(){
int n;
cin>>n;
vi a(n+10),b(n+10);
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
int mi=inf;
int cnt=0;
int t=0;
for(int i=1;i<=n;i++){
if(a[i]<b[i]){
cnt++;
t=b[i]-a[i];
}else{
mi=min(mi,a[i]-b[i]);
}
}
if(cnt>=2){
cout<<"NO\n";return;
}
if(cnt==0){
cout<<"YES\n";return;
}
if(cnt==1&&t<=mi){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
signed main() {
vcoistnt
int _=1;
cin>>_;
while(_--) solve();
return 0;
}
C. The Trail
思路
往矩阵里面填数,可以发现只要知道一个数那么就可以把这个矩阵填起来,那么根据性质来,令行和或列和为S,所有数相加S*n=S*m ,因为可能所以我们让S=0,那么就可以对整个矩阵进行填数
代码
#include<bits/stdc++.h>
using namespace std;
#define vcoistnt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ull unsigned long long
#define bit __builtin_popcountll
#define lowbit(x) ((x)&-(x))
#define vi vector<int>
#define vb vector<bool>
typedef pair<int,int> pll;
const int N=2e5+10;
const int inf=1e18;
const int mod=998244353;
void solve(){
int n,m;
cin>>n>>m;
string s;
cin>>s;
vector<vi> g(n+10,vi(m+10,0));
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>g[i][j];
}
}
int x=1,y=1;
int sum=0;
for(int i=0;i<s.size();i++){
int t=0;
if(s[i]=='R'){
for(int j=1;j<=n;j++){
t+=g[j][y];
}
g[x][y]=-t;
y++;
}else{
for(int j=1;j<=m;j++){
t+=g[x][j];
}
g[x][y]=-t;
x++;
}
}
int l=0;
for(int i=1;i<=m;i++){
l+=g[n][i];
}
g[n][m]=-l;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cout<<g[i][j]<<" ";
}
cout<<"\n";
}
}
signed main() {
vcoistnt
int _=1;
cin>>_;
while(_--) solve();
return 0;
}
D. Scarecrow
思路
一个贪心+模拟的题,关于乌鸦跳到后面的点可以大体分为三种情况:
1.乌鸦在0位置时刚开始,如果0位置有稻草人就跳到k位置,如果没有就需要第一个稻草人花费时间到0位置
2.在中间跳跃的过程又分为三种情况吧,设乌鸦所在位置为now,前一个稻草人的位置是a[at],下一个稻草人的位置是a[at+1],已经花费时间是time
2.1:如果下一个稻草人的可移动距离的右端点要比now小,那么我们让now=a[at+1]+time+k;
2.2:如果下一个稻草人的可移动距离涵盖了now,我们就让now+=k;
2.3:如果下一个稻草人的可移动距离的左端点要大于now,我们就同时让前一个稻草人和下一个稻草人花费时间同时移动,直到乌鸦能到达下一个稻草人
3.最后如果没跳到目标l点那么就需要最后一个稻草人花费时间到(l-k)的点让乌鸦到达l点
代码
#include<bits/stdc++.h>
using namespace std;
#define vcoistnt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ull unsigned long long
#define bit __builtin_popcountll
#define lowbit(x) ((x)&-(x))
#define vi vector<int>
#define vb vector<bool>
typedef pair<int,int> pll;
const int N=2e5+10;
const int inf=1e18;
const int mod=998244353;
void solve(){
int n,k,l;
cin>>n>>k>>l;
vi a(n+10);
for(int i=1;i<=n;i++){
cin>>a[i];
}
double time=0; //记录时间
int at=1; //记录当前在哪个稻草人之后
double now=0; //记录当前乌鸦所在位置
if(a[1]>0){
time+=a[1];
}else{
while(at<=n&&a[at]==0) at++;
at--;
}
now=k;
auto fly=[&](auto self)->void{
if(at<n){
if(a[at+1]+time<=now){
now=a[at+1]+time+k;
at++;
self(self);
}else if(a[at+1]+time>now&&a[at+1]-time<=now){
now+=k;
at++;
self(self);
}else if(now<a[at+1]-time){
int x=a[at+1]-time-now;
now=now+x/2.0+k;
time+=x/2.0;
at++;
self(self);
}
}else{
if(now<l) time+=(l-now);
}
};
fly(fly);
cout<<(int)round(time)<<"\n";
}
signed main() {
vcoistnt
int _=1;
cin>>_;
while(_--) solve();
return 0;
}