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. 你知道C++如何在一个函数内返回不同类型吗?

    C++ 中要在一个函数内返回不同类型的值,你可以使用 C++17 引入的 std::variant 或 std::any,或者使用模板和多态.下面将分别介绍这些方法. 方法一:使用 std::vari ...

  2. springboot如何用jar包启动,同时为不同机房设置不同的配置文件

    1.首先先把配置文件从jar中抽离 示例代码: <plugin> <groupId>org.apache.maven.plugins</groupId> <a ...

  3. 安全测试工具Burpsuit和OWASP ZAP使用入门指南

    Burpsuit使用入门指南 安装: 网上有很多相关相关保姆级别教程,所以这里不加赘述了 尽量使用java8版本,破解版兼容8做的比较好 如果发现注册机无法打开或者能打开注册机[run]无法点击唤起软 ...

  4. Java八股面试题整理(1)

    1.为什么Java代码可以实现一次编写,到处运行? 参考答案 JVM(Java虚拟机)是Java跨平台的关键. 在程序运行前,Java源代码(.java)需要经过编译器编译成字节码(.class).在 ...

  5. jdk21的外部函数和内存API(MemorySegment)(官方翻译)

    1.jdk21:   引入一个 API,通过该 API,Java 程序可以与 Java 运行时之外的代码和数据进行互操作.通过有效地调用外部函数(即JVM外部的代码)和安全地访问外部内存(即不由JVM ...

  6. Linux笔记03: Linux常用命令_3.5权限管理命令

    3.5 权限管理命令 3.5.1 权限介绍 1.为什么需要权限 绝大多数用户使用的是个人计算机,而使用个人计算机的用户一般都是被信任的用户(如家人.朋友等).在这种情况下,大家都可以使用管理员身份直接 ...

  7. 如何生成core文件进行项目调试

    由于项目前期的调试错误比较多,或者有某些隐藏危险:例如内存泄漏:偶尔才出现一次,如果没有捕捉错误的手段可能好不容易出现的机会就溜走了,所以生成core文件是必要的,发生段错误会生成相应的core文件, ...

  8. 【Python】【OpenCV】轮廓检测

    Code: 1 import cv2 2 import numpy as np 3 4 img = np.zeros((200, 200), dtype=np.uint8) 5 img[50:150, ...

  9. MinIO客户端之ping

    MinIO提供了一个命令行程序mc用于协助用户完成日常的维护.管理类工作. 官方资料 mc ping 检查指定的MinIO节点的服务是否可用. 不带参数,命令如下: ./mc ping local1 ...

  10. Python——第五章:随机模块random

    1.浮点数random.random() 的返回值是在 [0, 1)(左闭右开区间)内的随机浮点数.这意味着它可以取到 0,但不包括 1.所以,random.random() 可以返回 0,但不能返回 ...