Rexdf

The devil is in the Details.

[置顶]发布一个sublime汉化插件

| Comments

很简单的一个插件,现在支持汉化Sublime Text2,Sublime Text3。全部系统Win64、Win32,Linux64,Linux32,OSX等,可以随意来回切换简体中文、繁体中文、日语、英语,无需重启SublimeText。

建站日志

| Comments

今天主要有两个更新,对菜单进行了完整的更新,对CSS布局上的样式进行了修正(IE显示上的bug得到了修正)。

1.IE页面无限滚动

首先讲CSS修正遇到的一个奇葩的现象,之前在开启jiaThis边栏插件的情况下,IE下是可以无限向下拖动的,但是在FIrefox和Chrome下都是好的。这个问题不是太严重,页面滚动到最下面了刻意向下拖动也没意思,所以一直没解决。今天停掉多余的插件时,发现我一直都处于开启状态的jiaThis是可以关掉了,可以直接把代码写到脚本里面就好了,但是我先看了小工具,发现这里藏着一个远古的边栏插件而且它是没有显示的,果断的删掉了。然后没停jiaThis,清空了IE的缓存之后打开偶然发现居然可以滚动到最下面就停止了。于是果断的进行进一步的清理,发现了下面一行代码

<div class="hfeed" id="wrapper">

起初我是以为我在放加载动画的时候放进来的。在修改了部分CSS之后发现页面加载过程中会发生移动现象,显然这不是好的体验,固然是css文件重新定义了这个div的对齐方式了,一查是20px右边对齐,于是在代码行上也打算加上这么一行,这样虽然重复了,但是就不会抖动了。于是我改成了下面这样

<div id="wrapper" style="padding-right: 20px;">

结果在IE中那个现象又出现了,再次可以无限滚动。于是Chrome调试,发现class=”hfeed”似乎没有作任何CSS的选择器,好像就是一个多余项一样。一番搜索发现了下面这个事实。很是有趣,居然有一个预定义的类:显示有人提的问题Question About ‘ class=”hfeed” ‘  英文的参考hatom ,以及翻译过来的hAtom应用 让结构提供数据

2.多语言菜单

做的另外一件事便是多语言的导航菜单,由于支持多语言的qTranslate可以使用

<!--lang-->内容<!--:>

来区别语言,所以菜单栏进行了一下设计。可以切换语言,同时切换后又在不同的语言显示切换菜单。不过这个就像其他html标签一样会被wordpress过滤掉,所以是不能通过导入导出功能备份的,必须自己想法办手工备份。

3.整体布局进行了修改

布局上面,以前导航菜单、谷歌广告、QQ联系方式三个div采用的是以左上的绝对定位方式,显然这种方式不具有通用性,现在应该主要是基于相对定位的了,适应性更强,同时减小了导航菜单上的padding和margin值,留更多的空闲显示博客本身的内容。

4.后面打算

后期我打算写一写CSS与JS的学习笔记,同时整理下算法。

Love

| Comments

\begin{align*}
& \phi(x,y) = \phi \left(\sum_{i=1}^n x_ie_i, \sum_{j=1}^n y_je_j \right)
= \sum_{i=1}^n \sum_{j=1}^n x_i y_j \phi(e_i, e_j) = \\
& (x_1, \ldots, x_n) \left( \begin{array}{ccc}
\phi(e_1, e_1) & \cdots & \phi(e_1, e_n) \\
\vdots & \ddots & \vdots \\
\phi(e_n, e_1) & \cdots & \phi(e_n, e_n)
\end{array} \right)
\left( \begin{array}{c}
y_1 \\
\vdots \\
y_n
\end{array} \right)
\end{align*}

建站日志

| Comments

So long a time, I didn’t update my blog’s theme. But this time it was greatly revisied , and I renew for one year for my host.

1.Google Fonts

2.MulitLuange Support

It should adapt to client’s default language automatically.

3.pdf

You can download the post as a pdf file.But some post including MathJax’s Latex will not be converted as the orginal html.

