Categories
不学无术

interval scale和ratio scale的区别

interval scale 等距尺度:又称区间尺度,衡量的数字可代表大小或优劣顺序,数字的差距直接表示其差异的程度。
ratio scale 比例尺度:物与物的相对比较,表明各种物体间的相对度量关系。
参考百度百科

Categories
不学无术

Eclipse JRI : Java 调用 R 报错: Cannot find JRI native library!

Q: I get the following error, what’s wrong?
java.lang.UnsatisfiedLinkError: no jri in java.library.path
A: Usually it means that you didn’t setup the necessary environment variables properly or the JRI library is not where it is expected to be. The recommended way to start JRI programs is to use the run script which is generated along with the library. It sets everything up and is tested to work. If you want to write your own script or launcher, you must observe at least the following points:

  • R_HOME must be set correctly
  • (Windows): The directory containing R.dll must be in your PATH
  • (Mac): Well, it’s a Mac, so it just works ;).
  • (unix): R must be compiled using --enable-R-shlib and the directory containing libR.so must be in LD_LIBRARY_PATH. Also libjvm.so and other dependent Java libraries must be on LD_LIBRARY_PATH.
  • JRI library must be in the current directory or any directory listed in java.library.path. Alternatively you can specify its path with 
    -Djava.library.path= when starting the JVM. When you use the latter, make sure you check java.library.path property first such that you won’t break your Java.
  • Depending on your system, the R verison and other features you want to use, you may have to set additional settings such as R_SHARE_DIRR_INCLUDE_DIR andR_DOC_DIR.

Again, I don’t think you want to worry about all of the above – just use the start script!

特别注意红字标注的这一行,
QQ截图20130728131711
在这边修改实现即可。
参考:http://www.rforge.net/JRI/

Categories
不学无术

JXL Excel使用

http://www.360doc.com/content/11/0422/14/6728052_111518047.shtml

Categories
不学无术

1028. List Sorting (25) | STL中自定义排序

时间限制

200 ms
内存限制
32000 kB
代码长度限制
16000 B
Excel can sort records according to any column. Now you are supposed to imitate this function.
Input
Each input file contains one test case. For each case, the first line contains two integers N (<=100000) and C, where N is the number of records and C is the column that you are supposed to sort the records with. Then N lines follow, each contains a record of a student. A student’s record consists of his or her distinct ID (a 6-digit number), name (a string with no more than 8 characters without space), and grade (an integer between 0 and 100, inclusive).
Output
For each test case, output the sorting result in N lines. That is, if C = 1 then the records must be sorted in increasing order according to ID’s; if C = 2 then the records must be sorted in non-decreasing order according to names; and if C = 3 then the records must be sorted in non-decreasing order according to grades. If there are several students who have the same name or grade, they must be sorted according to their ID’s in increasing order.
Sample Input 1

3 1
000007 James 85
000010 Amy 90
000001 Zoe 60

Sample Output 1

000001 Zoe 60
000007 James 85
000010 Amy 90

Sample Input 2

4 2
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 98

Sample Output 2

000010 Amy 90
000002 James 98
000007 James 85
000001 Zoe 60

Sample Input 3

4 3
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 90

Sample Output 3

000001 Zoe 60
000007 James 85
000002 James 90
000010 Amy 90

============================================
这个题目能想到最好的办法,就是用set然后重载一个自定义排序了 感谢郭嘉,感谢STL!
set这个东西嘛,好像是用红黑树还是什么实现的(印象中是这样的) 原来打算用vector的,但是vector好像不能在插入的时候就根据自定义的排序方法排序好插进去,这样如果全部录入完了整体排序一遍是不是更耗费时间呢?
参考文章:
http://blog.csdn.net/stone_sky/article/details/8471722 讲的是自定义排序 http://zhidao.baidu.com/question/189798009.html 讲的是输出填0格式化问题 http://www.189works.com/article-43335-1.html http://wenku.baidu.com/view/08c0eb0bff00bed5b9f31d29.html 这两个就是自定义排序了
这题目这么搞了以后就简单多了:)当然最后一个测试点还是用了100ms…不管了过了就行 ============================================

