当前位置: 首页 > 编程日记 > 正文

12. 17 哈理工网络赛

An Easy Geometry Problem
Description

Lily is interested in hyperspace recently, and she is trying to solve an easy problem now. Given an n-dimensional hyperspace, assuming each dimension is a1, a2, a3, ..., an. And for each i (1 ≤ i ≤ n), j (i < j ≤ n), there is a plane ai=aj  These planes have divided the hyperspace into different regions. For example, in 3D hyperspace, we have three planes: x=y, y=z and x=z.

Now given q queries, for each query, there is a point (x1, x2, x3, ..., xn). Lily wants to know the maximum radius r of an n-dimensional ball she can put in point (x1, x2, x3, ..., xn), which means the center of the ball is in point (x1, x2, x3, ..., xn) and the ball’s surface cannot cross but can touch any planes mentioned above.

The equation of an n-dimensional ball with center (x1, x2, x3, ..., xn) is . And the distance between two points (x1, x2, x3, ..., xn) and (x1', x2', x3', ..., xn') in an n-dimensional hyperspace is:.

Input

First line contains an integer T (1 ≤ T ≤ 5), represents there are T test cases.

For each test case: First line contains two integers n (3 ≤ n ≤ 50000) and q (1 ≤ q ≤ 8), where n is the dimension of the hyperspace, and q is the number of queries. Following q lines, each line contains n integers x1, x2, x3, ..., xn (-109 ≤ xi ≤ 109), represents the coordinate of the ball’s center.

Output

For each test case, output one line containing "Case #X:"(without quotes), where X is the case number starting from 1, and output q lines containing the maximum possible radius of the ball in each query in input order, rounded to four decimal places.

Sample Input

1

3 2

0 0 0

11 22 33

Sample Output

Case #1:

0.0000

7.7782

题目分析 : 给你一个所在 n 维空间中的点,会有一些平面, 比如二维空间中的 x = y 平面,现在让你求以所给平面为圆心的半径最大的圆。

首先先考虑二维空间的情况,点到直线的公式这很容易求出来,那么扩展到  n  维空间呢,也是很好想的,任取空间中的两个坐标,投射到相应的平面上,可以计算出一个半径,现在要求所有的半径,直接暴力 n^2 ,肯定会超时,现在你就可以对所给的点进行一个排序,寻找相邻的两个点的最小结果,作为答案。

