Educational Codeforces Round 95 ABC 题解
A. Buying Torches
题意:合成一个物品需要一个a和一个b,一开始有一个a。现在有下面两种操作:
1.用1个a换x个a。
2.用y个a换1个b。
问你合成k个物品最少需要多少次操作。
思路:水题,先算出一共需要多少个a,然后用这个数除(x-1)上取整得到合成出这么多a需要的次数,再加上k次转化成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} };
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll x = read(), y = read(), k = read();
ll all = k*(y+1) - 1;
ll sum = (all + (x-2))/ (x-1);
cout<<sum+k<<'\n';
}
return 0;
}
B. Negative Prefixes
题意:给你个序列。除了有些固定位置不能动,其他位置任意排序。使得最后一次出现前缀和sum[j] < 0的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 = 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 a[maxn];
vector<ll> item;
ll ok[maxn];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
item.clear();
rep(i,1,n) a[i] = read();
rep(i,1,n) ok[i] = read();
rep(i,1,n) if(!ok[i]) item.pb(a[i]);
sort(item.begin(), item.end());
int cur = item.size() - 1;
rep(i,1,n) if(!ok[i]) a[i] = item[cur--];
rep(i,1,n) cout<<a[i]<<' '; cout<<'\n';
}
return 0;
}
C. Mortal Kombat Tower
题意:给一个01序列。你和你的队友可以取一个数或者两个数。但是队友取1的话要产生1点花费。问最少花费才能全部数取完。
思路:这个题其实够贪心就能过。
首先我们站在队友视角看,当回合是对方时:
1.若当前是0,不管后面有多少个连续0,总有方法使得队友拿最后一个0,然后最先遇到的1让“我”来拿。贪心。
2.若当前是1,那后面如果是0的话,尽量拿。不过这里会有一个wa点,比如 1 0 0 1 1,如果队友一开始拿了1 0,那结果就是2。但是如果他只拿1的话,就能保证后面的连续0最后一个还是队友来拿,最先遇到的1“我”来取。所以这里要给取1 0的时候给悔棋的次数计数。方便后面1少了0的时候拿回来一个。
然后我们站在自己的视角看,当回合是“我”的时候:
1.若当前是1,那看下一个是不是1,是的话把1尽量扫干净。下一个是0的话留给队友。
2.若当前是0,你会发现在两个0以上的时候不管后面有多少个连续0都能让队友取最后一个,然后“我”来拿1。如果只有1个0,就看看前面说的能不能悔棋,可以的话就多出一个0达到前面说的效果。没有的话只能我取走这个唯一的0了。
详见代码注释
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 a[maxn];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
rep(i,1,n) a[i] = read();
int flag = 0;
int zeros = 0; //用来悔棋用的
int turn = 1; // 回合
ll ans = 0;
rep(i,1,n)
{
if(flag&&a[i]==0) continue; //flag为真时后面的0都不用管了,肯定能把最后一个0安排给队友
if(flag) turn=0; //最后一个0给队友后,当前遇到1,是我的回合
turn++;
flag = 0;
if(turn&1) //我的回合
{
if(a[i]==1) //若是1
{
if(a[i+1]==1) i++; //能吃就吃
}
else // 若是0
{
if(a[i+1]==1) // 如果只有一个0,那就看看能不能悔棋,让队友少吃掉一个0,回退一位
{
if(zeros>=1) zeros--, flag=1; //可以的话又可以让队友踩最后一个0
else i++;
}
else flag=1; //两个以上0肯定可以让队友踩最后一个0
}
}
else //队友回合
{
if(a[i]==0) flag = 1; //当前是0,肯定能让队友踩最后一个0
else
{
if(i+1<=n&&a[i+1]==0) i++, zeros++; //下一个有0就吃,但是计一下悔棋的步数
ans++;
}
}
}
cout<<ans<<'\n';
}
return 0;
}
Educational Codeforces Round 95 ABC 题解的更多相关文章
- Educational Codeforces Round 64 部分题解
Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...
- Educational Codeforces Round 64部分题解
Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...
- Educational Codeforces Round 63部分题解
Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...
- Educational Codeforces Round 95(A-C题解)
A. Buying Torches 题目:http://codeforces.com/contest/1418/problem/A 题解:计算一个公式:1+n*(x-1)=(y+1)*k,求满足该条件 ...
- Educational Codeforces Round 95 (Rated for Div. 2)
CF的Educational Round (Div.2),质量还是蛮高的. A: 水题 #include<cstdio> #include<algorithm> typedef ...
- Educational Codeforces Round 95 (Rated for Div. 2) C. Mortal Kombat Tower (DP)
题意:你和基友两人从左往右轮流打怪兽,强怪用\(1\)表示,垃圾用\(0\)表示,但基友比较弱,打不过强怪,碰到强怪需要用一次魔法,而你很强,无论什么怪都能乱杀,基友先打,每人每次至少杀一个怪兽,最多 ...
- Educational Codeforces Round 95 (Rated for Div. 2) B. Negative Prefixes (贪心,构造)
题意:给你一串长度为\(n\)的序列,有的位置被锁上了,你可以对没锁的位置上的元素任意排序,使得最后一个\(\le0\)的前缀和的位置最小,求重新排序后的序列. 题解:贪心,将所有能动的位置从大到小排 ...
- Educational Codeforces Round 95 (Rated for Div. 2) A. Buying Torches (数学)
题意:刚开始你有一个木棍,造一个火炬需要一个木根和一个煤块,现在你可以用一个木棍换取\(x\)个木棍,或者\(y\)根木棍换一个煤块,消耗一次操作,问最少需要操作多少次才能造出\(k\)把火炬. 题解 ...
- Educational Codeforces Round 16---部分题解
710A. King Moves 给你图中一点求出它周围有几个可达的点: 除边界之外都是8个,边界处理一下即可: #include<iostream> #include<cstdio ...
- Educational Codeforces Round 38 部分题解
D. Buy a Ticket 分析 建一个源点,连向所有结点,边的花费为那个结点的花费,图中原有的边花费翻倍,最后跑一遍最短路即可. code #include<bits/stdc++.h&g ...
随机推荐
- CentOS linux安装jdk
1.查找系统是否安装jdk java -versionrpm -qa | grep jdk 2.卸载原jdk rpm -e --nodeps jdk..(这里为自己jdk路径) 3.下载指定版本rpm ...
- 海康摄像头SDK在Linux、windows下的兼容问题(二)已解决
上一篇提出的问题,在前几天解决了. 海康的技术人员给出了指导,在Linux库加载失败的时候,需要在代码中手动指定配置文件. 库文件加载说明] // 1. lib文件夹里面所有库文件libhcnetsd ...
- FastAPI与Tortoise-ORM开发的神奇之旅
title: FastAPI与Tortoise-ORM开发的神奇之旅 date: 2025/05/05 00:15:48 updated: 2025/05/05 00:15:48 author: cm ...
- 【经验】微信小程序开发 云后台比价(自带云开发、leancloud、bmob)(2022/10/31更新)
目录 前言 1. 免费配额 2. 超过额度时收费情况 3. 另外的价钱 总结 前言 作为前端开发者,没有购买云服务器的习惯,在只需要使用数据库的情况下,开发微信小程序完全可以用现在免费的云后台. 常用 ...
- 内网私仓全流程搭建记录(二)-npm私仓提交与拉取
1.npm私仓依赖下载及本地上传 方法一1)使用Pycharm创建py文档,写入如下py代码: import os import re import aiohttp import asyncio fr ...
- uniapp开发HarmonyOS NEXT应用之项目结构详细解读
昨天的文章介绍了使用uniapp跨平台鸿蒙应用时如何配置开发环境和运行调试项目,今天介绍一下uniapp项目目录的结构. 可能对于从事移动开发的友友来说,uniapp的项目结构看起来有一些陌生,它更接 ...
- LSTM 与 GRU
弄完这块, 感觉对于 RNN (递归神经网络) 基本就接近尾声了. 相对于 之前的卷积神经网络, 我感觉 RNN 还是相对有意思一些, 也可能是在前面手推 CNN 公式时弄翻车的原因, 以及实在对图像 ...
- skip
哇酷哇酷,和你的春天一样稍纵即逝的夏天 藏什么藏呢 自卑吗 你以为是缺点的 恰恰让我喜欢 但要短确实很短 说难是很难 而且烂 恰到好处吧 好男人也没的身手! 为了足以被好男人拯救 我在练习 结果是腿废 ...
- manim变换效果总结
在ManimCE中,除了上一篇介绍的丰富的动画效果外,变换效果也是制作精彩视觉内容的重要工具. 变换效果主要用于改变对象的形状.大小.颜色或位置,让对象在动画中呈现出动态的变化. 本文详细总结了 Ma ...
- Github Copilot 实战: 从零开始用AI写一个OCR工具 (3)
源码 https://github.com/densen2014/Blazor100/tree/master/AI/MiOcr 添加一个屏幕截图功能,显示截图起始点,结束点,截图区域,按键ESC取消截 ...