4.CSS optimization

All navigation bar in gradient

#nav-above {
background-color: #004979;
background: -ms-linear-gradient(top, #0000ff 0%, #7d7fc8 40%, #0000ff 100%);
background: linear-gradient(top, #0000ff 0%, #7d7dc8 40%, #0000ff 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#0000ff', endColorstr='#7d7dc8', GradientType=0 );
background: -moz-linear-gradient(top, blue, rgba(125, 125, 200, 0.5));
background: -webkit-gradient(linear, 0 0, 0 bottom, from(#0000ff), to(rgba(125, 125, 200, 0.5)));
background: -o-linear-gradient(top, blue, rgba(125, 125, 200, 0.5));
}

Compatible with IE, Firefox and Chrome

in ‘include/general-template.php’ edit ‘get_search_form’ function add ‘placeholder’ attribution.

#s:focus { width: 80%; }
.widget_search #s {
float: left;
-webkit-transition-duration: 400ms;
-webkit-transition-property: width, background;
-webkit-transition-timing-function: ease;
-moz-transition-duration: 400ms;
-moz-transition-property: width, background;
-moz-transition-timing-function: ease;
-o-transition-duration: 400ms;
-o-transition-property: width, background;
-o-transition-timing-function: ease;
width: 60%;
}

好久没用折腾博客空间的主题了,这次算是一个较为重大的更新,顺手把主机又续费一年。现在已经包含了较多的插件,有时间后面再专门写一篇介绍。本篇主要讲这次更新新添加的东西。上次ftiasch博客看到MathJax后,就有添加支持的想法。一搜索居然真的就有这个插件,所以直接就用起来了。

1.Google Fonts

不过现在看到的字体都不是谷歌的,谷歌字体已经加入,还没开始使用。

2.多语言

可以自动识别浏览器的语言,也可以手动设置。

3.pdf

添加了下载文章为PDF功能,不过MathJax的Latex就会在pdf里面被原文呈现。

4.CSS优化

4.1导航条全部采用了渐变

#nav-above {
background-color: #004979;
background: -ms-linear-gradient(top, #0000ff 0%, #7d7fc8 40%, #0000ff 100%);
background: linear-gradient(top, #0000ff 0%, #7d7dc8 40%, #0000ff 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#0000ff', endColorstr='#7d7dc8', GradientType=0 );
background: -moz-linear-gradient(top, blue, rgba(125, 125, 200, 0.5));
background: -webkit-gradient(linear, 0 0, 0 bottom, from(#0000ff), to(rgba(125, 125, 200, 0.5)));
background: -o-linear-gradient(top, blue, rgba(125, 125, 200, 0.5));
}

这段代码是用来支持IE、Firefox和Chrome中均能渐变显示的。

4.2动态伸缩搜索框

在include/general-template.php中修改get_search_form搜索框添加了placeholder,并添加了

#s:focus { width: 80%; }
.widget_search #s {
float: left;
-webkit-transition-duration: 400ms;
-webkit-transition-property: width, background;
-webkit-transition-timing-function: ease;
-moz-transition-duration: 400ms;
-moz-transition-property: width, background;
-moz-transition-timing-function: ease;
-o-transition-duration: 400ms;
-o-transition-property: width, background;
-o-transition-timing-function: ease;
width: 60%;
}

主要是针对三个浏览器设置延时,然后宽度设置成60%,获得焦点后变成80%,这样来进行动态伸缩效果。

4.3主要块背景透明

这个使用的技巧比较简单,只要不给div设置背景色,那么它自动就是透明的,然后用一张透明属性的png图片,这样就做成的见到的这个效果。

5经验

因为blog.rexdf.org在是通过.htaccess绑定到子目录的,这样就可以算作两个域名,但是我考虑到了把资源放到不同域名是可以加快加载速度的,因此一些背景图片等就故意使用rexdf.org域名来加载。

测试数学公式

| Comments

[latex]\begin{equation}\label{eq1}r = r_F+ \beta (r_M - r_F) + \epsilon\end{equation}[/latex] [latex] \begin{aligned} \color{red}{\dot{x}} & =\color{blue}{ \sigma(y-x)} \ \dot{y} & = \rho x - y - xz \ \dot{z} & = -\beta z + xy \end{aligned} [/latex] [latex] x^2+y1+z{12}^{34} \ \sin^{-1} (x) \ \lim\limits{h->0} \frac{f(x+h)-f(x)}{h} \ \lim\nolimits{h\to 0} \frac{f(x+h)-f(x)}{h} \ f(x)=\sum\limits{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n \ \int0^1 f(x)dx \ \left[ \begin{array} {lcr} 1 & 2 & 3 \ 4 & 5 & 6 \ 7 & 8 & 9 \end{array} \right] \ \left[ \begin{array}{lcr} a & b \ c & d \end{array} \right] \left( \begin{array}{lcr} n \ k \end{array} \right) [/latex] [latex] \left( \sum{k=1}^n a_k b_k \right)^2 \leq \left( \sum{k=1}^n a_k^2 \right) \left( \sum{k=1}^n b_k^2 \right) \ \mathbf{V}1 \times \mathbf{V}2 = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \ \frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \ \frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 \end{vmatrix} \ P(E) = {n \choose k} p^k (1-p)^{ n-k} \ \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\ldots} } } } \ 1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots = \prod{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, \quad\quad \text{for $ q <1$}. \ \begin{aligned} \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{aligned} [/latex]\[ \mathbf{V}1 \times \mathbf{V}2 = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \ \frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \ \frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 \end{vmatrix} \]$$\left( \sum{k=1}^n a_k b_k \right)^2 \leq \left( \sum{k=1}^n a_k^2 \right) \left( \sum{k=1}^n b_k^2 \right)\\mathbf{V}1 \times \mathbf{V}2 = \begin{vmatrix}\mathbf{i} & \mathbf{j} & \mathbf{k} \\frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0\end{vmatrix}\P(E) = {n \choose k} p^k (1-p)^{ n-k}\\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}{1+\frac{e^{-8\pi}} {1+\ldots} } } }\1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots =\prod{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, \quad\quad \text{for $ q <1$}.\\begin{aligned}\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{aligned}$$

Comments

rexdf:

#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello\n");
return 0;
}

