2023 年上海市大学生程序设计竞赛 - 五月赛A,B,C
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的更多相关文章
- 山东省第四届ACM大学生程序设计竞赛解题报告(部分)
2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...
- [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number
Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...
- 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 ...
- 2016年中国大学生程序设计竞赛(合肥)-重现赛1001 HDU 5961
传递 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- 2016年中国大学生程序设计竞赛(合肥)-重现赛1008 HDU 5968
异或密码 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- 2016年中国大学生程序设计竞赛(合肥)-重现赛1009 HDU 5969
最大的位或 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server
点击打开链接 2226: Contest Print Server Time Limit: 1 Sec Memory Limit: 128 MB Submit: 53 Solved: 18 [Su ...
- 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 ...
随机推荐
- c++引用(REFERENCES)
一个例子 void add(int value) { value++; } int main() { int a = 5; LOG(a); add(a); LOG( a); } 在这种情况下,变量a在 ...
- HDOJ 6703 Array
HDOJ 6703 Array 题目 题目链接 array *Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K ...
- arm-gcc 命名规则
背景 在 Ubuntu中交叉编译裸机程序的时候,注意到了这个问题:因此对此作为一个总结. 命名规则 交叉编译工具链的命名规则为:arch [-vendor] [-os] [-(gnu)eabi] ar ...
- 抓取豆瓣电影TOP250标题-年份-评分-评分人数
import csv import re import requests headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; ...
- 嵌入式基础测试手册——基于NXP iMX6ULL开发板(4)
前 言 本文档适用开发环境: Windows开发环境:Windows 7 64bit.Windows 10 64bit 虚拟机:VMware15.1.0 Linux开发环境:Ubuntu18.04.4 ...
- 韦东山freeRTOS系列教程之【第七章】互斥量(mutex)
目录 系列教程总目录 概述 7.1 互斥量的使用场合 7.2 互斥量函数 7.2.1 创建 7.2.2 其他函数 7.3 示例15: 互斥量基本使用 7.4 示例16: 谁上锁就由谁解锁? 7.5 示 ...
- OpenWrt中的LuCi和Lua一些总结
Lua.LuCi Lua是一种小巧的脚本语言,和Python一样,Lua脚本的运行需要Lua解释器: UCI(Unified Configuration Interface)是OpenWrt实现所有系 ...
- Java-JDBC的对象DriverManager,Connection,ResultSet,PreparedStatement,工具类:JDBCUTILS,JDBC控制事务
1. 概念 Java DataBase Connectivity Java 数据库连接 Java语言操作数据库 JDBC本质:其实是官方(sun)公司的一套操作所有关系型数据库的规则,即接口.各个数据 ...
- CCF 命令行选项
题目原文 问题描述(题目链接登陆账号有问题,要从这个链接登陆,然后点击"模拟考试",进去找本题目) 试题编号: 201403-3 试题名称: 命令行选项 时间限制: 1.0s ...
- .NET 轻量级 命令行工具 CSharpRepl
前言 当我们需要快速测试代码片段时,常见的做法是启动Visual Studio或使用在线代码编辑器.然而,Visual Studio的启动可能较为缓慢且占用较多系统资源,而在线编辑器则可能遇到语法支持 ...