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 题解的更多相关文章

  1. Educational Codeforces Round 64 部分题解

    Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...

  2. Educational Codeforces Round 64部分题解

    Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...

  3. Educational Codeforces Round 63部分题解

    Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...

  4. Educational Codeforces Round 95(A-C题解)

    A. Buying Torches 题目:http://codeforces.com/contest/1418/problem/A 题解:计算一个公式:1+n*(x-1)=(y+1)*k,求满足该条件 ...

  5. Educational Codeforces Round 95 (Rated for Div. 2)

    CF的Educational Round (Div.2),质量还是蛮高的. A: 水题 #include<cstdio> #include<algorithm> typedef ...

  6. Educational Codeforces Round 95 (Rated for Div. 2) C. Mortal Kombat Tower (DP)

    题意:你和基友两人从左往右轮流打怪兽,强怪用\(1\)表示,垃圾用\(0\)表示,但基友比较弱,打不过强怪,碰到强怪需要用一次魔法,而你很强,无论什么怪都能乱杀,基友先打,每人每次至少杀一个怪兽,最多 ...

  7. Educational Codeforces Round 95 (Rated for Div. 2) B. Negative Prefixes (贪心,构造)

    题意:给你一串长度为\(n\)的序列,有的位置被锁上了,你可以对没锁的位置上的元素任意排序,使得最后一个\(\le0\)的前缀和的位置最小,求重新排序后的序列. 题解:贪心,将所有能动的位置从大到小排 ...

  8. Educational Codeforces Round 95 (Rated for Div. 2) A. Buying Torches (数学)

    题意:刚开始你有一个木棍,造一个火炬需要一个木根和一个煤块,现在你可以用一个木棍换取\(x\)个木棍,或者\(y\)根木棍换一个煤块,消耗一次操作,问最少需要操作多少次才能造出\(k\)把火炬. 题解 ...

  9. Educational Codeforces Round 16---部分题解

    710A. King Moves 给你图中一点求出它周围有几个可达的点: 除边界之外都是8个,边界处理一下即可: #include<iostream> #include<cstdio ...

  10. Educational Codeforces Round 38 部分题解

    D. Buy a Ticket 分析 建一个源点,连向所有结点,边的花费为那个结点的花费,图中原有的边花费翻倍,最后跑一遍最短路即可. code #include<bits/stdc++.h&g ...

随机推荐

  1. 倍增 & Tarjan 求解LCA

    什么是LCA? 假设我们有一棵树: 1 / \ 2 3 / \ / 4 5 6 对于 \(2\) 和 \(6\) 的LCA,就是最近公共祖先,即为距离 \(2\) 和 \(6\) 最近的两个节点公有的 ...

  2. 【经验】Ubuntu 20.04 ROS2 Foxy安装

    参考博客 ROS2安装 有的地方原博主打错了,还没改过来,我按我自己的改好了. 有的地方比如github和raw.githubusercontent.com访问不了,我替换成能用的镜像源了,只求一键复 ...

  3. 如何开启AI副业,月入10w? 想听的速来!!

    提供AI咨询+AI项目陪跑服务,有需要回复1 最近几天与粉丝多有交流,他们或者是经理.或者是总监,甚至有粉丝手里已经掌握了公司一些预算使用权. 从他们身上反映出了同一个问题:他们对于AI是偏焦虑的,想 ...

  4. centos7部署keepalived

    yum install keepalived -y 修改/etc/keepalived.conf配置文件,达到高可用状态 vim /etc/keepalived/keepalived.conf ! C ...

  5. 第六章: SEO与交互指标

    第6章: SEO与交互指标 在当今的SEO环境中,Google越来越重视用户交互指标,如页面停留时长.交互性能等.本章将深入探讨如何优化网页速度和用户交互体验,以提升SEO效果和用户满意度. 1. G ...

  6. C#之方法

    在C#中,方法是类的函数成员,方法由两个主要部分: (1)方法头:指定了方法的特征,包括是否返回数据,如果返回,返回什么类型;方法的名称;哪种类型的数据可以传递给方法或从方法返回,以及如何处理这些数据 ...

  7. .NET外挂系列:8. harmony 的IL编织 Transpiler

    一:背景 1. 讲故事 前面文章所介绍的一些注入技术都是以方法为原子单位,但在一些罕见的场合中,这种方法粒度又太大了,能不能以语句为单位,那这个就是我们这篇介绍的 Transpiler,它可以修改方法 ...

  8. Mac sublime text4 修改选中行背景色

    在下面目录找到Mac sublime text所使用的配置文件: /Users/wxxf/Library/Application Support/Sublime Text/Packages/User ...

  9. Django Web应用开发实战附录A

    Django面试题 1.Python解释器有哪些类型,有什么特点? CPython:由C语言开发,而且使用范围最广泛IPython:基于CPython的一个交互式计时器PyPy:提高执行效率,采用JI ...

  10. Krita的语言选项里没有中文

    sudo apt install krita-l10n 即可,