rexdf: \(\sum\limits_{i=0}^{i=\infty}\frac{x^i}{i!}\)

LFP文件格式解析

| Comments

经过一番折腾,在我的64位Win8上面也装上了GSTreamer的Python绑定,然后就开始玩behnam-python-lfp-reader,之后经过搜索,发现了一个标准C语言版本的,和一个用php类写的版本。

1.lfptools

当然先clone下来

git clone git://github.com/nrpatel/lfptools.git

然后进入MingW

cd /e/work/lfptools/
make

成功编译 lfptools 现在就分析下源代码了 main函数进入之后解析命令行第一个参数,并调用lfp_create打开,过程大约就是,算出文件长度并填入表中(二进制到位中间转换过一次),然后整个按照二进制文件读取出来。 接着便是调用lfp_file_check检测是否是lfp格式的文件,lfp格式文件开头标志为0x89, 0x4C, 0x46, 0x50, 0x0D, 0x0A, 0x1A, 0x0A。 下一步就是解析lfp文件了,lfp数据是一块一块的,每块都有一个魔术头3+1byte,然后就是块的长度,这是一个32bit的整数,而且大端方式,转换成正常整数即是数据块长度,之后就是45bit SHA1+35bit Blank,接下去就是声明长度的块数据了。数据块识别好以后就是识别数据块的类型,首先寻找一个“”包含的字符串,从处理上看,应该包括以下几种类型: LFP_RAW_IMAGE应该就是普通的图片格式了,调用converted_image函数处理,似乎就是把38bit的数据转换成如下的两个16位数据。 image LFP_JSON 数据名字,假设其他不是”imageRef”标识的 LFP_DEPTH_LUT 深度信息,是48bit一个32位的float格式。用”depth”(包括引号)标识 LFP_LUT 是Lytro第二版本有的,用”lut”(包括引号)标识 LFP_JPEG 是JPEG格式数据,用”image”(包括引号)标识 LFP_BLOCK_OF_IMAGES 这个是H264块,用”blockOfImagesRef”(包括引号)标识

