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 ...
随机推荐
- 快速理解 MCP 与 A2A 协议的关系,它们如何协作构建复杂AI系统
近期关于MCP协议的讨论非常热门,主要因为通过MCP协议通过标准化接口为 AI 应用与外部数据源建立统一交互通道,这使得大模型可以与外部数据源或工具进行交互,从而实现各种专业场景下的智能应用.关于如何 ...
- MySQL 中使用索引一定有效吗?如何排查索引效果?
MySQL 中使用索引一定有效吗?如何排查索引效果? 虽然索引是提升 MySQL 查询性能的常见手段,但并不是所有情况下索引都会有效.索引的使用取决于查询条件.数据分布.索引设计等多个因素.如果索引未 ...
- 什么情况下会触发 Java 的 Full GC?
什么情况下会触发 Java 的 Full GC? Full GC(完全垃圾回收)是 Java 中的一个重要垃圾回收阶段,它会回收 整个堆内存,包括 新生代 和 老年代.触发 Full GC 的条件通常 ...
- 编写一个最原始的Servlet
目录 1 简介 2 编写程序 1 简介 Servlet(Server Applet)是 Java Servlet 的简称,是使用 Java 语言编写的运行在服务器端的程序.具有独立于平台和协议的特性, ...
- 超越代码生成:AI 如何重塑软件开发全生命周期 (SDLC)? (需求、测试到部署)
引言:AI 不止写代码,软件开发的"全链路"变革已至 各位技术圈的朋友们,提到 AI 在软件开发中的应用,恐怕大多数人首先想到的还是 GitHub Copilot.DeepSeek ...
- 如何开启AI副业,月入10w? 想听的速来!!
提供AI咨询+AI项目陪跑服务,有需要回复1 最近几天与粉丝多有交流,他们或者是经理.或者是总监,甚至有粉丝手里已经掌握了公司一些预算使用权. 从他们身上反映出了同一个问题:他们对于AI是偏焦虑的,想 ...
- Notepad++之"常用技术"
一.^ 前面 数据准备 二.$ 后面 准备 结果
- 人工神经网络(ANN)模型
一.概述 人工神经网络(Artificial Neural Network,ANN),是一种模拟生物神经网络结构和功能的计算模型,它通过大量的神经元相互连接,实现对复杂数据的处理和模式识别.从本质 ...
- C#数据结构之Tree
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 面试题:java Runnable与Callable 的区别
相同点 都是接口:(废话,当然是接口了) 都可用来编写多线程程序: 都需要调用Thread.start()启动线程. Callable是类似于Runnable的接口,实现Callable接口的类和实现 ...