posts - 99,  comments - 8,  trackbacks - 0
 
response和request中的cookie用法http://shashoutian2005.blog.163.com/blog/static/16854152009619104557857/


什么是Cookies?Cookies是数据包,可以让网页具有记忆功能,在某台电脑上记忆一定的信息。Cookies的工作原理是,第一次由服务器端写入到客户端的系统中。以后每次访问这个网页,都是先由客户端将Cookies发送到服务器端,再由服务器端进行判断,然后再产生HTML代码返回给客户端,这是一个很重要的原理。关于服务器端和客户端的概念,请点击我写的这篇:什么是服务器端和客户端,举了2个实例。

Cookies在ASP中的最常用的方法,请做好笔记:

1.如何写入Cookies?
Response.Cookies("字段名")=变量或字符串,例如:
Response.Cookies("name2")="Dingdang"

2.如何设置Cookies时间?
Response.Cookies("字段名").expires=时间函数+N,例如:
Response.Cookies("name2").expires=date+1,表示Cookies保存1天,再比如:
Response.Cookies("name2").expires=Hour+8,表示Cookies保存8小时。

3.在以往的ASP教程中,很少有介绍Cookies退出的方法。在“退出”这个ASP页中可以这样写:
Response.Cookies("字段名")=""
之后,在客户端的浏览器就清除了Cookies,并且Cookies文件会消失。注意有多少个字段,就要写多少句来清除。

4.如何读取Cookies?
变量名=Request.Cookies("字段名"),例如:
name2=Request.Cookies("name2")
如果网页中写入<%=name2%>这句,则会显示“Dingdang”。
也可以这样直接读取Cookies,<%=Request.Cookies("name2")%>

Cookies是属于Session对象的一种。但有不同,Cookies不会占服务器资源;而“Session”则会占用服务器资源。所以,尽量不要使用Session,而使用Cookies
posted @ 2011-03-23 11:15 雪黛依梦 阅读(178) | 评论 (0)编辑 收藏

HTML 学习网站 http://www.zhongguosou.com/html/html_meta.html

http://www.chinahtml.com/0602/xhtml-11393917823377.html