2.behnam-python-lfp-reader

git clone git://github.com/behnam/python-lfp-reader.git

主要是装Gstreamer的Python绑定比较麻烦,不能用google code的10.7那个OSSBuild,要用2012的那个,而且不能同时安装这个两个。不过奇怪的是在XP系统上那么快,为何在我的系统上几乎要几分钟来执行import gst命令。左键换焦点,中键全聚焦,右键小幅度变化视角。对于代码的分析,没有太大的欲望。所以也就只是调试下这个项目代码而已。 lfp reader

3.Lytro: Image Viewer

git clone git://github.com/maxvw/php-lytro.git

这个是php版本的,本来打算放到博客空间上面的,但是才发现博客是采用php5.2,开了tips问了下,说是不可以,要我买VPS可以自己折腾,想想这个空间大约6月份就到期了,就不续费好了。回到这个软件上了,这个是用php实现的,用了namespace等,用OO的思想实现的,图片进行缓存。 imageviewer经过一番折腾,在我的64位Win8上面也装上了GSTreamer的Python绑定,然后就开始玩behnam-python-lfp-reader,之后经过搜索,发现了一个标准C语言版本的,和一个用php类写的版本。

1.lfptools

当然先clone下来

git clone git://github.com/nrpatel/lfptools.git

然后进入MingW

cd /e/work/lfptools/
make

成功编译 lfptools lfptools2 现在就分析下源代码了 main函数进入之后解析命令行第一个参数,并调用lfp_create打开,过程大约就是,算出文件长度并填入表中(二进制到位中间转换过一次),然后整个按照二进制文件读取出来。 接着便是调用lfp_file_check检测是否是lfp格式的文件,lfp格式文件开头标志为0x89, 0x4C, 0x46, 0x50, 0x0D, 0x0A, 0x1A, 0x0A。 下一步就是解析lfp文件了,lfp数据是一块一块的,每块都有一个魔术头3+1byte,然后就是块的长度,这是一个32bit的整数,而且大端方式,转换成正常整数即是数据块长度,之后就是45bit SHA1+35bit Blank,接下去就是声明长度的块数据了。数据块识别好以后就是识别数据块的类型,首先寻找一个“”包含的字符串,从处理上看,应该包括以下几种类型: LFP_RAW_IMAGE应该就是普通的图片格式了,调用converted_image函数处理,似乎就是把38bit的数据转换成如下的两个16位数据。 image LFP_JSON 数据名字,假设其他不是”imageRef”标识的 LFP_DEPTH_LUT 深度信息,是48bit一个32位的float格式。用”depth”(包括引号)标识 LFP_LUT 是Lytro第二版本有的,用”lut”(包括引号)标识 LFP_JPEG 是JPEG格式数据,用”image”(包括引号)标识 LFP_BLOCK_OF_IMAGES 这个是H264块,用”blockOfImagesRef”(包括引号)标识

2.behnam-python-lfp-reader

git clone git://github.com/behnam/python-lfp-reader.git

主要是装Gstreamer的Python绑定比较麻烦,不能用google code的10.7那个OSSBuild,要用2012的那个,而且不能同时安装这个两个。不过奇怪的是在XP系统上那么快,为何在我的系统上几乎要几分钟来执行import gst命令。左键换焦点,中键全聚焦,右键小幅度变化视角。对于代码的分析,没有太大的欲望。所以也就只是调试下这个项目代码而已。 lfp reader

3.Lytro: Image Viewer

