Codeforces Round 986 (Div. 2)
Codeforces Round 986 (Div. 2) 总结
A
按题意模拟即可,因为
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int N=1;
int n,a,b;
string s;
void solve()
{
cin>>n>>a>>b;
cin>>s;
int x=0,y=0;
for(int j=0;j<100;j++)
for(int i=0;i<n;i++)
{
if(s[i]=='N') y++;
else if(s[i]=='E') x++;
else if(s[i]=='S') y--;
else x--;
if(x==a&&y==b)
{
cout<<"Yes\n";
return;
}
}
cout<<"No\n";
}
int main ()
{
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int T;
cin>>T;
while(T--) solve();
return 0;
}
B
有点烦人的题,要分类讨论清楚。将一次操作中
- 若
,就是全是 ,讨论一下 的值。- 当
时,可以将 个 移动到 ,代价为 。 - 当
时,将 个 移动到 ,再将一个 移动到 。代价为 。 - 当
时,无论怎么操作,能移动到最大的数为 ,所以不合法。 - 当
时,就要将 个 移动到 ,代价为 。
- 当
- 若
,那么就是要将大于 的值都移动到 ,代价就是大于 的数的个数。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int N=1;
ll n,b,c;
void solve()
{
cin>>n>>b>>c;
if(!b)
{
if(c<n-2) cout<<-1<<'\n';
else
{
if(c<=n-1) cout<<n-1<<'\n';
else cout<<n<<'\n';
}
return ;
}
if(c>=n)
{
cout<<n<<'\n';
return ;
}
ll k=max(0ll,n-1-c)/b+1;
cout<<n-k<<'\n';
}
int main ()
{
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int T;
cin>>T;
while(T--) solve();
return 0;
}
C
首先切蛋糕时,一但大于
设
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,m;
ll v;
ll a[N],b[N],c[N],pre[N];
void solve()
{
cin>>n>>m>>v;
for(int i=1;i<=n;i++) cin>>a[i],pre[i]=pre[i-1]+a[i];
map<int,int> H;
ll x=0;
H[0]=0;
for(int i=1;i<=n;i++)
{
b[i]=b[i-1];
if(x<v) x+=a[i];
if(x>=v) x=0,b[i]++;
if(H.count(b[i])==0) H[b[i]]=i;
}
if(b[n]<m)
{
cout<<-1<<'\n';
return ;
}
c[n+1]=0,x=0;
ll ans=pre[n]-pre[H[m]];
for(int i=n;i>=1;i--)
{
c[i]=c[i+1];
if(x<v) x+=a[i];
if(x>=v) x=0,c[i]++;
int j=H[m-c[i]];
ans=max(ans,pre[i-1]-pre[j]);
}
cout<<ans<<'\n';
}
int main ()
{
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int T;
cin>>T;
while(T--) solve();
return 0;
}
分类:
codeforces总结
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效