Dr. Tuple is working on the new data-mining application for Advanced Commercial Merchandise Inc. One of the subroutines for this application works with two arrays P and Q containing N records of data each (records are numbered from 0 to N − 1). Array P contains hash-like structure with keys. Array P is used to locate record for processing and the data for the corresponding record is later retrieved from the array Q.

  All records in array P have a size of SP bytes and records in array Q have size of SQ bytes. Dr. Tuple needs to implement this subroutine with the highest possible performance because it is a hot-spot of the whole data-mining application. However, SP and SQ are only known at run-time of application which complicates or makes impossible to make certain well-known compile-time optimizations.

  The straightforward way to find byte-offset of i-th record in array P is to use the following formula:

                Pofs(i) = SP · i, (1)

and the following formula for array Q:

                 Qofs(i) = SQ · i. (2)

  However, multiplication computes much slower than addition or subtraction in modern processors. Dr. Tuple avoids usage of multiplication while scanning array P by keeping computed byte-offset Pofs(i) of i-th record instead of its index i in all other data-structures of data-mining application. He uses the following simple formulae when he needs to compute byte-offset of the record that precedes or follows i-th record in array P:

                Pofs(i + 1) = Pofs(i) + SP

                Pofs(i − 1) = Pofs(i) − SP

  Whenever a record from array P is located by either scanning of the array or by taking Pofs(i) from other data structures, Dr. Tuple needs to retrieve information from the corresponding record in array Q. To access record in array Q its byte-offset Qofs(i) needs to be computed. One can immediately derive formula to compute Qofs(i) with known Pofs(i) from formulae (1) and (2):

                 Qofs(i) = Pofs(i)/SP · SQ (3)

  Unfortunately, this formula not only contains multiplication, but also contains division. Even though only integer division is required here, it is still an order of magnitude slower than multiplication on modern processors. If coded this way, its computation is going to consume the most of CPU time in data-mining application for ACM Inc.

  After some research Dr. Tuple has discovered that he can replace formula (3) with the following fast formula:

​ Qofs’(i) = (Pofs(i) + Pofs(i) << A) >> B (4)

  where A and B are non-negative integer numbers, “<< A” is left shift by A bits (equivalent to integer multiplication by 2A), “ >> B” is right shift by B bits (equivalent to integer division by 2B).

  This formula is an order of magnitude faster than (3) to compute, but it generally cannot always produce the same result as (3) regardless of the choice for values of A and B. It still can be used if one is willing to sacrifice some extra memory.

  Conventional layout of array Q in memory (using formula (2)) requires N · SQ bytes to store the entire array. Dr. Tuple has found that one can always choose such K that if he allocates K bytes of memory for the array Q (where KN ·SQ) and carefully selects values for A and B, the fast formula (4) will give non-overlapping storage locations for each of the N records of array Q.

  Your task is to write a program that finds minimal possible amount of memory K that needs to be allocated for array Q when formula (4) is used. Corresponding values for A and B are also to be found. If multiple pairs of values for A and B give the same minimal amount of memory K, then the pair where A is minimal have to be found, and if there is still several possibilities, the one where B is minimal. You shall assume that integer registers that will be used to compute formula (4) are wide enough so that overflow will never occur.

Input

  Input consists of several datasets. Each dataset consists of three integer numbers N, SP, and SQ separated by spaces (1 ≤ N ≤ 2^20,1 ≤ SP ≤ 2^10,1 ≤ SQ ≤ 2^10).

Output

  For each dataset, write to the output file a single line with three integer numbers K, A, and B separated by spaces.

Sample Input

20 3 5

1024 7 1

Sample Output

119 0 0

1119 2 5

HINT

   这个题是参照vj上下面评论的一个大佬写的,虽然想到了等差之类的,但没有想到k的取值公式。这个题从公式上面看可以知道是一个等差公式,那么要保证映射后的下标不会出现位置重复那么公差就必须(p + (p << i)) >> j)/q大于1,否则,比如1和1.2和1.8转换为整数后都是1,那么当公差大于1的话,计算出来的每一个下标比前一个都大于1就不会出现重复的现象。

  下一个要解决的问题就是如何来表示k的取值,因为每一个映射的下标都不会重复,那么最后一个最大的映射之后获得的也是最大的就是k的值,然后每一次比较获得更小的一个。因此比较公式就是(p * (n - 1) + ((p * (n - 1)) << i)) >> j) + q。最后一个是n-1,不是n,0......n-1。另外需要注意的是位运算符的优先级以及int 范围的k很可能会越界。下面是代码:

Accepted

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h> int main()
{
long long int n, p, q;
while (scanf("%lld %lld %lld", &n, &p, &q) != EOF)
{
long long int k = 9223372036854775807;
int a, b;
for (int i = 0;i < 32;i++)
{
for (int j = 0;j < 32;j++)
{
if ((p + (p << i)) >> j >= q && (k > ((p * (n - 1) + ((p * (n - 1)) << i)) >> j) + q))
{
k = ((p * (n - 1) + ((p * (n - 1)) << i)) >> j) + q;
a = i;b = j;
}
}
}
printf("%lld %d %d\n", k, a, b);
}
}