git clone git://github.com/maxvw/php-lytro.git

这个是php版本的,本来打算放到博客空间上面的,但是才发现博客是采用php5.2,开了tips问了下,说是不可以,要我买VPS可以自己折腾,想想这个空间大约6月份就到期了,就不续费好了。回到这个软件上了,这个是用php实现的,用了namespace等,用OO的思想实现的,图片进行缓存。

大家好

| Comments

\begin{align*}
& \phi(x,y) = \phi \left(\sum_{i=1}^n x_ie_i, \sum_{j=1}^n y_je_j \right)
= \sum_{i=1}^n \sum_{j=1}^n x_i y_j \phi(e_i, e_j) = \\
& (x_1, \ldots, x_n) \left( \begin{array}{ccc}
\phi(e_1, e_1) & \cdots & \phi(e_1, e_n) \\
\vdots & \ddots & \vdots \\
\phi(e_n, e_1) & \cdots & \phi(e_n, e_n)
\end{array} \right)
\left( \begin{array}{c}
y_1 \\
\vdots \\
y_n
\end{array} \right)
\end{align*}

Codeforces 177 D

| Comments

Polo the Penguin and Houses

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer p__i (1 ≤ p__i ≤ n). Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number x. Then he goes to the house whose number is written on the plaque of house x (that is, to house p__x), then he goes to the house whose number is written on the plaque of house p__x (that is, to house p__p__x), and so on. We know that:  

  1. When the penguin starts walking from any house indexed from 1 to k, inclusive, he can walk to house number 1.
  2. When the penguin starts walking from any house indexed from k + 1 to n, inclusive, he definitely cannot walk to house number 1.
  3. When the penguin starts walking from house number 1, he can get back to house number 1 after some non-zero number of walks from a house to a house.   You need to find the number of ways you may write the numbers on the houses’ plaques so as to fulfill the three above described conditions. Print the remainder after dividing this number by 1000000007 (109 + 7).

Input

The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ min(8, n)) — the number of the houses and the number k from the statement.

Output

In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

Sample test(s)

input

5 2

output

54

input

7 4

output

1728


#include <iostream>

using namespace std;

const long long MOD=1e9+7;

long long pow_mod(int n,int k)
{
    long  long ret=1,p=n;
    while(k)
    {
        if(k&1)
        {
            ret*=p;
            ret%=MOD;
        }
        p*=p;
        p%=MOD;
        k>>=1;
    }
    return ret;
}

int main()
{
    int N,K;
    cin>>N>>K;
    cout<<((pow_mod(K,K-1)*pow_mod(N-K,N-K))%MOD)<<endl;
    return 0;
}

Codeforces 177 E

| Comments

Polo the Penguin and XOR operation

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive. For permutation p = p0, p1, …, p__n, Polo has defined its beauty — number . Expression  means applying the operation of bitwise excluding “OR” to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is represented as “^” and in Pascal — as “xor”. Help him find among all permutations of integers from 0 to n the permutation with the maximum beauty.

Input

The single line contains a positive integer n (1 ≤ n ≤ 106).

Output

In the first line print integer m the maximum possible beauty. In the second line print any permutation of integers from 0 to n with the beauty equal to m. If there are several suitable permutations, you are allowed to print any of them.

Sample test(s)

input

4

output

20 0 2 1 4 3


#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int a[1000005];
int vis[1000005];

int main()
{
    int n,mask=0,tmp_p,p=1;
    int tmp;
    long long sum=0;
    cin>>n;
    while(p<=n)
    {
        mask|=p;
        p<<=1;
    }
    //cout<<mask<<endl;
    for(int i=n;i;i--)
      if(0==vis[i])
      {
          tmp=((~i)&mask);
          //cout<<i<<" find "<<tmp<<endl;
          if(tmp<=n)
          {
              vis[i]=1;
              vis[tmp]=1;
              sum+=mask<<1;
              a[i]=tmp;
              a[tmp]=i;
          }
          else
          {
              tmp_p=1;
              //tmp=((~i)&(mask>>1));
              while((1<<tmp_p)<=mask)
              {
                  tmp=((~i)&(mask>>tmp_p));
                  if(0==vis[tmp])break;
                  tmp_p++;
              }
              vis[tmp]=1;
              vis[i]=1;
              sum+=(tmp^i)<<1;
              a[i]=tmp;
              a[tmp]=i;
          }
      }
    cout<<sum<<endl;
    if(vis[0])cout<<a[0];
    else cout<<0;
    for(int i=1;i<=n;i++)
      cout<<" "<<a[i];
    return 0;
}