#include
#include
#include
#include
using namespace std;
int compareName(const char name1[],const  char name2[])
{
    for(int i=0; i<8; i++)
    {
        if( name1[i] < name2[i] )
            return 1;
        else if(name1[i] > name2[i])
            return -1;
        //相等的话继续比较
    }
    return 0; //相同的名字
}
struct StudentRecord
{
    int ID;
    char name[9];
    int grade;
    int sortType; //按哪一列排序,1,2,3
    StudentRecord(){}
    StudentRecord(int _id, char _name[], int _grade, int _sortType)
    {
        ID = _id;
        strcpy(name, _name);
        grade = _grade;
        sortType = _sortType;
    }
    void set(int _id, char _name[], int _grade)
    {
        ID = _id;
        strcpy(name, _name);
        grade = _grade;
    }
    //自定义排序方法
    bool operator< (const StudentRecord& other) const
    {
        int cmpResult;
        switch(sortType)
        {
        case 1:
            //按照ID升序排列
            return ID < other.ID;
        case 2:
            //按照姓名的升序排列,如果有同名再按ID升序
            cmpResult = compareName(name, other.name);
            if(cmpResult > 0)
                return true;
            else if (cmpResult < 0)
                return false;
            else
                return ID < other.ID;
        case 3:
            //按照成绩的升序排列,如果有同名成绩按ID升序
            if (grade == other.grade)
                return ID < other.ID;
            else
                return grade < other.grade;
        default:
            printf("ERROR!");
            return false;
        }
    }
};
set records;
int main()
{
    long N; int C;
    scanf("%ld %d", &N, &C);
    StudentRecord singleRec;
    singleRec.sortType = C;
    for(long i=0; i<N; i++)
    {
        int ID, grade;
        char name[8];
        scanf("%d %s %d", &ID, name, &grade);
        singleRec.set(ID, name, grade);
        records.insert(singleRec);
    }
    set::iterator it;
    for(it = records.begin(); it != records.end(); it++)
    {
        StudentRecord sr = *it;
        printf("%06d %s %dn", sr.ID, sr.name, sr.grade);
    }
    return 0;
}

====================================

测试点

测试点 结果 用时(ms) 内存(kB) 得分/满分
0 答案正确 0 790 5/5
1 答案正确 0 740 5/5
2 答案正确 0 750 5/5
3 答案正确 0 790 2/2
4 答案正确 0 790 2/2
5 答案正确 0 740 2/2
6 答案正确 100 8970 4/4
Categories
不学无术

c++中vector自定义排序的问题

http://blog.csdn.net/stone_sky/article/details/8471722

Categories
木有技术

Visual Studio 2012 改Tab制表符为4个空格

之前没发现这个问题,后来看到自己发的博客里面代码各种参差不齐…想到有可能是这个东西的关系…
其实对于C++来说Tab键还不是致命的,要是写Python的话Tab和空格弄不清就爽翻了..~当然这个是题外话了,没人用VS写Python的吧:)
步骤如图,不赘述了~
QQ截图20130725132639
QQ截图20130725132700 QQ截图20130725132706
 
然后确定
 
其他软件的可以参考此文:
http://blog.csdn.net/wfdtxz/article/details/8520629

Categories
不学无术

1009. Product of Polynomials (25)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
This time, you are supposed to find A*B where A and B are two polynomials.
Input Specification:
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 … NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, …, K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10, 0 <= NK < … < N2 < N1 <=1000.
 
Output Specification:
For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.
Sample Input

2 1 2.4 0 3.2
2 2 1.5 1 0.5

Sample Output

3 3 3.6 2 6.0 1 1.6

=====================================
这题目没什么难度的说,就是多项式乘积嘛~
唯一要注意的事情是,结果的输出时按照指数递减的…这里用了map里面的reverse_iterator,真心是好用!
另外,也不知道系数有没有负数,所以处理的时候考虑了一下相加为0的情况…貌似没啥必要哦…
总之是很简单的东西~前提是有STL这货…
=====================================

