1418A. Buying Torches

这次A题,真心fo了(导致wa了我两次)

样例出错两次,数据出错一次。

讲一下我的思路吧。

  • 首先先明确至少需要多少个棍。\(k\) 个火炬,至少需要$k ∗ y + k $ 个棍棍。
  • 其次要想,怎么从\(1\)个棍,利用第一条贸易,变成 \(k ∗ y + k\)个棍。我们可以先通过观察,假设 \(x = 12\)。
\[1−>12\\
12 − > 23\\
23 − > 34
\]

可以发现每次加\(11\),也就是\(x − 1\)

所以,设\(tmp\)是贸易一的次数。

\[1 + ( x − 1 ) ∗ t m p − > k ∗ y + k
\]

这里我为什么要用\(− >\)而不是$= $呢?

因为可能不能正好等于$k ∗ y + k $。

那就取

\[1+(x−1)∗tmp>k∗y+k
\]

时\(tmp\) 的值。

最后 \(tmp\) 再加上 \(2^k\) 次即可。

#python
for _ in range(int(input())):
x,y,k=map(int,input().split())
tmp=(k*y+k-1)//(x-1)
if tmp*(x-1)<k*y+k-1:
tmp+=1
tmp+=k
print(tmp)
//C++
#include<bits/stdc++.h>
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
const int N = 1e5 + 100;
ll _, n, m, a[N], i, j;
void solve() {
ll x, y, k;
cin >> x >> y >> k;
ll tmp = (k * y + k - 1) / (x - 1);
if (tmp * (x - 1) < k * y + k - 1)tmp++;
tmp += k;
cout << tmp << endl;
} int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> _; while (_--) solve();
}

再看看一下dalao的数学解法:

由于第二次交易是获取煤炭的唯一方法,因此我们显然需要进行 \(k\) 次第二次交易。 那么,我们需要进行多少次首次交易? 我们可以看到,为了最终得到足够的棒和煤,我们需要获得 \(ky + k\) 棒(将 \(ky\) 转换为煤,将 \(k\) 转换为棒)。 由于第一次交易实际上每次都给我们 \(x-1\) 个新的摇杆,因此我们需要进行 \(\frac{ky + k-1}{x-1}\)个第一次交易(对于不熟悉的人请参考下限和上限功能)。

有关实现细节,请注意,对于正整数\(a\) 和 \(b\),\(\frac{a}{b}=\frac{a+b-1}{b}\)。

//C++实现
#include <iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long x,y,k;
cin>>x>>y>>k;
cout<<((y+1)*k+x-3)/(x-1)+k<<endl;
}
return 0;
}

1418B. Negative Prefixes

模拟题,记录可以动的,从大到小排序。

#python
for _ in range(int(input())):
n=int(input())
lst=list(map(int,input().split()))
s=list(map(int,input().split()))
index=[]
t=[]
for i in range(n):
if s[i]==0:
index.append(i)
t.append(lst[i])
if len(t)==0:
print(*lst)
continue
t.sort(reverse=True)
for i in range(len(index)):
lst[index[i]]=t[i]
print(*lst)
//c++
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
int t=1;
cin>>t;
while(t--){
int n,i,j=0;
cin>>n;
int a[n],b[n];
vector<int>v;
for(i=0;i<n;i++)cin>>a[i];
for(i=0;i<n;i++)cin>>b[i];
for(i=0;i<n;i++){if(b[i]==0){v.push_back(a[i]);}}
sort(v.rbegin(),v.rend());
for(i=0;i<n;i++){if(b[i]==0){a[i]=v[j];j++;}}
for(i=0;i<n;i++)cout<<a[i]<<" ";
cout<<endl;
}
}

