当前位置: 首页 > news >正文

【蓝桥杯冲冲冲】进阶搜索 Anya and Cubes

蓝桥杯备赛 | 洛谷做题打卡day22

文章目录

  • 蓝桥杯备赛 | 洛谷做题打卡day22
  • Anya and Cubes
    • 题面翻译
    • 输入格式
    • 输出
    • 题目描述
    • 输入格式
    • 输出格式
    • 样例 #1
      • 样例输入 #1
      • 样例输出 #1
    • 样例 #2
      • 样例输入 #2
      • 样例输出 #2
    • 样例 #3
      • 样例输入 #3
      • 样例输出 #3
    • 提示
    • 题解代码
    • 我的一些话

在这里插入图片描述

输入格式

The first line of the input contains three space-separated integers $ n $, $ k $ and $ S\ (1\le n\le25,\ 0\le k\le n,\ 1\le S\le10^{16})$ — the number of cubes and the number of stickers that Anya has, and the sum that she needs to get.

The second line contains $ n $ positive integers $ a_{i}\ ( 1\le a_{i}\le10^{9}) $ — the numbers, written on the cubes. The cubes in the input are described in the order from left to right, starting from the first one.

Multiple cubes can contain the same numbers.

输出格式

Output the number of ways to choose some number of cubes and stick exclamation marks on some of them so that the sum of the numbers became equal to the given number $ S $ .

样例 #1

样例输入 #1

2 2 30
4 3

样例输出 #1

1

样例 #2

样例输入 #2

2 2 7
4 3

样例输出 #2

1

样例 #3

样例输入 #3

3 1 1
1 1 1

样例输出 #3

6

提示

In the first sample the only way is to choose both cubes and stick an exclamation mark on each of them.

In the second sample the only way is to choose both cubes but don’t stick an exclamation mark on any of them.

In the third sample it is possible to choose any of the cubes in three ways, and also we may choose to stick or not to stick the exclamation mark on it. So, the total number of ways is six.

题解代码

学会利用新知,自己多试试并尝试积攒一些固定解答方案,debug,以下是题解代码 ~

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans[25], res[25], S;
int n, m, maxDep;
bool f;
bool IDDFS(ll p, ll q, int dep)
{if (dep == maxDep){if (p == 1 && q > res[dep - 1] && (q < ans[dep] || !ans[dep])){res[dep] = q;memcpy(ans, res, sizeof(res));return true;}return false;}if (dep == maxDep - 1){for (ll z = (q << 2) / p / p + 1; z < min((S << 1) / p, S * S / q); z++){ll delta = p * p * z * z - (q << 2) * z, s = sqrt(delta);if (s * s != delta || p * z + s & 1)continue;res[dep] = p * z - s >> 1, res[dep + 1] = p * z + s >> 1;if (res[dep + 1] < ans[dep + 1] || !ans[dep + 1]){memcpy(ans, res, sizeof(res));return true;}}return false;}ll l = max(res[dep - 1], (q - 1) / p) + 1LL, r = (maxDep - dep + 1) * q / p;bool flag = false;for (int i = l; i < r; i++){ll tx = p * i - q, ty = q * i, g = __gcd(tx, ty);res[dep] = i;if (IDDFS(tx / g, ty / g, dep + 1))flag = true;}return flag;
}
int main()
{
#ifndef ONLINE_JUDGEfreopen("data.in", "r", stdin);// freopen("data.out", "w", stdout);
#endifscanf("%d%d", &n, &m);while (!f){S = 100, maxDep++;while (S < 1e7 && !f)S = (S << 3) + (S << 1), f = IDDFS(n, m, 1);}for (int i = 1; i <= maxDep; i++)printf("%lld ", ans[i]);return 0;
}

