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. 【web实验报告】实验二

    一.实验目的 通过一个小型网站的开发,掌握JSP基础知识,加深对session,request,response,cookie等对象的理解,掌握其使用方法,进一步深入掌握HTML.CSS和JavaSc ...

  2. SpringBoot项目中常见组件的配置属性

    本文本的属性摘录自官方Properties配置清单,并附加了国内开发常用的框架配置属性.以国内WEB开发中,所涉及的常见组件为顺序组织配置清单 1. 配置属性清单 1.1 日志配置 序号 属性名 类型 ...

  3. javaScript正则截取自定义标签-javascript-zheng-ze-jie-qu-zi-ding-yi-biao-qian

    title: javaScript正则截取自定义标签 date: 2021-12-29 17:31:48.448 updated: 2021-12-29 17:31:48.448 url: https ...

  4. 【ASP.NET Core】使用SignalR推送服务器日志

    一个多月前接手了一个产线机器人项目,上位机以读写寄存器的方式控制机器人,服务器就是用 ASP.NET Core 写的 Web API.由于前一位开发者写的代码质量问题,导致上位机需要16秒才能启动.经 ...

  5. Volcano 原理、源码分析(二)

    0. 总结前置 1. 概述 2. 寻找调度器中的 PodGroup 2.1 从 PodGroup 到 JobInfo 的封装 2.2 从 Pod 到 TaskInfo 的封装 3. 控制器中 PodG ...

  6. 热闹的人工智能VS酷寒的资本寒冬,2023年AI Agent项目盘点与融资分析

    2023年国内AI Agent下项目大盘点,科技大厂与创业公司齐头并进 热闹人工智能VS酷寒资本寒冬,2023年AI Agent项目盘点与融资分析 资本寒冬下的AIGC,为什么这些AI Agent项目 ...

  7. k8s集群Node节点管理:节点信息查看及节点label标签管理

    k8s集群Node节点管理:节点信息查看及节点label标签管理 Kubernetes集群Node管理 一.查看集群信息 [root@k8s-master1 ~]# kubectl cluster-i ...

  8. 如何使用.NET在2.2秒内处理10亿行数据(1brc挑战)

    译者注 在上周我就关注到了在github上有1brc这样一个挑战,当时看到了由Victor Baybekov提交了.NET下最快的实现,当时计划抽时间写一篇文章解析他的代码实现,今天突然看到作者自己写 ...

  9. 十分钟从入门到精通(下)——OBS权限配置

    上一篇我们介绍了OBS权限管理中统一身份认证和企业项目管理,本期我们继续介绍OBS权限管理中的高级桶策略和ACL应用.   您是否也遇到过类似的问题或者困扰? 1.隔壁的主账户给了子用户创建一个桶,但 ...

  10. 避坑指南:关于SPDK问题分析过程

    [前言] 这是一次充满曲折与反转的问题分析,资料很少,代码很多,经验很少,概念很多,当内核态,用户态,DIF,LBA,大页内存,SGL,RDMA,NVME和SSD一起迎面而来的时候,问题是单点的意外, ...