Educational Round 95 (Div. 2) A - B题题解(A题数据连错3次,搞人心态中)的更多相关文章

  1. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  2. Codeforces Round #298 (Div. 2) A、B、C题

    题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...

  3. Codeforces Round #371 (Div. 2) B. Filya and Homework 水题

    B. Filya and Homework 题目连接: http://codeforces.com/contest/714/problem/B Description Today, hedgehog ...

  4. codeforces水题100道 第二十六题 Codeforces Beta Round #95 (Div. 2) A. cAPS lOCK (strings)

    题目链接:http://www.codeforces.com/problemset/problem/131/A题意:字符串大小写转换.C++代码: #include <cstdio> #i ...

  5. Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题

    C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...

  6. Codeforces Round #384 (Div. 2) A. Vladik and flights 水题

    A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...

  7. Codeforces Round #379 (Div. 2) A. Anton and Danik 水题

    A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...

  8. Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题

    A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...

  9. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  10. Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题

    A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

随机推荐

  1. BIRCH算法全解析:从原理到实战

    本文全面解析了BIRCH(平衡迭代削减聚类层次)算法,一种用于大规模数据聚类的高效工具.文章从基础概念到技术细节,再到实战应用与最佳实践,提供了一系列具体的指导和例子.无论你是数据科学新手,还是有经验 ...

  2. Kubernetes 漫游:etcd

    概述 etcd 是一个基于 Raft 协议实现.开源的.分布式的键值存储系统.主要用于在分布式系统中提供强一致性和高可用性的数据存储. etcd 在 Kubernetes 中的作用如下: 集群状态数据 ...

  3. 6款AI工具网站,赶紧收藏,以备不时之需

    1.海鲸AI-支持AI对话.AI文档解析.AI绘画 海鲸AI-基于新一代人工智能技术,只需输入问题,即可得到智能回答 https://​www.weijiwangluo.com/talk/ 海鲸AI是 ...

  4. 洛谷P2579 [ZJOI2005]沼泽鳄鱼(矩阵快速幂,周期)

    例题:现在豆豆已经选好了两座石墩Start和End,他想从Start出发,经过K个单位时间后恰好站在石墩End上.假设石墩可以重复经过(包括Start和End),他想请你帮忙算算,这样的路线共有多少种 ...

  5. python的websockets库

    安装 pip install websockets 分为客户端和服务端两部分 服务端一般与异步的库一起用 因为客户端不可能只服务一个客户 所以要用异步处理多个客户 以asyncio示例 from we ...

  6. STM32一个定时器输出四路不同频率和占空比PWM波的方法

    一般来说,一个定时器输出4路频率相同.占空比不同的PWM波是比较容易的,使用PWM模式即可实现.如果说是输出4路频率不同.占空比不同的PWM就没有现成的模式,是不是无法实现了呢?答案肯定是" ...

  7. 图纸安全管理:华企盾DSC数据防泄密系统的综合解决方案

    企业设计人员创造出的图纸既是珍贵的知识产权,又承载着公司的创新力和竞争力.然而,随着信息技术的迅速发展,图纸泄密风险也在不断增加.为了保护这一重要的企业资产,华企盾DSC数据防泄密系统提供了一系列专业 ...

  8. Arrarylist集合的使用

    前提:最近JAVA实训课老师讲了一些Arrarylist集合的相关知识,刚好端午假期有空就把这课上学到的知识和自己碰到的一些问题总结下来. 一.Arrarylist集合的使用(以学生信息存储作为演示) ...

  9. 使用.NET Core接入飞书AI

    飞书AI接入教程 首先,准备俩个账号:ChatGPT账号.飞书账号. 飞书账号请自行注册,访问链接 www.feishu.cn/ 即可登录. 第一步,飞书进入开发者平台.点击创建应用. 填写应用名称和 ...

  10. 5分钟就能实现的API监控,有什么理由不做呢?基调听云

    API深度影响着你的应用 今天的数字应用世界其实是一个以API为中心的世界,我们只是没有意识到这些API的重要性.比如在电子商务交易.社交媒体等对交互高度依赖的领域,可以说API决定了应用的质量一点也 ...