Educational Round 95 (Div. 2) A - B题题解(A题数据连错3次,搞人心态中)
1418A. Buying Torches
这次A题,真心fo了(导致wa了我两次)
样例出错两次,数据出错一次。
讲一下我的思路吧。
- 首先先明确至少需要多少个棍。\(k\) 个火炬,至少需要$k ∗ y + k $ 个棍棍。
- 其次要想,怎么从\(1\)个棍,利用第一条贸易,变成 \(k ∗ y + k\)个棍。我们可以先通过观察,假设 \(x = 12\)。
12 − > 23\\
23 − > 34
\]
可以发现每次加\(11\),也就是\(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次,搞人心态中)的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #371 (Div. 2) B. Filya and Homework 水题
B. Filya and Homework 题目连接: http://codeforces.com/contest/714/problem/B Description Today, hedgehog ...
- codeforces水题100道 第二十六题 Codeforces Beta Round #95 (Div. 2) A. cAPS lOCK (strings)
题目链接:http://www.codeforces.com/problemset/problem/131/A题意:字符串大小写转换.C++代码: #include <cstdio> #i ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题
C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...
- 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 ...
- 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 ...
- Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题
A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...
- 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 ...
- 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 ...
随机推荐
- Django笔记四十三之使用uWSGI部署Django系统
本文首发于公众号:Hunter后端 原文链接:Django笔记四十三之使用uWSGI部署Django系统 目前部署 Django 的方式一般来说是使用 Nginx + uWSGI + Django 来 ...
- nginx的keepalive和keepalive_requests(性能测试TPS波动)
当使用nginx作为反向代理时,为了支持长连接,需要做到两点: 从client到nginx的连接是长连接 从nginx到server的连接是长连接 保持和client的长连接: http { keep ...
- 必知必会Java
你好,我是阿光. 最近想着把工作中使用过的java命令都梳理一下,方便日后查阅.虽然这类文章很多,但自己梳理总结后,还是会有一些新的收获.这也是这篇笔记的由来. 今天先聊聊 jps 命令. 命令概述 ...
- [ABC267F] Exactly K Steps
Problem Statement You are given a tree with $N$ vertices. The vertices are numbered $1, \dots, N$, a ...
- springBoot——整合junit
spring整合junit复习 springBoot整合junit package com.example.springboot_04; import com.example.springboot_0 ...
- 单元测试平台搭建:sonarQube+sonarScanner+Jenkins+jacoco
单元测试平台搭建及结果分析 一.方案 需求目标:提高单元测试覆盖率和规范代码编写规范 选用工具:Sonarqube.sonarqube Scanner.Jenkins.jacoco 方案: 工程中引入 ...
- NLP项目实战02:英文文本识别
简介: 欢迎来到本篇文章!今天我们将讨论一个新的自然语言处理任务--英文短文识别.具体而言,即通过分析输入的英文文本来判断其是比较消极的还是比较积极的. 展示: 1.项目界面 如下所示是项目启动后用户 ...
- lottie 动画在 vue 中的使用
前言 最近我所负责的项目中,我采用了动画效果,并开始使用 gif 来实现.然而,在实践过程中,我发现 gif 格式的动画在 git 中出现了明显的锯齿感,这让我非常困扰.为了追求更完美的表现效果,我最 ...
- 『UniApp』uni-app-打包成App
前言 大家好,我是 BNTang, 在上一节文章中,我给大家详细的介绍了如何将我开发好的项目打包为微信小程序并且发布到微信小程序商店 趁热打铁,在来一篇文章,给大家详细的介绍如何将项目打包成APP. ...
- Golang标准库 container/list(双向链表) 的图文解说
Golang标准库 container/list(双向链表) 的图文解说 提到单向链表,大家应该是比较熟悉的了.今天介绍的是 golang 官方库提供的 双向链表. 1.基础介绍 单向链表中的每个节点 ...