A. 选择

多造几组数据可以发现

\(dp[n] = dp[n / 2] + 1\).

假如一个序列为\(\{1,2,\cdots,n\}\),那我们从\(n/2\)后都减去\(n/2\),序列就变为了\(\{1,2,\cdots,n/2,1,2,\cdots,n/2\}\),那么我们只需要\(n/2\)时次数最少得方案即可.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <numeric>
#define inf 0x3f3f3f3f
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define endl '\n'
#define int long long using namespace std; const int N = 1e6 + 10, mod = 1e9 + 7;
typedef unsigned long long ll;
typedef pair<int,int> PII; void solve(){
cin >> n;
vector<int> dp(n + 1);
dp[1] = 1;
for(int i = 1;i <= n;i ++)
dp[i] = dp[i / 2] + 1;
cout << dp[n] << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
} /*
*/

B. 锐评

假设答案至少为 \(r\),且 \(a,b\) 已经完成操作,那么我们可以有这样的不等式:

\(\frac {a} {a + b} \geq r \Rightarrow (1 - r) a - rb \geq 0.\)

因此,给 \(a\) 加 1,\(b\) 减 1 的收益是线性的,因此一定在 \(a\) 最大和 \(b\) 最小时取到极值,对两者取 \(max\) 即可。

对\(b\)取最小时,记得把多出来的钱刷好评(另外如果你一直过不了第一个点的话,可以试试把\(scanf\)换成\(cin\),很奇怪\(\cdots\))

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long
using namespace std; int n,t,k,m; void solve() {
int x,a,b;
cin >> m >> x >> a >> b;
int ma = a + m, mi = max(b - m / x,0ll);
double ans = max((double) ma / (ma + b), (double)(a + m % x) / (m % x + a + mi));
printf("%.9lf\n",ans);
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}

C. 饮茶

先假设每天都出去玩。这样,如果到某天来不及了,我只能放弃之前某天出去玩,此时显然放弃浪费时间越多的越好。因此,从前到后维护当前还能放弃的时间差最大堆,需要的时候弹掉最大的直到满足条件,最后输出堆的大小。

这里我用的是优先队列,不过都是一个道理

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f using namespace std;
const int N = 2e3 + 10; typedef pair<int,int> PII;
map<int, int > mp;
int n,m,t,k,c;
int mod,ans;
void solve()
{
cin >> n;
priority_queue<int> T;
int a,b;
int ans = n;
int sumtime = 0;
for(int i = 0;i < n;i++){
cin >> t >> a >> b;
if(a > b)
T.push(a - b);
sumtime += b - t;
while(sumtime < 0){
if(T.empty()){
cout << -1 << endl;
return ;
}
sumtime += T.top();
T.pop();
ans --;
}
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
//cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}

2023 年上海市大学生程序设计竞赛 - 五月赛A,B,C的更多相关文章

  1. 山东省第四届ACM大学生程序设计竞赛解题报告(部分)

    2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...

  2. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  3. [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number

    Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...

  4. 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree

    Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...

  5. 2016年中国大学生程序设计竞赛(合肥)-重现赛1001 HDU 5961

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  6. 2016年中国大学生程序设计竞赛(合肥)-重现赛1008 HDU 5968

    异或密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  7. Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...

  8. 2016年中国大学生程序设计竞赛(合肥)-重现赛1009 HDU 5969

    最大的位或 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  9. 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server

    点击打开链接 2226: Contest Print Server Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 53  Solved: 18 [Su ...

  10. fzu 2105 Digits Count ( 线段树 ) from 第三届福建省大学生程序设计竞赛

    http://acm.fzu.edu.cn/problem.php?pid=2105 Problem Description Given N integers A={A[0],A[1],...,A[N ...

随机推荐

  1. spark读取hive表,org.apache.spark.sql.AnalysisException: Unsupported data source type for direct query on files: hive;

    异常出现:spark读取hive表时,spark.read.table(hive.test) hdp版本的spark默认的catalog是spark,配置项 metastore.catalog.def ...

  2. CentOS7系统搭建web环境 php&nginx&pgsql

    环境:VMware.CentOS-7-x86_64-DVD-2009.iso.nginx-1.26.1.php-7.2.0.postgresql-12 php最好安装对应php项目所需版本,否则会出现 ...

  3. Power BI进阶秘籍,干货满满!如何将度量值转化为切片器(动态切换分析指标),实操指南来了!

    Power BI进阶秘籍,干货满满!如何将度量值转化为切片器(动态切换分析指标),实操指南来了!   想要在Power BI中让度量值也能像维度一样灵活筛选?没问题,这里就为你揭秘如何将度量值转化为切 ...

  4. ST 表整体二分解法

    整体二分时遍历数组从 \(mid\) 开始的最大值再合并就可以了,时间 \(O(n \log n + q)\) 空间 \(O(n)\). #include<bits/stdc++.h> / ...

  5. Java开发常见问题分析和处理方案

    程序Bug的产生,通常分为三种类型 逻辑漏洞: 低级错误,程序执行后无法达到想要效果. 越界访问: 访问了非法区域,造成程序崩溃. 条件考虑不全面: 你以为你万无一失,但你永远都不知道输入参数究竟是什 ...

  6. 如何优雅地使用Mybatis逆向工程生成类

    文/朱季谦 1.环境:SpringBoot 2.在pom.xml文件里引入相关依赖: 1 <plugin> 2 <groupId>org.mybatis.generator&l ...

  7. 洛谷P1451

    背景:复习 简单的dfs,也可以说是有点像连通块 #include<iostream> #include<utility> using namespace std; typed ...

  8. [oeasy]python0070_ 字体样式_下划线_中划线_闪动效果_反相_取消效果

    字体样式 回忆上次内容 m 可以改变字体样式 0-10 之间设置的都是字体效果 0 复原 1 变亮 2 变暗 从3到10 又是什么效果 呢?? 真的可以blink闪烁吗? 3m 3m 实现斜体字的效果 ...

  9. [oeasy]python0010_hello_world_unix_c历史迷因

    ​ Hello World! 回忆上次内容 我们这次设置了断点 设置断点的目的是更快地调试 调试的目的是去除 ​​bug​​ 别害怕 ​​bug​​ 一步步地总能找到 ​​bug​​ 这就是程序员基本 ...

  10. QT 开发快速入门

    本人 qt 业余,但有的时候要用到 qt,而又没有系统的学习,用到哪里看哪里. 环境: vs2012+ qt-vsaddins+qt5.5 qt 的按钮点击事件出发的基本要素: 1. 按钮触发函数为 ...