#include 
#include 
using namespace std;
#define MapIterator map::iterator
#define MapIteratorReverse map::reverse_iterator
int main()
{
    int K;
    scanf("%d", &K);
    map polyA; //第一行
    for(int i=0; i p(Ni, Ki);
        polyA.insert(p);
    }
    scanf("%d", &K);
    map result; //结果
    for(int i=0; ifirst + Ni;  //乘方
            float Kj = it->second * Ki;//系数
            if(result.count(Nj) > 0)
            {
                //原来有结果
                float sum = Kj + result[Nj];
                if(sum == 0)
                    //这项没了...
                    result.erase(Nj);
                else
                    result[Nj] = sum;
            }
            else
            {
                result.insert(pair(Nj, Kj));
            }
        }
    }
    printf("%d", result.size());
    MapIteratorReverse it;
    for(it = result.rbegin(); it != result.rend(); it++)
    {
        printf(" %d %.1f", it->first, it->second);
    }
    return 0;
}
Categories
不学无术 木有技术

Eclipse中文字体太小的解决方法

原文来自:http://www.cnblogs.com/newdon318/archive/2012/03/23/2413340.html
最近新装了Win7,打开eclipse3.7中文字体很小,简直难以辨认。在网上搜索发现这是由于Eclipse 3.7 用的字体是 Consolas,显示中文的时候默认太小了。
解决方式有两种:
一、把字体设置为Courier New
操作步骤:打开Elcipse,点击菜单栏上的“Windows”——点击“Preferences”——点击“Genneral”——点击“Appearance”——点击“Colors and Font”——在右侧框展开“Basic”文件夹–双击“Text Font”——在弹出窗选择“Courier New”(注:这里可能找不到“Courier New”,点击字体选择框左下角的“显示更多字体”链接来打开设置字体的控制面板,找到“Courier New”,右键选择“显示”即可激活该字体)——点击按钮“确定”——点击按钮“OK”,完成。
二、使用混合字体代替Consolas字体。
操作步骤:
1.下载Consolas和微软雅黑混合字体(地址:http://files.cnblogs.com/icelyb24/YaHei.Consolas.1.12.rar
2.解压之后,把YaHei.Consolas.1.12.ttfw文件复制到C:WindowsFonts目录下,完成字体的安装
3.打开Elcipse,点击菜单栏上的“Windows”——点击“Preferences”——点击“Genneral”——点击“Appearance”——点击“Colors and Font”——在右侧框展开“Basic”文件夹–双击“Text Font”——在弹出窗选择“YaHei.Consolas”——点击按钮“确定”——点击按钮“OK”,完成。

Categories
不学无术

C++异常机制

本文转载自 http://ticktick.blog.51cto.com/823160/191881
====================================================================
这两天我写了一个测试c++异常处理机制的例子,感觉有很好的示范作用,在此贴出来,给c++异常处理的初学者入门。本文后附有c++异常的知识普及,有兴趣者也可以看看。
下面的代码直接贴到你的console工程中,可以运行调试看看效果,并分析c++的异常机制。

  1. #include “stdafx.h”
  2. #include<stdlib.h>
  3. #include<crtdbg.h>
  4. #include <iostream>
  5. // 内存泄露检测机制
  6. #define _CRTDBG_MAP_ALLOC
  7. #ifdef _DEBUG
  8. #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
  9. #endif
  10. // 自定义异常类
  11. class MyExcepction
  12. {
  13. public:
  14.         // 构造函数,参数为错误代码
  15.         MyExcepction(int errorId)
  16.         {
  17.          // 输出构造函数被调用信息
  18.             std::cout << “MyExcepction is called” << std::endl;
  19.             m_errorId = errorId;
  20.         }
  21.         // 拷贝构造函数
  22.         MyExcepction( MyExcepction& myExp)
  23.         {
  24.          // 输出拷贝构造函数被调用信息
  25.             std::cout << “copy construct is called” << std::endl;
  26.             this->m_errorId = myExp.m_errorId;
  27.         }
  28.        ~MyExcepction()
  29.         {
  30.             // 输出析构函数被调用信息
  31.             std::cout << “~MyExcepction is called” << std::endl;
  32.         }
  33.        // 获取错误码
  34.         int getErrorId()
  35.         {
  36.             return m_errorId;
  37.         }
  38. private:
  39.         // 错误码
  40.         int m_errorId;
  41. };
  42. int main(int argc, char* argv[])
  43. {
  44.         // 内存泄露检测机制
  45.         _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
  46.         // 可以改变错误码,以便抛出不同的异常进行测试
  47.         int throwErrorCode = 110;
  48.        std::cout << ” input test code :” << std::endl;
  49.        std::cin >> throwErrorCode;
  50.        try
  51.        {
  52.             if ( throwErrorCode == 110)
  53.             {
  54.              MyExcepction myStru(110);
  55.                 // 抛出对象的地址 -> 由catch( MyExcepction*    pMyExcepction) 捕获
  56.                 // 这里该对象的地址抛出给catch语句,不会调用对象的拷贝构造函数
  57.                 // 传地址是提倡的做法,不会频繁地调用该对象的构造函数或拷贝构造函数
  58.                 // catch语句执行结束后,myStru会被析构掉
  59.                 throw    &myStru;
  60.             }
  61.             else if ( throwErrorCode == 119 )
  62.             {
  63.              MyExcepction myStru(119);
  64.                 // 抛出对象,这里会通过拷贝构造函数创建一个临时的对象传出给catch
  65.                 // 由catch( MyExcepction    myExcepction) 捕获
  66.                 // 在catch语句中会再次调用通过拷贝构造函数创建临时对象复制这里传过去的对象
  67.                 // throw结束后myStru会被析构掉
  68.                 throw    myStru;
  69.              }
  70.              else if ( throwErrorCode == 120 )
  71.              {
  72.                   // 不提倡这样的抛出方法
  73.                   // 这样做的话,如果catch( MyExcepction*    pMyExcepction)中不执行delete操作则会发生内存泄露
  74.                   // 由catch( MyExcepction*    pMyExcepction) 捕获
  75.                   MyExcepction * pMyStru = new MyExcepction(120);
  76.                   throw pMyStru;
  77.              }
  78.              else
  79.              {
  80.                   // 直接创建新对象抛出
  81.                   // 相当于创建了临时的对象传递给了catch语句
  82.                   // 由catch接收时通过拷贝构造函数再次创建临时对象接收传递过去的对象
  83.                   // throw结束后两次创建的临时对象会被析构掉
  84.                    throw MyExcepction(throwErrorCode);
  85.              }
  86.         }
  87.         catch( MyExcepction*    pMyExcepction)
  88.         {
  89.              // 输出本语句被执行信息
  90.                std::cout << “执行了 catch( MyExcepction*    pMyExcepction) ” << std::endl;
  91.              // 输出错误信息
  92.                std::cout << “error Code : ” << pMyExcepction->getErrorId()<< std::endl;
  93.             // 异常抛出的新对象并非创建在函数栈上,而是创建在专用的异常栈上,不需要进行delete
  94.             //delete pMyExcepction;
  95.         }
  96.         catch ( MyExcepction myExcepction)
  97.         {
  98.             // 输出本语句被执行信息
  99.             std::cout << “执行了 catch ( MyExcepction myExcepction) ” << std::endl;
  100.             // 输出错误信息
  101.             std::cout << “error Code : ” << myExcepction.getErrorId()<< std::endl;
  102.         }
  103.         catch(…)
  104.         {
  105.              // 输出本语句被执行信息
  106.              std::cout << “执行了 catch(…) ” << std::endl;
  107.              // 处理不了,重新抛出给上级
  108.              throw ;
  109.         }
  110.         // 暂停
  111.         int temp;
  112.         std::cin >> temp;
  113.        return 0;
  114. }

知识点: c++异常机制
一、 概述
C++自身有着非常强的纠错能力,发展到如今,已经建立了比较完善的异常处理机制。C++的异常情况无非两种,一种是语法错误,即程序中出现了错误的语句,函数,结构和类,致使编译程序无法进行。另一种是运行时发生的错误,一般与算法有关。
关于语法错误,不必多说,写代码时心细一点就可以解决。C++编译器的报错机制可以让我们轻松地解决这些错误。
第二种是运行时的错误,常见的有文件打开失败、数组下标溢出、系统内存不足等等。而一旦出现这些问题,引发算法失效、程序运行时无故停止等故障也是常有的。这就要求我们在设计软件算法时要全面。比如针对文件打开失败的情况,保护的方法有很多种,最简单的就是使用“return”命令,告诉上层调用者函数执行失败;另外一种处理策略就是利用c++的异常机制,抛出异常。
二、c++异常处理机制
C++异常处理机制是一个用来有效地处理运行错误的非常强大且灵活的工具,它提供了更多的弹性、安全性和稳固性,克服了传统方法所带来的问题.
异常的抛出和处理主要使用了以下三个关键字: try、 throw 、 catch 。
抛出异常即检测是否产生异常,在C++中,其采用throw语句来实现,如果检测到产生异常,则抛出异常。该语句的格式为:
throw 表达式;
如果在try语句块的程序段中(包括在其中调用的函数)发现了异常,且抛弃了该异常,则这个异常就可以被try语句块后的某个catch语句所捕获并处理,捕获和处理的条件是被抛弃的异常的类型与catch语句的异常类型相匹配。由于C++使用数据类型来区分不同的异常,因此在判断异常时,throw语句中的表达式的值就没有实际意义,而表达式的类型就特别重要。
try-catch语句形式如下 :

  1. try
  2. {
  3.         包含可能抛出异常的语句;
  4. }
  5. catch(类型名 [形参名]) // 捕获特定类型的异常
  6. {
  7. }
  8. catch(类型名 [形参名]) // 捕获特定类型的异常
  9. {
  10. }
  11. catch(…)    // 三个点则表示捕获所有类型的异常
  12. {
  13. }

【范例1】处理除数为0的异常。该范例将上述除数为0的异常可以用try/catch语句来捕获异常,并使用throw语句来抛出异常,从而实现异常处理,实现代码如代码清单1-1所示。
// 代码清单1-1

  1. #include<iostream.h>     //包含头文件
  2. #include<stdlib.h>
  3. double fuc(double x, double y) //定义函数
  4. {
  5.     if(y==0)
  6.     {
  7.         throw y;     //除数为0,抛出异常
  8.     }
  9.     return x/y;     //否则返回两个数的商
  10. }
  11. void main()
  12. {
  13.     double res;
  14.     try  //定义异常
  15.     {
  16.         res=fuc(2,3);
  17.         cout<<“The result of x/y is : “<<res<<endl;
  18.         res=fuc(4,0); 出现异常,函数内部会抛出异常
  19.     }
  20.     catch(double)             //捕获并处理异常
  21.     {
  22.          cerr<<“error of dividing zero.n”;
  23.          exit(1);                //异常退出程序
  24.     }
  25. }
【范例2】自定义异常类型 (在本文开始的代码中已经给出示范)
三、异常的接口声明
为了加强程序的可读性,使函数的用户能够方便地知道所使用的函数会抛出哪些异常,可以在函数的声明中列出这个函数可能抛出的所有异常类型,例如:

void fun() throw( A,B,C,D);

这表明函数fun()可能并且只可能抛出类型(A,B,C,D)及其子类型的异常。
如果在函数的声明中没有包括异常的接口声明,则此函数可以抛出任何类型的异常,例如:

void fun();

一个不会抛出任何类型异常的函数可以进行如下形式的声明:

void fun() thow();

五、异常处理中需要注意的问题
1. 如果抛出的异常一直没有函数捕获(catch),则会一直上传到c++运行系统那里,导致整个程序的终止
2. 一般在异常抛出后资源可以正常被释放,但注意如果在类的构造函数中抛出异常,系统是不会调用它的析构函数的,处理方法是:如果在构造函数中要抛出异常,则在抛出前要记得删除申请的资源。
3. 异常处理仅仅通过类型而不是通过值来匹配的,所以catch块的参数可以没有参数名称,只需要参数类型。
4. 函数原型中的异常说明要与实现中的异常说明一致,否则容易引起异常冲突。
5. 应该在throw语句后写上异常对象时,throw先通过Copy构造函数构造一个新对象,再把该新对象传递给 catch.
那么当异常抛出后新对象如何释放?
异常处理机制保证:异常抛出的新对象并非创建在函数栈上,而是创建在专用的异常栈上,因此它才可以跨接多个函数而传递到上层,否则在栈清空的过程中就会被销毁。所有从try到throw语句之间构造起来的对象的析构函数将被自动调用。但如果一直上溯到main函数后还没有找到匹配的catch块,那么系统调用terminate()终止整个程序,这种情况下不能保证所有局部对象会被正确地销毁。
6. catch块的参数推荐采用地址传递而不是值传递,不仅可以提高效率,还可以利用对象的多态性。另外,派生类的异常扑获要放到父类异常扑获的前面,否则,派生类的异常无法被扑获。
7. 编写异常说明时,要确保派生类成员函数的异常说明和基类成员函数的异常说明一致,即派生类改写的虚函数的异常说明至少要和对应的基类虚函数的异常说明相同,甚至更加严格,更特殊。

Categories
不学无术

HDOJ-1097 A hard puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 23989    Accepted Submission(s): 8466

Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.
this puzzle describes that: gave a and b,how to know the a^b’s the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.

 

Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)

 