posted @ 2011-03-21 21:17 雪黛依梦 阅读(137) | 评论 (0)编辑 收藏
Floyd-Warshall算法,简称Floyd算法,用于求解任意两点间的最短距离,时间复杂度为O(n^3)。我们平时所见的Floyd算法的一般形式如下:
1 void Floyd(){
2     int i,j,k;
3     for(k=1;k<=n;k++)
4         for(i=1;i<=n;i++)
5             for(j=1;j<=n;j++)
6                 if(dist[i][k]+dist[k][j]<dist[i][j])
7                     dist[i][j]=dist[i][k]+dist[k][j];
8 }

  注意下第6行这个地方,如果dist[i][k]或者dist[k][j]不存在,程序中用一个很大的数代替。最好写成if(dist[i][k]!=INF && dist[k][j]!=INF && dist[i][k]+dist[k][j]<dist[i][j]),从而防止溢出所造成的错误。
  上面这个形式的算法其实是Floyd算法的精简版,而真正的Floyd算法是一种基于DP(Dynamic Programming)的最短路径算法。
  设图G中n 个顶点的编号为1到n。令c [i, j, k]表示从i 到j 的最短路径的长度,其中k 表示该路径中的最大顶点,也就是说c[i,j,k]这条最短路径所通过的中间顶点最大不超过k。因此,如果G中包含边<i, j>,则c[i, j, 0] =边<i, j> 的长度;若i= j ,则c[i,j,0]=0;如果G中不包含边<i, j>,则c (i, j, 0)= +∞。c[i, j, n] 则是从i 到j 的最短路径的长度。
  对于任意的k>0,通过分析可以得到:中间顶点不超过k 的i 到j 的最短路径有两种可能:该路径含或不含中间顶点k。若不含,则该路径长度应为c[i, j, k-1],否则长度为 c[i, k, k-1] +c [k, j, k-1]。c[i, j, k]可取两者中的最小值。
  状态转移方程:c[i, j, k]=min{c[i, j, k-1], c [i, k, k-1]+c [k, j, k-1]},k>0。
  这样,问题便具有了最优子结构性质,可以用动态规划方法来求解。

  为了进一步理解,观察上面这个有向图:若k=0, 1, 2, 3,则c[1,3,k]= +∞;c[1,3,4]= 28;若k = 5, 6, 7,则c [1,3,k] = 10;若k=8, 9, 10,则c[1,3,k] = 9。因此1到3的最短路径长度为9。
  下面通过程序来分析这一DP过程,对应上面给出的有向图:

 

 1 #include <iostream>
 2 using namespace std;
 3 
 4 const int INF = 100000;
 5 int n=10,map[11][11],dist[11][11][11];
 6 void init(){
 7     int i,j;
 8     for(i=1;i<=n;i++)
 9         for(j=1;j<=n;j++)
10             map[i][j]=(i==j)?0:INF;
11     map[1][2]=2,map[1][4]=20,map[2][5]=1;
12     map[3][1]=3,map[4][3]=8,map[4][6]=6;
13     map[4][7]=4,map[5][3]=7,map[5][8]=3;
14     map[6][3]=1,map[7][8]=1,map[8][6]=2;
15     map[8][10]=2,map[9][7]=2,map[10][9]=1;
16 }
17 void floyd_dp(){
18     int i,j,k;
19     for(i=1;i<=n;i++)
20         for(j=1;j<=n;j++)
21             dist[i][j][0]=map[i][j];
22     for(k=1;k<=n;k++)
23         for(i=1;i<=n;i++)
24             for(j=1;j<=n;j++){
25                 dist[i][j][k]=dist[i][j][k-1];
26                 if(dist[i][k][k-1]+dist[k][j][k-1]<dist[i][j][k])
27                     dist[i][j][k]=dist[i][k][k-1]+dist[k][j][k-1];
28             }
29 }
30 int main(){
31     int k,u,v;
32     init();
33     floyd_dp();
34     while(cin>>u>>v,u||v){
35         for(k=0;k<=n;k++){
36             if(dist[u][v][k]==INF) cout<<"+∞"<<endl;
37             else cout<<dist[u][v][k]<<endl;
38         }
39     }
40     return 0;
41 }

  输入 1 3
  输出 +∞
            +∞
            +∞
            +∞
            28
            10
            10
            10
            9
            9
            9

  Floyd-Warshall算法不仅能求出任意2点间的最短路径,还可以保存最短路径上经过的节点。下面用精简版的Floyd算法实现这一过程,程序中的图依然对应上面的有向图。

 1 #include <iostream>
 2 using namespace std;
 3 
 4 const int INF = 100000;
 5 int n=10,path[11][11],dist[11][11],map[11][11];
 6 void init(){
 7     int i,j;
 8     for(i=1;i<=n;i++)
 9         for(j=1;j<=n;j++)
10             map[i][j]=(i==j)?0:INF;
11     map[1][2]=2,map[1][4]=20,map[2][5]=1;
12     map[3][1]=3,map[4][3]=8,map[4][6]=6;
13     map[4][7]=4,map[5][3]=7,map[5][8]=3;
14     map[6][3]=1,map[7][8]=1,map[8][6]=2;
15     map[8][10]=2,map[9][7]=2,map[10][9]=1;
16 }
17 void floyd(){
18     int i,j,k;
19     for(i=1;i<=n;i++)
20         for(j=1;j<=n;j++)
21             dist[i][j]=map[i][j],path[i][j]=0;
22     for(k=1;k<=n;k++)
23         for(i=1;i<=n;i++)
24             for(j=1;j<=n;j++)
25                 if(dist[i][k]+dist[k][j]<dist[i][j])
26                     dist[i][j]=dist[i][k]+dist[k][j],path[i][j]=k;
27 }
28 void output(int i,int j){
29     if(i==j) return;
30     if(path[i][j]==0) cout<<j<<' ';
31     else{
32         output(i,path[i][j]);
33         output(path[i][j],j);
34     }
35 }
36 int main(){
37     int u,v;
38     init();
39     floyd();
40     while(cin>>u>>v,u||v){
41         if(dist[u][v]==INF) cout<<"No path"<<endl;
42         else{
43             cout<<u<<' ';
44             output(u,v);
45             cout<<endl;
46         }
47     }
48     return 0;
49 }

  输入 1 3                    
  输出 1 2 5 8 6 3