Flash Mob

| Comments

Description Jumping Jack is in charge of organizing a ash mob. The members of the ash mob move around town all day and part of the appeal of this group is they come together to do their thing whenever the mood strikes Jack. When the mood does strike, Jack sends a text message to the members to meet at a particular intersection in town in exactly one hour. The streets of the town run only north-south or east-west and are evenly spaced, forming a perfect grid like a sheet of graph paper. Due to the spontaneity, Jack wants to minimize the inconvenience and so picks an intersection to minimize the total distance traveled by the ash mob’s members. Fortunately Jack has the locations of all the members via the GPS on their cell phones. Your job is to second the meeting location given all the members’ locations. Each intersection will be given by a pair of non-negative integers; the first coordinate is the east-west street and the second coordinate is the north-south street. The location of each ash mob member will be an intersection. Members can travel only north-south or east-west between intersections. For example, suppose there are 5 mob members at locations (3;4);(0;5);(1;1);(5;5), and (5;5). Then if Jack summons them all to location (3;5), the total number of blocks traveled by the mob members would be 14. Jack could do no better { but sometimes the ‘best’ location may not be unique

Input

Input for each test case will be a series of integers on one or more lines. The first integer, n (1 <= n <= 1000), indicates the number of mob members. There follow n pairs of integers indicating the location (intersection) of each member. The location coordinates are both between 0 and 10^6, inclusive. More than one member may be at the same intersection. A line containing 0 will follow the last test case.

Output

Output one line for each test case in the format given below. The ordered pair is the coordinates of the location in the city where the total distance traveled (in blocks) is minimal. If there is more than one such location, output the one with the smallest first coordinate. If there is more than one ‘best’ location with the smallest first coordinate, output the one of those with the smallest second coordinate. The total number of blocks traveled by all the mob members follows the location.

Sample Input

5 3 4 0 5 1 1 5 5 5 5 4 100 2 100 2 100 2 1 20000 0

Sample Output

Case 1: (3,5) 14 Case 2: (100,2) 20097

Source

2012 East Central Regional Contest

//求平面上一点到其他点曼哈顿距离和最小
//其实只要分别考虑两维就好了
//y=|x-x1|+|x-x2|+...+|x-xn|,的最小值一定取在中位数值上(包括偶数个点,此时中间是水平线)
//但是下面的算法并不是这么求的,用的模拟退火的方法,也刷到了8ms,挺不容易的。当然上面的算法肯定是0ms了。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
int p[1005][3],n;
int px[1005],py[1005];
//int min_x,min_y,max_x,max_y;
int st_x,st_y;
int st;
int multx,multy;
const int dx[]={-1,-1,0,-1,0,1,1,1};
const int dy[]={-1,0,-1,1,1,-1,0,1};
 
inline int Abs(int x)
{
    if(x>0)return x;
    return -x;
}
 
int sum(int x,int y)
{
    int ret=0;
    for(int i=0;i<n;i++)
      ret+=Abs(p[i][0]-x)+Abs(p[i][1]-y);
    //cout<<"sum "<<x<<" "<<y<<" "<<ret<<endl;
    //cout<<ret<<endl;
    return ret;
}
 
void solve()
{
    //st_x=(min_x+max_x)/2;st_y=(min_y+max_y)/2;
    int stx,sty;
    int idx;
    st=sum(st_x,st_y);
    int st2;
    while(1)
    {
        idx=-1;
        for(int i=0;i<8;i++)
        {
            stx=st_x+multx*dx[i];
            sty=st_y+multy*dy[i];
            st2=sum(stx,sty);
            if(st2<st || (i<3 && st2==st))
            {
                st=st2;
                idx=i;
            }
        }
        if(-1==idx)
        {
            if(1==multx && 1==multy)break;
            if(multx>1)multx>>=1;
            if(multy>1)multy>>=1;
        }
        else
        {
            st_x=st_x+multx*dx[idx];
            st_y=st_y+multy*dy[idx];
        }
        //cout<<idx<<" "<<st_x<<" "<<st_y<<" "<<sum(st_x,st_y)<<endl;
       //system("pause");
    }
}
 
int main()
{
    freopen("1796in.txt","r",stdin);
    freopen("1796_revise_out.txt","w",stdout);
    int tx,ty;
    long long sx,sy;
    int cs=0;
    while(scanf("%d",&n),n)
    {
        //min_x=1e6;min_y=1e6;
        //max_x=0;max_y=0;
        sx=0;sy=0;
        for(int i=0;i<n;i++)
        {
            //cin>>tx>>ty;
            scanf("%d%d",&tx,&ty);
            p[i][0]=tx;p[i][1]=ty;
            px[i]=tx;py[i]=ty;
            sx+=tx;
            sy+=ty;
        }
        sort(px,px+n);
        sort(py,py+n);
        multx=(px[n-1]-px[0])/2;
        multy=(py[n-1]-py[0])/2;
        if(n&1)
        {
            st_x=px[n/2];
            st_y=py[n/2];
        }
        else
        {
            st_x=(px[n/2]+px[n/2+1])/2;
            st_y=(py[n/2]+py[n/2+1])/2;
        }
        solve();
        cs++;
        //cout<<"Case "<<cs<<": ("<<st_x<<","<<st_y<<") "<<st<<endl;
        printf("Case %d: (%d,%d) %dn",cs,st_x,st_y,st);
    }
    return 0;
}

Description Jumping Jack is in charge of organizing a ash mob. The members of the ash mob move around town all day and part of the appeal of this group is they come together to do their thing whenever the mood strikes Jack. When the mood does strike, Jack sends a text message to the members to meet at a particular intersection in town in exactly one hour. The streets of the town run only north-south or east-west and are evenly spaced, forming a perfect grid like a sheet of graph paper. Due to the spontaneity, Jack wants to minimize the inconvenience and so picks an intersection to minimize the total distance traveled by the ash mob’s members. Fortunately Jack has the locations of all the members via the GPS on their cell phones. Your job is to second the meeting location given all the members’ locations. Each intersection will be given by a pair of non-negative integers; the first coordinate is the east-west street and the second coordinate is the north-south street. The location of each ash mob member will be an intersection. Members can travel only north-south or east-west between intersections. For example, suppose there are 5 mob members at locations (3;4);(0;5);(1;1);(5;5), and (5;5). Then if Jack summons them all to location (3;5), the total number of blocks traveled by the mob members would be 14. Jack could do no better { but sometimes the ‘best’ location may not be unique

Input

Input for each test case will be a series of integers on one or more lines. The first integer, n (1 <= n <= 1000), indicates the number of mob members. There follow n pairs of integers indicating the location (intersection) of each member. The location coordinates are both between 0 and 10^6, inclusive. More than one member may be at the same intersection. A line containing 0 will follow the last test case.

Output

Output one line for each test case in the format given below. The ordered pair is the coordinates of the location in the city where the total distance traveled (in blocks) is minimal. If there is more than one such location, output the one with the smallest first coordinate. If there is more than one ‘best’ location with the smallest first coordinate, output the one of those with the smallest second coordinate. The total number of blocks traveled by all the mob members follows the location.

Sample Input

5 3 4 0 5 1 1 5 5 5 5 4 100 2 100 2 100 2 1 20000 0