Codeforces Round #568 (Div. 2) AB C1 C2 题解
A. Ropewalkers
题意:给三个数,每次可以对一个数+1或-1,问最少多少次可以使得三个数两两之间距离>=d。
思路:水题,存进来的排个序,abc依次表示从小到大的。只要考虑b往两边距离满足题意即可。
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 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 arr[5];
int main()
{
ll a, b , c ,d;
cin>>arr[1]>>arr[2]>>arr[3]>>d;
sort(arr+1,arr+1+3);
a = arr[1] , b = arr[2], c = arr[3];
ll d1 = 0;
if(b - a < d) d1 += d - (b - a);
if(c - b < d) d1 += d - (c - b);
cout<<d1<<endl;
return 0;
}
B. Email from Polycarp
题意:s串为原串,判断t串是否是在s的基础上在使某若干位置的字符重复出现得到的。
思路:双指针简单模拟一下。p指向原串,q指向目标串。如果s[p] == t[q],就继续往下匹配。若不一样,只有两种可能:1.t串在重复上一个字符。 2. 完全失配,直接退出。 如果p走完了s串且t剩下来的全是重复的,就输出"YES"。否则都为"NO" 。
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 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 = 1e6+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 Map[500];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
mem(Map,0);
string s; cin>>s;
string t; cin>>t;
for(int i=0; i<s.size();i++) Map[s[i]] ++;
int p = 0, q = 0;
while(p<s.size()&&q<t.size())
{
if(Map[t[q]]==0) break;
if(t[q] == s[p]) p++, q++;
else
{
if(q>0&&t[q] == t[q-1])
{
while(q<t.size()&&t[q]!=s[p]&&t[q]==t[q-1]) q++;
}
else break;
}
}
if(p<s.size())
{
cout<<"NO"<<'\n';
}
else
{
int flag = 1;
if(q<t.size())
for(int i=q; i<t.size();i++) if(t[i]!=t[i-1]) flag = 0;
if(!flag)
cout<<"NO"<<'\n';
else
cout<<"YES"<<'\n';
}
}
return 0;
}
C1. Exam in BerSU (easy version)
题意:给出n个数,每个数会消耗t[i]的时间,问在m时限的情况下i前面要最少去掉多少人才能保证t[i]放得下
思路:贪心一下,要走的人最少的话肯定是让前面的用时大的人走最好。所以读入一个数就将前i-1个数排序一下。从大往小选即可。
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 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 t[maxn];
int main()
{
ll n = read(), m = read();
ll cur = 0;
rep(i,1,n)
{
ll x = read();
sort(t+1,t+i,greater<ll>());
ll p = 1; ll tmp = m - cur;
while(tmp < x) tmp += t[p], p++;
cout<<p-1<<' ';
t[i] = x;
cur += x;
}
cout<<'\n';
return 0;
}
C2. Exam in BerSU (hard version)
题意:如上题。
思路:这题数据量加大很多,不能想C1那样莽了。仔细看数据发现t[i]<=100,这是个破题口。也就是说我们完全可以把上一题的思路顺延下来,排序的时候只需要在1~100出现过的数字进行排序就行了。所以我们用一个Map记录一下当前数有没有出现过,没出现过就加入all数组,Map同时计数这个数出现了多少次。然后拿到一个数就对前面的all数组排序(长度不会超过100),从大到小挑就行了。而且all[j]有多少个我们也是知道的,可以在O(1)时间内知道all[j]要挑多少。详见代码。
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 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 = 2e5+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 t[maxn];
vector<ll> all;
map<ll,ll> Map;
int main()
{
ll n = read(), m = read();
ll cur = 0;
rep(i,1,n)
{
ll x = read();
sort(all.begin(), all.end(), greater<ll>());
ll tmp = m - cur;
ll need = 0;
for(int j=0; j< all.size(); j++)
{
if(tmp >= x) break;
ll num = min(Map[all[j]] , ( x - tmp+all[j]-1)/all[j] );
need += num;
tmp += num * all[j];
}
cout<<need<<' ';
if(!Map[x]) all.pb(x);
Map[x]++;
cur += x;
}
cout<<'\n';
return 0;
}
Codeforces Round #568 (Div. 2) AB C1 C2 题解的更多相关文章
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- Codeforces Round #676 (Div. 2) A - D个人题解(E题待补)
1421A. XORwice 题目链接:Click Here // Author : RioTian // Time : 20/10/18 #include <bits/stdc++.h> ...
- Codeforces Round #568 (Div. 2) C2. Exam in BerSU (hard version)
链接: https://codeforces.com/contest/1185/problem/C2 题意: The only difference between easy and hard ver ...
- codeforces Round #568(Div.2)A B C
有点菜,只写出了三道.活不多说,上题开干. A. Ropewalkers Polycarp decided to relax on his weekend and visited to the per ...
- Codeforces Round #568 (Div. 2)网卡&垫底记
这场和div3差不多嘛(后来发现就是div3),就是网太卡10min交一发就不错了,简直自闭. A 签到. B 记录每一段的字母数,满足条件即:段数相同+字母相同+字母数下>=上. #inclu ...
- Codeforces Round #260 (Div. 2)AB
http://codeforces.com/contest/456/problem/A A. Laptops time limit per test 1 second memory limit per ...
- Codeforces Round #259 (Div. 2)AB
链接:http://codeforces.com/contest/454/problem/A A. Little Pony and Crystal Mine time limit per test 1 ...
- Codeforces Round #555 (Div. 3) AB
A: http://codeforces.com/contest/1157/problem/A 题意:每次加到10的整数倍之后,去掉后面的0,问最多有多少种可能. #include <io ...
随机推荐
- C#之集合常用扩展方法与Linq
一.集合的常用扩展方法(lambda的方式) 1.Where() 根据条件选择数据 2.Select() 根据数据条件转换成新的数据类型,类似于DTO转换类 3.Max() 根据条件选择最大值 4.M ...
- FastAPI数据库集成与事务管理
title: FastAPI数据库集成与事务管理 date: 2025/04/18 00:15:34 updated: 2025/04/18 00:15:34 author: cmdragon exc ...
- 前端自动打包工具webpack的安装和使用
一.准备 要使用webpack工具,最好了解一些基础的文件目录操作的命令行, win all里的一些常用的命令行 http://blog.csdn.net/qq_36110571/article/de ...
- 里程碑:MCP星球作为国内首个中文MCP社区和MCP工具平台,突破7000个MCP服务!
随着人工智能技术的快速发展,越来越多的开发者开始使用模型上下文协议(Model Context Protocol,简称MCP)来优化大模型与外部工具的交互.作为首个最大的中文MCP工具市场,MCP星球 ...
- Result、ConfigAwait、ValueTask
Result.ConfigAwait.ValueTask 参照: C# Async/Await: ConfigAwait, ValueTask是个啥?对提高性能有用么?_哔哩哔哩_bilibili 理 ...
- 揭秘AI自动化框架Browser-use(二),如何构造大模型提示词
在上一篇技术分析中,我们探讨了Browser-use框架如何实现页面元素标注.本文将聚焦于其提示词构造流程,揭示AI如何理解浏览器界面的核心机制. 上一篇-揭秘AI自动化框架Browser-use(一 ...
- Flex布局-margin 妙用技巧
在 flex 布局 中, 通过对子项设置 margin-auto; 的方式去吃掉剩余空间, 这种小技巧在很多时候能极大简化我们的布局哦. 单元素水平垂直居中 如果父容器是 flex, 要实现元素水平垂 ...
- 基于FPGA的超声波雷达感应预警系统 全过程记录
FPGA系统开发 综合实验记录 实验时间节点与想法记录 2023.4.24 新建本文档.目前决定有以下两个方案,要根据学校发的器件和自己的水平和后面时间决定. 课设想法 具体情况 基于FPGA的高速运 ...
- mp4文件下载,而不是在线播放
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- web ctf日记
X-Forworded-For:从本地访问 Refer:从**网址访问 一句话木马:`<?php @eval($_POST['a']);?>` eval将a作为PHP程序post进入(用蚁 ...