Dain

写出一个可以工作的程序并不够

统计

留言簿

积分与排名

良师益友

阅读排行榜

评论排行榜

置顶随笔 #

[置顶]励志

师兄太强了,拿到了baidu、M$、Google的offer,可是实验室第一人啊,实在是admire
现在都说工作难找,不过只要努力,总会找到自己满意的,向师兄学习
我一定要努力啊

posted @ 2006-12-08 10:42 Dain 阅读(543) | 评论 (14)编辑 收藏

2008年9月18日 #

tate

posted @ 2008-09-18 19:58 Dain 阅读(12) | 评论 (0)编辑 收藏

2007年5月29日 #

Getting the Minimum and Maximum Values for a Numeric Type

Getting numeric limits

#include <iostream>
#include 
<limits>

using namespace std;

template
<typename T>
void showMinMax() {
   cout 
<< "min: " << numeric_limits<T>::min() << endl;
   cout 
<< "max: " << numeric_limits<T>::max() << endl;
   cout 
<< endl;
}


int main() {
   cout 
<< "short:" << endl;
   showMinMax
<short>();
   cout 
<< "int:" << endl;
   showMinMax
<int>();
   cout 
<< "long:" << endl;
   showMinMax
<long>();
   cout 
<< "long long:" << endl;
   showMinMax
<long long>();
   cout 
<< "float:" << endl;
   showMinMax
<float>();
   cout 
<< "double:" << endl;
   showMinMax
<double>();
   cout 
<< "long double:" << endl;
   showMinMax
<long double>();
   cout 
<< "unsigned short:" << endl;
   showMinMax
<unsigned short>();
   cout 
<< "unsigned int:" << endl;
   showMinMax
<unsigned int>();
   cout 
<< "unsigned long:" << endl;
   showMinMax
<unsigned long>();
   cout 
<< "unsigned long long:" << endl;
   showMinMax
<unsigned long long>();
}

posted @ 2007-05-29 10:38 Dain 阅读(418) | 评论 (2)编辑 收藏

2007年5月25日 #

3017

#include <stdio.h>
#include 
<stdlib.h>
#include 
<vector>

using namespace std;

struct Node 
{
    
int i,j;
    
int value;
}
;

long num[100000];
vector
<Node> matrix;

int main() {
    
long n;
    
long long m;
    scanf(
"%ld %lld",&n,&m);

    
long i,j;
    
for(i = 0;i < n;++i) {
        scanf(
"%ld",&num[i]);
    }


    
for(i = 0;i < n;++i) {
        
if(num[i] > m) {
            
break;
        }

    }


    
if(i < n) {
        printf(
"-1\n");

        
return 0;
    }


    
long long res = -1;
    
long long sum;
    
long max,min = 0;
    
for(i = 0;i < n;++i) {
        
if(i > 0{
            min 
= 1000000;
            
for(j = 0;j < matrix.size();++j) {
                
if(matrix[j].j == i - 1 && matrix[j].value < min) {
                    min 
= matrix[j].value;
                }

            }

        }

        
else {
            min 
= 0;
        }


        sum 
= 0;
        Node node;
        max 
= -1;
        
for(j = i;j < n;++j) {
            sum 
+= num[j];
            
if(sum <= m) {
                
if(max < num[j]) {                    
                    max 
= num[j];
                }

                node.i 
= i;
                node.j 
= j;
                node.value 
= max + min;
                matrix.push_back(node);
                
if(j == n - 1{
                    
if(res != -1{
                        
if(node.value < res) {
                            res 
= node.value;
                        }

                    }

                    
else {
                        res 
= node.value;
                    }

                }

            }

            
else {
                
break;
            }

        }

    }

    
    printf(
"%lld\n",res);

    
return 0;
}

posted @ 2007-05-25 10:06 Dain 阅读(66) | 评论 (0)编辑 收藏

3017

#include <stdio.h>
#include 
<stdlib.h>
#include 
<vector>

using namespace std;

struct Node 
{
    
int i,j;
    
int value;
}
;

long num[100000];
vector
<Node> matrix;

int main() {
    
long n;
    
long long m;
    scanf(
"%ld %lld",&n,&m);

    
long i,j;
    
for(i = 0;i < n;++i) {
        scanf(
"%ld",&num[i]);
    }


    
for(i = 0;i < n;++i) {
        
if(num[i] > m) {
            
break;
        }

    }


    
if(i < n) {
        printf(
"-1\n");

        
return 0;
    }


    
long long res = -1;
    
long long sum;
    
long max,min = 0;
    
for(i = 0;i < n;++i) {
        
if(i > 0{
            min 
= 1000000;
            
for(j = 0;j < matrix.size();++j) {
                
if(matrix[j].j == i - 1 && matrix[j].value < min) {
                    min 
= matrix[j].value;
                }

            }

        }

        
else {
            min 
= 0;
        }


        sum 
= 0;
        Node node;
        max 
= -1;
        
for(j = i;j < n;++j) {
            sum 
+= num[j];
            
if(sum <= m) {
                
if(max < num[j]) {                    
                    max 
= num[j];
                }

                node.i 
= i;
                node.j 
= j;
                node.value 
= max + min;
                matrix.push_back(node);
                
if(j == n - 1{
                    
if(res != -1{
                        
if(node.value < res) {
                            res 
= node.value;
                        }

                    }

                    
else {
                        res 
= node.value;
                    }

                }

            }

            
else {
                
break;
            }

        }

    }

    
    printf(
"%lld\n",res);

    
return 0;
}

posted @ 2007-05-25 10:06 Dain 阅读(75) | 评论 (0)编辑 收藏

2007年5月24日 #

不要再犯低级的错误

最近,总是犯非常低级的错误
看题不仔细
将j误写成k,而且怪的是,测试的例子都通过了,后来通过debug才找到了这个很低级的错误

真是气人啊

不要再犯了

posted @ 2007-05-24 13:56 Dain 阅读(62) | 评论 (0)编辑 收藏

2007年4月16日 #

列出所有9位数,它的前n位能被n整除

最简单的是穷举,不过那可要O(9*109),不可取 

#include <iostream>
#include 
<vector>
#include 
<algorithm>

using namespace std;

vector
<int> fun(int n)
{
    vector
<int> last,all;
    
int i,j,k;
    
for(i = 1;i < 10;++i)
        all.push_back(i);

    
if(n == 1)
        
return all;

    
int size;
    
int num;
    
for(i = 2;i <= n;++i)
    
{
        last 
= all;
        all.clear();
        size 
= (int)last.size();
        
for(j = 0;j < size;++j)
        
{
            
for(k = 0;k < 10;++k)