posted @ 2011-03-10 16:37 雪黛依梦 阅读(12744) | 评论 (0)编辑 收藏
LCS
http://blog.sina.com.cn/s/blog_5368ef9a01009ll7.html
posted @ 2010-11-25 21:19 雪黛依梦 阅读(103) | 评论 (0)编辑 收藏
http://baike.baidu.com/taglist?tag=%CA%FD%BE%DD%BD%E1%B9%B9&tagfromview
posted @ 2010-11-11 21:00 雪黛依梦 阅读(118) | 评论 (0)编辑 收藏
http://www.cnblogs.com/DiaoCow/archive/2010/04/19/1715337.html

http://baiyun.me/category/acm/data-struct/trie-tree/

搜索字典项目的方法为:

         (1) 从根结点开始一次搜索;
  (2) 取得要查找关键词的第一个字母,并根据该字母选择对应的子树并转到该子树继续进行检索;  
     (3) 在相应的子树上,取得要查找关键词的第二个字母,并进一步选择对应的子树进行检索。   
        (4) 迭代过程……   
        (5) 在某个结点处,关键词的所有字母已被取出,则读取附在该结点上的信息,即完成查找。

posted @ 2010-11-11 20:39 雪黛依梦 阅读(299) | 评论 (0)编辑 收藏
//解题思路:求一个数最右边的一位数,即%10
//故:N^N 的最右边的一位数是( N^N ) % 10,根据同余定理= (N % 10)^N
//通过观察由 1 - 9的 N 次幂容易找出相应的规律,
#include <iostream>
#
include <algorithm>
using namespace std;
#include <stdlib.h>

int main ()
{
    int t;
    scanf (
"%d"&t);
    
while ( t -- )
    {
          int n, a;
          scanf (
"%d"&n);
          a 
= n % 10;
          
          
if ( a == 0 )
          printf (
"%d\n", 0);
          
          
else if ( a == 1 )
          printf (
"%d\n"1);
          
          
else if ( a == 5 )
          printf (
"%d\n"5);
          
          
else if ( a == 6 )
          printf (
"%d\n"6);
          
          
else if ( a == 2 )
          {
               
if ( n % 4 == 0 )
               printf (
"%d\n"6);
               
               
else if ( n % 4 == 1 )
               printf (
"%d\n"2);
               
               
else if ( n % 4 == 2 )
               printf (
"%d\n"4);
               
               
else if ( n % 4 == 3 )
               printf (
"%d\n"8);
          }
          
          
else if ( a == 3 )
          {
               
if ( n % 4 == 0 )
               printf (
"%d\n"1);
               
               
else if ( n % 4 == 1 )
               printf (
"%d\n"3);
               
               
else if ( n % 4 == 2 )
               printf (
"%d\n"9);
               
               
else if ( n % 4 == 3 )
               printf (
"%d\n"7);
          }
          
          
else if ( a == 4 )
          {
               
if ( n % 2 == 0 )
               printf (
"%d\n"6);
               
               
else if ( n % 2 == 1 )
               printf (
"%d\n"4);
          }
          
          
else if ( a == 7 )
          {
               
if ( n % 4 == 0 )
               printf (
"%d\n"1);
               
               
else if ( n % 4 == 1 )
               printf (
"%d\n"7);
               
               
else if ( n % 4 == 2 )
               printf (
"%d\n"9);
               
               
else if ( n % 4 == 3 )
               printf (
"%d\n"3);
          }
          
          
else if ( a == 8 )
          {
               
if ( n % 4 == 0 )
               printf (
"%d\n"6);
               
               
else if ( n % 4 == 1 )
               printf (
"%d\n"8);
               
               
else if ( n % 4 == 2 )
               printf (
"%d\n"4);
               
               
else if ( n % 4 == 3 )
               printf (
"%d\n"2);
          }
          
          
else if ( a == 9 )
          {
               
if ( n % 2 == 0 )
               printf (
"%d\n"1);
               
               
else if ( n % 2 == 1 )
               printf (
"%d\n"9);
          }
    }
   system (
"pause");
   
return 0;
}
posted @ 2010-09-11 22:00 雪黛依梦 阅读(506) | 评论 (0)编辑 收藏
//重在理解方法:每次找到最小的 2 3 5  7 的因子数,之后利用所存数的下标的关系改变 
#include <iostream>
using namespace std;

