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. Shell必备三剑客

    Top 目录 Sed--三剑客之一 基本格式 选项及含义 命令flags标记及功能 支持正则表达式, 扩展正则表达式 高级命令 命令格式 注意: 命令示例 字符串替换----'s' 行内容替换--'c ...

  2. H5自适应

    一.设置html的font-size,使用rem作为单位 假设设计稿宽度750px,屏幕宽高750px, 1.1rem=屏幕宽度/设计稿宽度*100px,适合用px表示宽度 1rem=100px re ...

  3. 媒体img组件以及swiper轮播

    .swiper{        height: 400rpx;        margin-top: 100rpx;        .item{            padding: 20rpx;  ...

  4. 如何使用 Helm 在 K8s 上集成 Prometheus 和 Grafana|Part 1

    本系列将分成三个部分,您将学习如何使用 Helm 在 Kubernetes 上集成 Prometheus 和 Grafana,以及如何在 Grafana 上创建一个简单的控制面板.Prometheus ...

  5. 【笔记整理】[案例]爱词霸翻译post请求

    import json if __name__ == '__main__': import requests resp = requests.post( url="http://ifanyi ...

  6. 华企盾DSC:wps个人模式无策略组新建的文件仍然加密

    解决方法:右键wps安装目录手动解密即可(原因:wps模板被加密导致)

  7. C#与数据库访问技术之ExecuteNonQuery方法

    ExecuteNonQuery方法主要用来更新数据. 通常使用它来执行Update.Insert和Delete语句. 该方法返回值意义如下: 对于Update.Insert和Delete语句,返回值为 ...

  8. 为什么Java中“1000==1000”为false,而”100==100“为true?

    在日常编程中,我们经常遇到一些看似简单却隐藏着复杂逻辑的问题. 比如,你是否想过为什么在 Java 中表达式1000==1000会返回 false,而 100==100 却返回 true 呢? Int ...

  9. Spring Boot入坑-2-第一个Spring Boot项目

    Spring Boot简介 自从2014年4月Pivotal团队推出以来,作为一个基于Spring的开源轻量级框架,备受企业级应用喜爱 简化Spring应用的搭建与开发过程 是对Spring缺点进行的 ...

  10. Python 初学者必看:Python 异常处理集合

    摘要:作为 Python 初学者,在刚学习 Python 编程时,经常会看到一些报错信息,本文专门介绍 python 异常处理. 异常 广义上的错误分为错误和异常 错误指的是可以人为避免 异常是指在语 ...