我的一些话

  • 今天学习进阶搜索,深搜属于比较难的部分,需要多动脑,多思考思路还是很好掌握的,虽然一次性AC有一定难度,需要通盘的考虑和理解,以及扎实的数据结构基础才能独立写出AC代码。但无论难易,大家都要持续做题,保持题感喔!一起坚持(o´ω`o)

  • 如果有非计算机专业的uu自学的话,关于数据结构的网课推荐看b站上青岛大学王卓老师的课,讲的很细致,有不懂都可以私信我喔

  • 总结来说思路很重要,多想想,多在草稿纸上画画,用测试数据多调试,debug后成功编译并运行出正确结果真的会感到很幸福!

  • 关于之前蓝桥杯备赛的路线和基本方法、要掌握的知识,之前的博文我都有写,欢迎大家关注我,翻阅自取哦~

  • 不管什么都要坚持吧,三天打鱼两天晒网无法形成肌肉记忆和做题思维,该思考的时候一定不要懈怠,今天就说这么多啦,欢迎评论留言,一起成长:)

相关文章:

  • 医院安全(不良)事件报告系统源码,不良事件处理的全过程管理,实现11大类不良事件类型的报告上报、流转审批、跟踪改进及统计分析功能。
  • Java后端须知的前端知识
  • 2023年全国职业院校技能大赛(高职组)“云计算应用”赛项赛卷9
  • FutureTask底层实现分析
  • jquery的9大选择器
  • C++面试:表结构设计规范
  • 腾讯云SDK并发调用优化方案
  • 迅为LS2K0500开发板引出PCI接口,可扩展显卡、网卡、声卡、视频卡、SATARAID等
  • 突破编程_C++_面试(基础知识(一))
  • LeetCode2670. Find the Distinct Difference Array
  • Golang 流媒体服务器lalserver使用指南
  • Wpf 使用 Prism 实战开发Day16
  • 第七篇:node中间件详解
  • 指针的深入了解6
  • 软件工程知识梳理4-详细设计
  • 【347天】每日项目总结系列085(2018.01.18)
  • Android路由框架AnnoRouter:使用Java接口来定义路由跳转
  • ES6--对象的扩展
  • gitlab-ci配置详解(一)
  • gulp 教程
  • js正则,这点儿就够用了
  • miniui datagrid 的客户端分页解决方案 - CS结合
  • mysql_config not found
  • PAT A1017 优先队列
  • React+TypeScript入门
  • ReactNative开发常用的三方模块
  • SQLServer之创建显式事务
  • 从 Android Sample ApiDemos 中学习 android.animation API 的用法
  • 读懂package.json -- 依赖管理
  • 回流、重绘及其优化
  • 京东美团研发面经
  • 写给高年级小学生看的《Bash 指南》
  • #DBA杂记1
  • #大学#套接字
  • (八)五种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (附源码)ssm旅游企业财务管理系统 毕业设计 102100
  • (六)DockerCompose安装与配置
  • (十一)JAVA springboot ssm b2b2c多用户商城系统源码:服务网关Zuul高级篇
  • (一)为什么要选择C++
  • (轉)JSON.stringify 语法实例讲解
  • *p=a是把a的值赋给p,p=a是把a的地址赋给p。
  • .gitignore
  • .net core 客户端缓存、服务器端响应缓存、服务器内存缓存
  • .NET IoC 容器(三)Autofac
  • .NET/C# 中你可以在代码中写多个 Main 函数,然后按需要随时切换
  • .NET/MSBuild 中的发布路径在哪里呢?如何在扩展编译的时候修改发布路径中的文件呢?
  • .NET高级面试指南专题十一【 设计模式介绍,为什么要用设计模式】
  • @kafkalistener消费不到消息_消息队列对战之RabbitMq 大战 kafka
  • @取消转义
  • [ CTF ] WriteUp- 2022年第三届“网鼎杯”网络安全大赛(朱雀组)
  • [].shift.call( arguments ) 和 [].slice.call( arguments )
  • [AIGC 大数据基础]hive浅谈
  • [android] 切换界面的通用处理
  • [bzoj1038][ZJOI2008]瞭望塔
  • [cb]UIGrid+UIStretch的自适应