首页 > 其他分享 >2024.9.6 CF1307 模拟赛记录

2024.9.6 CF1307 模拟赛记录

时间:2024-09-06 19:16:29浏览次数:1  
标签:typedef int 2024.9 long solve CF1307 mx 模拟 define

A:各捆干草间互相独立,所以优先移动距 \(1\) 近的。

点击查看代码
#include<bits/stdc++.h>
#define int long long
#define psbk push_back
#define fst first
#define scd second
#define umap unordered_map
#define pqueue priority_queue
#define vc vector
#define endl '\n'
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
constexpr int inf = 0x3f3f3f3f;
int n, d, a[105];
void solve()
{
	cin >> n >> d;
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
		if(i == 1)
		{
			ans = a[1];
		}
		else
		{
			ans += min(a[i], d / (i - 1));
			d -= min(a[i], d / (i - 1)) * (i - 1);
		}
	}
	cout << ans << endl;
}
signed main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int tt;
	cin >> tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

B:首先,若存在 \(i\) 使得 \(a_i=x\),显然答案为 \(1\)。

否则,令 \(mx=\max_{i=1}^na_i\),当距离 \(>2\times mx\) 时不断向右跳,然后再跳 \(2\) 次,一定可以到达。

点击查看代码
#include<bits/stdc++.h>
#define int long long
#define psbk push_back
#define fst first
#define scd second
#define umap unordered_map
#define pqueue priority_queue
#define vc vector
#define endl '\n'
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
constexpr int inf = 0x3f3f3f3f;
int n, x, a[100005];
void solve()
{
	cin >> n >> x;
	int mx = -1e18;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
		mx = max(mx, a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i] == x)
		{
			cout << 1 << endl;
			return;
		}
	}
	cout << max((x - 1 - mx) / mx, 0ll) + 2 << endl;
}
signed main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int tt;
	cin >> tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

C:

标签:typedef,int,2024.9,long,solve,CF1307,mx,模拟,define
From: https://www.cnblogs.com/Byf23333/p/18400836

相关文章

  • C语言——使用回调函数模拟实现qsort
    同学们还记得之前我们已经学过一种排序方法叫“冒泡排序“嘛。代码直接附上咯voidbubble_sort(intarr[],intsz){ inti=0;//趟数 for(i=0;i<sz-1;i++) { intj=0; for(j=0;j<sz-i-1;j++) { if(arr[j]>arr[j+1]) { inttmp=......
  • 2024.9.6 Python,华为笔试题总结,字符串格式化,字符串操作,广度优先搜索解决公司组织绩效
    1.字符串格式化name="Alice"age=30formatted_string="Name:{},Age:{}".format(name,age)print(formatted_string)或者name="Alice"age=30formatted_string=f"Name:{name},Age:{age}"print(formatted_string)2......
  • 『模拟赛』CSP-S模拟1
    Rank1BADA.喜剧的迷人之处在于签。正好早上还在改一个要分解质因数的题,所以一眼就出思路了。首先将\(a\)的平方因子全部除去,剩下的就是\(b\)必须的因数,即若设将平方因子全部除去后的\(a\)为\(a'\),则\(b\)应表示为\(a'\timesx^2\),从\(L\)这个下界开始只用找......
  • 使用flask进行Mock Server模拟接口操作及问题解决
    1.flask介绍flask是一个轻量级的pythonweb微框架2.MockServer介绍MockServer是一个开源的模拟服务器,它可以定义和记录API交互,支持各种http方法(get、post、put、delete),可以自定义响应内容,例如返回静态文件可以使用flask来搭建一个mock模拟服务3.模拟接口先安装flaskpip......
  • 2024.9.6 leetcode 70 爬楼梯 (哈希表/动态规划)
    题面70.爬楼梯-力扣(LeetCode)题解:极其经典的一道动态规划,比如要跳到10楼有f(10)种方法,可以分为1、先跳到9楼再往上跳1楼2、先跳到8楼再往上跳2楼,所以f(10)=f(8)+f(9),昨天复习了哈希表,所以用哈希练习一下。classSolution{public:intclimbStairs(intn){uno......
  • 9.6 上午 becoder 模拟赛总结&题解
    T1语言水题不多说,很容易发现NP需要满足的只是最后一个单词为N,前面是A或N都可以随意放。所以用两个数组,\(v1_i\)记录以\(i\)结尾的前缀是否可以构成NP,\(v2_i\)记录以\(i\)为开头的后缀是否可以构成NP。最后for循环扫一遍是否有同时满足\(v1_{i-1}=true\)和......
  • KUnit:设备模拟&重定向
    设备模拟有些驱动文件是需要device的,所以KUnit提供了一些设备模拟的方法,并且还提供了总线来管理设备的生命周期。下面先以clockdevice模拟举例(drivers/clk/clk_test.c)首先用一个struct来模拟这个clk设备。其中clk_hw是clk的描述,rate相当于模拟设备的波特率寄存器structclk......
  • 2024.9.4 leetcode 169 多数元素 (哈希表)
    题面 169.多数元素-力扣(LeetCode)题解:复习(自学)了一下哈希表,unordered_map<int,int>umap定义一个表umap.find(nums[i])!=umap.end()判断是否存在umap.insert({nums[i],1})插入umap.erase(nums[i])清除C++容器类<unordered_map>|菜鸟教程(runoob.com)class......
  • 2024.9.5 leetcode 3174 清除数字(字符串)
    题面3174.清除数字-力扣(LeetCode)题解:今天的每日一题比较简单,思路是遍历字符串,遇到第一个数字x的时候,把数字x和前面的字母y删除,也就是删除yx。1、为什么前面一定是字母,因为遇到的是第一个数字,前面不可能再有数字。2、如何实现删除yx,重新定义一个字符串,每一次遍历将y前面的字......
  • 【自由能系列(中级),代码模拟】预测编码的核心:三个关键方程式的详解
    预测编码的核心:三个关键方程式的详解——探索预测编码背后的数学原理与应用核心结论:预测编码是一种基于贝叶斯定理的理论框架,它通过三个关键方程式描述了大脑如何处理和解释来自环境的信号。这些方程式分别建立了贝叶斯定理的简化形式、生成模型以及观察者模型,共同揭示了......