Data Mining UVA - 1591的更多相关文章

  1. Distributed Databases and Data Mining: Class timetable

    Course textbooks Text 1: M. T. Oszu and P. Valduriez, Principles of Distributed Database Systems, 2n ...

  2. What is the most common software of data mining? (整理中)

    What is the most common software of data mining? 1 Orange? 2 Weka? 3 Apache mahout? 4 Rapidminer? 5 ...

  3. What’s the difference between data mining and data warehousing?

    Data mining is the process of finding patterns in a given data set. These patterns can often provide ...

  4. A web crawler design for data mining

    Abstract The content of the web has increasingly become a focus for academic research. Computer prog ...

  5. Datasets for Data Mining and Data Science

    https://github.com/mattbane/RecommenderSystem http://grouplens.org/datasets/movielens/ KDDCUP-2012官网 ...

  6. cluster analysis in data mining

    https://en.wikipedia.org/wiki/K-means_clustering k-means clustering is a method of vector quantizati ...

  7. Weka 3: Data Mining Software in Java

    官方网站: Weka 3: Data Mining Software in Java 相关使用方法博客 WEKA使用教程(经典教程转载) (实例数据:bank-data.csv) Weka初步一.二. ...

  8. data mining,machine learning,AI,data science,data science,business analytics

    数据挖掘(data mining),机器学习(machine learning),和人工智能(AI)的区别是什么? 数据科学(data science)和商业分析(business analytics ...

  9. 数据挖掘(data mining),机器学习(machine learning),和人工智能(AI)的区别是什么? 数据科学(data science)和商业分析(business analytics)之间有什么关系?

    本来我以为不需要解释这个问题的,到底数据挖掘(data mining),机器学习(machine learning),和人工智能(AI)有什么区别,但是前几天因为有个学弟问我,我想了想发现我竟然也回答 ...

随机推荐

  1. C++入门教程:大白话讲解,新手基础篇⭐⭐⭐(附源码及详解、视频课程资料推荐)

    目录 C++教程 前言 视频教程 文字教程 集成开发环境(IDE) 编译器 工作原理 学习指南 入门书籍 进阶书籍 算法.竞赛书籍 教程 标准构建 程序解释 第一个C++程序--"hello ...

  2. 你真的了解URLEncode吗?

    使用浏览器进行Http网络请求时,若请求query中包含中文,中文会被编码为 %+16进制+16进制形式,但你真的深入了解过,为什么要进行这种转义编码吗?编码的原理又是什么? 例如,浏览器中进行百度搜 ...

  3. iOS写在定制相机之前

    问题 不是所有的拍照UIImagePickerController都能搞定,理由如下: 1.产品不整点幺蛾子,哪来体验创新 2.设计不整点幺蛾子,怎能体现用心 3.运营:这体验跟某宝某信咋不一样??? ...

  4. Svelte v2 已经过时了!

    带你走马观花,细看新版变化. 注意:原文发表于2018-04-18,随着框架不断演进,部分内容可能已不适用. 大约是一年之前,我们首次在 Svelte 的 issue 跟踪器上讨论过 v2 版本,现在 ...

  5. 树的遍历c/c++

    先序遍历(递归) 1 void preOrderTraverase(TreeNode * r) 2 { 3 if(r) 4 { 5 printf("%d\t",r->_dat ...

  6. Linux没有ens33解决方案

    一.前言 运行环境:window10+VMware14+Centos7 博主最近遇到一个比较郁闷的问题,在虚拟机上操作Linux系统查看IP的时候,发现没有ens33或者eth0了,试了很多办法都没有 ...

  7. 浮动引发的高度塌陷问题及其解决方法(BFC相关概念及性质)

    浮动引发的高度塌陷问题 高度塌陷问题的产生 BFC(Block Formatting Context)的引入 元素开启BFC后的特点 开启BFC的元素不会被其他浮动元素所覆盖 开启BFC的元素不会发生 ...

  8. 剑指 Offer 32 - II. 从上到下打印二叉树 II + 层次遍历二叉树 + 按层存储

    剑指 Offer 32 - II. 从上到下打印二叉树 II Offer_32 题目描述: 题解分析: 这道题我一开始想到的解决方法较粗暴,就是使用两个变量来记录当前层的节点数和下一层的结点数. 以上 ...

  9. CNN结构演变总结(二)轻量化模型

    CNN结构演变总结(一)经典模型 导言: 上一篇介绍了经典模型中的结构演变,介绍了设计原理,作用,效果等.在本文,将对轻量化模型进行总结分析. 轻量化模型主要围绕减少计算量,减少参数,降低实际运行时间 ...

  10. Linux速通 随笔整理

    Linux速通 随笔整理 为了方便阅读,特整理了相关的学习笔记 零.大纲 一.系统安装 二.命令格式 三.文件管理 四.用户群组 五.文件处理 六.系统初始化及监控 七.硬盘初始化 八.网络原理