Output
For each test case, you should output the a^b’s last digit number.

 

Sample Input
7 66 8 800

 

Sample Output
9 6

==========================================
死搞肯定是要超时的….
其实一共9个数字,乘方都是有规律的..写的丑陋了点,不过能用就好^^

#include 
#include 
using namespace std;
const int BUFFER_LENGTH = 31;
const int pattern_size[] = {1, 1, 4, 4, 2, 1, 1, 4, 4, 2};
const int pattern_0[] = {0};
const int pattern_1[] = {1};
const int pattern_2[] = {2, 4, 8, 6};
const int pattern_3[] = {3, 9, 7, 1};
const int pattern_4[] = {4, 6};
const int pattern_5[] = {5};
const int pattern_6[] = {6};
const int pattern_7[] = {7, 9, 3, 1};
const int pattern_8[] = {8, 4, 2, 6};
const int pattern_9[] = {9, 1};
int main()
{
	char a[BUFFER_LENGTH];
	long long b;
	while(cin >> a >> b)
	{
		int len_a = strlen(a);
		int last_digit = a[len_a-1] - 0x30;
		int result;
		b--;
		switch(last_digit)
		{
		case 0:
			result = pattern_0[b%pattern_size[0]];
			break;
		case 1:
			result = pattern_1[b%pattern_size[1]];
			break;
		case 2:
			result = pattern_2[b%pattern_size[2]];
			break;
		case 3:
			result = pattern_3[b%pattern_size[3]];
			break;
		case 4:
			result = pattern_4[b%pattern_size[4]];
			break;
		case 5:
			result = pattern_5[b%pattern_size[5]];
			break;
		case 6:
			result = pattern_6[b%pattern_size[6]];
			break;
		case 7:
			result = pattern_7[b%pattern_size[7]];
			break;
		case 8:
			result = pattern_8[b%pattern_size[8]];
			break;
		case 9:
			result = pattern_9[b%pattern_size[9]];
			break;
		default:
			result = -1;
		}
		cout << result << endl;
	}
	return 0;
}