代码示例 :

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
const double num = sqrt(2);
using namespace std;
typedef long long ll;ll pre[51234];ll ab(ll x){if (x < 0) return -x;else return x;
}int main (){int t;int n, q;int cas = 1;cin >> t;while(t--){cin >> n >> q;printf("Case #%d:\n", cas++);while(q--){for(int i = 1; i <= n; i++){scanf("%lld", &pre[i]);}sort(pre+1, pre+1+n);  // 这里很重要 double ans = 999999999;for(int i = 1; i < n; i++){ll d = ab(pre[i]-pre[i+1]);ans = min(ans, 1.0*d/num);}printf("%.4lf\n", round(ans*10000)/10000);	}	}	return 0;
} 

I .

Aggie is faced with a sequence of tasks, each of which with a difficulty value di and an expected profit pi. For each task, Aggie must decide whether or not to complete it. As Aggie doesn’t want to waste her time on easy tasks, once she takes a task with a difficulty di, she won’t take any task whose difficulty value is less than or equal to di.

Now Aggie needs to know the largest profits that she may gain.

Input

The first line consists of one positive integer t (t ≤ 10), which denotes the number of test cases.

For each test case, the first line consists one positive integer n (n ≤ 100000), which denotes the number of tasks. The second line consists of n positive integers, d1, d2, …, dn (di ≤ 100000), which is the difficulty value of each task. The third line consists of n positive integers, p1, p2, …, pn (pi ≤ 100), which is the profit that each task may bring to Aggie.

Output

For each test case, output a single number which is the largest profits that Aggie may gain.

Sample Input

1

5

3 4 5 1 2

1 1 1 2 2

Sample Output

4

题目分析 : 类似于LIS,也可以采取维护一个最大的和的序列,但是有一点不同的是,就是在后续插入一个值后,要讲该值后面的元素中键值大于插入的,但是和却小于插入的和的 全部删除掉, 这里用 map 来维护 。

代码示例 :

int a[eps], b[eps];int main() {//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);int t, n;map<int, int>mp;map<int, int>::iterator it, ip, is;cin >>t;while(t--){cin >> n;for(int i = 1; i <= n; i++) scanf("%d", &a[i]);for(int i = 1; i <= n; i++) scanf("%d", &b[i]);mp.clear();mp[0] = 0;int ans = 0;for(int i = 1; i <= n; i++){if (!mp.count(a[i])) mp[a[i]] = b[i];it = mp.find(a[i]);ip = --it;int p = ip->second + b[i];it++;mp[a[i]] = max(mp[a[i]], p);for(ip = ++it; ip != mp.end(); ip++){if (ip->second <= mp[a[i]]) {is = --ip;mp.erase(++ip);ip = is;}else break;}ans = max(ans, mp[a[i]]);}    printf("%d\n", ans);}return 0;
}

解法二 : 利用 dp 的思想,维护一个最长的递增子序列,将收益视为相同困难度的情况

int a[eps], b[eps];
int dp[eps2];int main() {//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);int t, n;cin >>t;while(t--){cin >> n;for(int i = 1; i <= n; i++) scanf("%d", &a[i]);for(int i = 1; i <= n; i++) scanf("%d", &b[i]);memset(dp, inf, sizeof(dp));int len = 0;for(int i = 1; i <= n; i++){int p = lower_bound(dp, dp+len, a[i])-dp;for(int j = p; j < p+b[i]; j++){dp[j] = a[i];}len = max(len, p+b[i]);}printf("%d\n", len);}return 0;
}

转载于:https://www.cnblogs.com/ccut-ry/p/8058933.html

相关文章:

微信确认出Bug,目前已全部恢复

1 月 24 日&#xff0c;微信官方发布声明称&#xff0c;今天上午&#xff0c;微信部分功能出现故障&#xff0c;微信用户登录、消息会话、公众号、小程序、外部链接、文件发送等功能均受到不同程度的影响&#xff0c;波及小部分用户。今日 10:30 左右&#xff0c;有网友表示&am…

《xUnit Test Patterns》学习笔记3 - Philosophy of Test Automation

这一章主要讲自动化测试的原则。前面的章节介绍了很多测试的思想&#xff0c;而思想的东西难免有点虚&#xff0c;这一章就是告诉你&#xff0c;遇到了具体的什么问题时&#xff0c;应该怎么办。作者咨询了很多的开发人员和测试人员&#xff0c;同时也和Martin Fowler就自动化测…

js new 运算符到底做了什么?

MDN上是这么介绍new运算符的&#xff1a;new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象类型之一。 这里&#xff0c;我们探究的是new运算符实际上做了什么&#xff1f; var a new A(); 复制代码当这段代码运行的时候&#xff0c;内部实际上执行的是&am…

Qt中文手册 之 QTableWidgetItem

头文件 #include<QTableWidgetItem> 成员函数 1、QTableWidgetItem::QTableWidgetItem(int type = Type) 使用指定item类型type构造。 item的type QTableWidgetItem::Type0默认的类型:窗口部件QTableWidgetItem::UserType1000The minimum value for custom types. Val…

你知道“啥是佩奇”,却不一定了解佩奇排名算法

作者 | 程序员小吴 从初学者的角度学习算法&#xff0c;以动画的形式呈现解题的思路。来源 | 五分钟学算法佩奇排名介绍佩奇排名是根据页面之间的链接结构计算页面的值的一种算法。下面我们通过动画来理解进行计算的具体流程。假设一个正方形表示一个 WEB 页面&#xff0c;一个…

用友发布U8 All-in-One引爆中小企业全面信息化

1月16日&#xff0c;北京经历了2010年第一场大雪和创50年的低温记录后&#xff0c;温度似有回升的感觉。什刹海一座别致建筑二楼的"用友中小企业全面信息化策略暨U8 All-in-One发布会"现场洋溢着融融暖意。用友在这里隆重发布了面向中小企业全面信息化的解决方案--U8…

Qt中文手册 之 QTreeWidgetItem

头文件:#include <QTreeWidgetItem> 成员函数 1、QTreeWidgetItem::QTreeWidgetItem(int type = Type) 使用类型type构造项,默认类型窗口类型 2、QTreeWidgetItem::QTreeWidgetItem(const QStringList & strings, int type = Type) 使用字符串列表strings作为项…

6位技术大咖11月倾心巨献,大数据+安全主题的技术分享合集【阿里云MVP 干货集锦】...

为什么80%的码农都做不了架构师&#xff1f;>>> 摘要&#xff1a; 大家好&#xff0c;阿里云 MVP 11月大数据安全主题分享新鲜出炉&#xff0c;快来一睹为快吧&#xff01;哪些MVP的分享最吸引你&#xff0c;你最想支持哪个MVP&#xff1f; 我们将开启为期一周的最…

linux下jsp环境的搭建

转自http://gehailong.blog.51cto.com/765312/264162作gehailong一 、安装JDK#chmod x jdk-6u13-linux-i586-rpm.bin//给文件加入执行权限#./jdk-6u13-linux-i586-rpm.bin//生成安装文件,运行完此命令后会生成一个jdk-6u13-linux-i586.rpm#rpm -ivh jdk-6u13-linux-i586.rpm//安…

ABP理论学习之通知系统

本篇目录 介绍订阅通知发布通知用户通知管理者实时通知通知存储通知定义介绍 通知&#xff08;Notification&#xff09;用于告知用户系统中的特定事件。ABP提供了基于实时通知基础设施的发布订阅模型&#xff08;pub/sub&#xff09;。 发送模型 给用户发送通知有两种方式&am…

linux驱动:TI+DM8127+GPIO(一)之应用——报警输入输出

一、【GPIO应用】 报警输出1 ALRM_OUT1A、ALRM_OUT1B <-- ALM_OUT1 <-- CVOUT1_YC4 <-- W22 <--VOUT[1]_G_Y_YC[4]/EMAC[1]_MRXD[7]/VIN[1]A_D[9]/PATA_D[1]/GP3[8] /sys/class/gpio/gpio104/value 其中104 32*38 GPIOn_x的编号为32*nx&#xff0c;例如此处用…

Facebook增强版LASER开源:零样本迁移学习,支持93种语言

来源| Facebook AI 研究院译者 | Linstancy责编 | 琥珀出品 | AI 科技大本营&#xff08;ID:rgznai100&#xff09;【导语】为了加速自然语言处理 (NLP) 在更多语言上实现零样本迁移学习 (zero-shot transfer learning)&#xff0c;Facebook 研究者扩展并增强了 LASER (Languag…

Python文本预处理:步骤、使用工具及示例

作者 | Data Monster译者 | Linstancy编辑 | 一一出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09;本文将讨论文本预处理的基本步骤&#xff0c;旨在将文本信息从人类语言转换为机器可读格式以便用于后续处理。此外&#xff0c;本文还将进一步讨论文本预处理过程所需要…

读《杜拉拉升职记》有感

读杜拉拉升职记有感1.一定要在核心部门任职&#xff0c;防止被边缘化2.劳心者治人&#xff0c;劳力者治于人干了活还受气怎么办&#xff1f;1.把每一个阶段的主要任务和安排的都做成清晰简明的表格&#xff0c;发给我的老板&#xff0c;告诉他如果有反对意见&#xff0c;在某某…

linux驱动:TI+DM8127+GPIO(二)之驱动

二、【GPIO驱动框架》驱动driver】 重要结构体 gpio_chip&#xff1a;管理一组GPIO gpio_desc&#xff1a;描述每个GPIO gpio_bank&#xff1a;封装了gpio_chip加入GPIO控制的属性 1、驱动注册到platform中 Arch/arm/plat-omap/gpio.c中 static int __init omap_gpio_drv…

菜鸟的DUBBO进击之路(八):配置抽离导致${jdbc.url}被当成字符串处理

为什么80%的码农都做不了架构师&#xff1f;>>> 导致这个问题的原因有很多&#xff0c;基于我查到的资料做个记录 第一:xmlns:context"http://www.springframework.org/schema/context" xsi:schemaLocation"http://www.springframework.org/schema/…

用VS2005打开方案出现“此安装不支持该项目类型”

当在用VS2005打开已有项目时常会出现“此安装不支持该项目类型”。 出现此原因是因为已有项目是在打了VS 2005 SP1补丁后编写的&#xff0c;所以在没有打补丁的.net中会出现此种情况 下面就补丁下载&#xff1a;VS80sp1-KB926604-X86-CHS.exeWebApplicationProjectSetup.msi

linux驱动:TI+DM8127+GPIO(三)之omap_hwmod中添加GPIO资源

三、【GPIO驱动框架》向omap_hwmod中添加GPIO资源】 ***将GPIO硬件信息添加到注册到omap_hwmod_list列表中 Arch/arm/plat-omap/include/plat/ti81xx.h中 #define TI814X_GPIO3_BASE 0x481AE000 Arch/arm/plat-omap/gpio.c中 输入输出控制寄存器偏移地址 #define OMAP4…

用Redis存储Tomcat集群的Session(转载)

本文转自http://blog.csdn.net/chszs/article/details/42610365 感谢作者 前段时间&#xff0c;我花了不少时间来寻求一种方法&#xff0c;把新开发的代码推送到到生产系统中部署&#xff0c;生产系统要能够零宕机、对使用用户零影响。 我的设想是使用集群来搞定&#xff0c;通…

微信的Bug差点让我被老板炒鱿鱼!

作者 | 屠敏转载自CSDN&#xff08;ID:CSDNnews&#xff09;1 月 24 日上午 10&#xff1a;30 左右&#xff0c;10 亿用户量的国民应用微信疑似出现大 Bug。据网友反馈&#xff0c;自己一直使用的微信号突然显示被删除&#xff0c;登也登不上。对此&#xff0c;不少人的银行卡一…

vPower系列1: vMotion-没有vMotion,虚拟化只是玩具

vPower今天开讲&#xff0c;第一篇vMotion。vMotion是虚拟化可以支撑核心应用的重要前提&#xff0c;没有vMotion&#xff0c;虚拟化只是玩具&#xff0c;只能应用在实验环境和开发环境。为什么这么说呢&#xff1f;为什么会有vMotion&#xff1f;vMotion解决了虚拟平台上的什么…

linux驱动:TI+DM8127+GPIO(四)之设备

四、【GPIO驱动框架》设备device】 arch/arm/mach-omap2/gpio.c中 1、static int __init omap2_gpio_init(void) { returnomap_hwmod_for_each_by_class("gpio", omap2_gpio_dev_init, NULL); } archarm/mach-omap2/omap_hwmod.c 中 2、int omap_hwmod_for_each…

简单的TableViewCell高度自适应(只有Label,仅当参考思路)

在iOS开发中或多或少的都会碰到TableViewCell高度自适应,那么今天这篇文章就简单的介绍一下如何给tableViewCell自适应高度 #ViewController copy interface ViewController ()<UITableViewDelegate, UITableViewDataSource>{UITableView *_tableView; }property (nonato…

Google发布新的问答语料库,专攻篇章级的NLU问题

译者 | Linstancy整理 | Jane出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09;开放域的问答&#xff08;QA&#xff09;是自然语言理解&#xff08;NLU&#xff09;中的一项基本任务&#xff0c;旨在模拟人是如何通过阅读和理解完整的文档&#xff0c;从而寻找信息、发…

AjaxControltoolkit(工具包)安装步骤说明

本来打算做一个系统搜索中Ajax AutoComplete自动提示的效果,想尝试一下以前用AjaxControlToolkit中控件,在官网上下载一个AjaxControlToolkit2.0版本我尽然忘了如何安装.很是汗了一把. 看来人都是有惰性的,哪怕自己认为以前比较熟练自信的东西 如果时间一长不做回顾还是不行的 …

linux驱动:TI+DM8127+GPIO(五)之plarform

五、【GPIO驱动框架》平台platform】 &#xff08;一&#xff09;设备找驱动 1、drivers/base/platform.c中 int platform_device_register(structplatform_device *pdev) { device_initialize(&pdev->dev); returnplatform_device_add(pdev); } 2、int platform_…

2:0!谷歌 AI “AlphaStar“ 虐杀职业星际玩家

作者 | 若名出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09;刚刚&#xff0c;在更复杂的《星际争霸 II》游戏中&#xff0c;DeepMind AI 以总比分 2:0 分别战胜两位职业人类选手。这或许是自 2017 年 AlphaGo 在围棋上战胜人类后&#xff0c;再次让人类刷新 AI 认知的…

插件化知识梳理(7) 类的动态加载入门

一、前言 在 插件化知识梳理(6) - Small 源码分析之 Hook 原理 这一章的学习完成之后&#xff0c;下一步我们将进入插件化加载的精髓&#xff0c;动态加载类的学习&#xff0c;在此之前&#xff0c;我们需要先准备一些关于类加载的知识。 Android当中&#xff0c;支持动态加载的…

redhat中使用securecrt 中文乱码解决办法

具体解决方法是&#xff1a; 1&#xff0c;修改远程linux机器的配置 vim /etc/sysconfig/i18n 把LANG改成支持UTF-8的字符集 如&#xff1a;LANG”zh_CN.UTF-8″ 或者是 LANG”en_US.UTF-8″ 2&#xff0c;然后再改Secure CRT的设置,选项->会话选项->外观->字符编码-&…

知否?知否?一文看懂深度文本分类之DPCNN原理与代码

【导读】ACL2017年中&#xff0c;腾讯AI-lab提出了Deep Pyramid Convolutional Neural Networks for Text Categorization(DPCNN)。论文中提出了一种基于word-level级别的网络-DPCNN&#xff0c;由于上一篇文章介绍的TextCNN 不能通过卷积获得文本的长距离依赖关系&#xff0c;…