int num[5843];  //存储前5842个丑数 

int find_min ( int a, int b, int c, int d )
{
    int temp = a < b ? a : b;
    int index = c < d ? c : d;
    return temp < index ? temp : index;
}

void solve ( )
{
     int i1, i2, i3, i4, i;
     int h1, h2, h3, h4;
     i1 = i2 = i3 = i4 = 1;
     num[1] = 1;
     for (i = 2; i < 5843; i ++ )
     {
         h1 = num[i1] * 2;                   
         h2 = num[i2] * 3; 
         h3 = num[i3] * 5;
         h4 = num[i4] * 7;
         int min = find_min ( h1, h2, h3, h4 );
         
         num[i] = min;
         
         
         //易错点:这里不可以用else if 因为ti中可能会有相同的最小值,如当:min = 6 时 
         if ( min == h1 )
         i1 ++;
         
         if ( min == h2 )
         i2 ++;
         
         if ( min == h3 )
         i3 ++;
         
         if ( min == h4 )
         i4 ++;
     }
}

int main ()
{
    solve ();
    int n;
    while ( scanf ("%d", &n), n )
    {
          if ( n % 100 != 11 && n % 10 == 1 )
            printf ("The %dst humble number is %d.\n", n, num[n]);
          
          else if ( n % 100 != 12 && n % 10 == 2 )
            printf ("The %dnd humble number is %d.\n", n, num[n]);
          
          else if ( n % 100 != 13 && n % 10 == 3 )
            printf ("The %drd humble number is %d.\n", n, num[n]);
          
          else 
            printf ("The %dth humble number is %d.\n", n, num[n]);
    }
    //system ("pause");
    return 0;
}
posted @ 2010-09-11 20:56 雪黛依梦 阅读(543) | 评论 (0)编辑 收藏
一个水题可是错了好几次,原因就是在scanf    n   时输入的格式错了,应该是:%lf
//思路:首先是通过打表找到当长度取 0.01到5.20之间的数时,最多要多少张card,
//然后将张数存到length中用下表i表示张数 
#include <iostream>
#include <algorithm>
using namespace std;
#include <stdlib.h>

int main ()
{
    double length[300];
    memset ( length, 0, sizeof(length));
    for ( int i = 1; i <= 300; i ++)
    {
        for (int j = 1; j <= i; j ++)
        {
            length[i] += 1.0 / ( j + 1 );
        } 
        //printf ("%d %.2f\n", i, length[i]);
    }
    
    double n;
    while ( scanf ("%lf", &n) && n != 0.00 )
    {
          for ( int i = 1;i <= 300; i ++ )
          {
              if (  n <= length[i] )
              {
                    printf ("%d card(s)\n", i);
                    break;     
              } 
          }
    }
    system ("pause");
    return 0;
}
posted @ 2010-09-07 21:04 雪黛依梦 阅读(317) | 评论 (0)编辑 收藏
一水题也被我WA 了好几次哦!就是开头的那个必须是START
所以必须多加一个strcmp ( first, ''START'')
#include <iostream>
#
include <algorithm>
using namespace std;

int main ()
{
    char first[
11];
    char last[
8];
    char str[
201];
    
    
while (  scanf ("%s"&first) && strcmp( first, "EDNOFINPUT"&& !strcmp (first, "START") )
    {
         getchar ();
         int len 
= 0;
         
while ( (str[len] = getchar ()) != '\n')
         len 
++;
         
         
for ( int i = 0; i < len; i ++ )
         {
             
if ( str[i] >= 'A' && str[i] <= 'E'
             {
                  printf (
"%c", str[i] + 21);
             }
             
else if ( str[i] >= 'F' && str[i] <= 'Z')
             {
                  printf (
"%c", str[i] - 5);
             }
             
else
             printf (
"%c", str[i]);
         } 
         printf (
"\n");
         scanf (
"%s", last);
    }
   
//system ("pause");
   
return 0;
}
posted @ 2010-09-07 11:02 雪黛依梦 阅读(364) | 评论 (0)编辑 收藏
仅列出标题
共10页: 1 2 3 4 5 6 7 8 9 Last 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(4)

随笔分类

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