博文

目前显示的是 五月, 2008的博文

sqlhelper使用模板

sqlhelper : 1 、 /// 执行一个不需要返回值的 SqlCommand 命令,通过指定专用的连接字符串。     /// 使用参数数组形式提供参数列表     /// </summary>     /// <remarks>     /// 使用示例:     /// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));     /// </remarks>     /// <param name="connectionString"> 一个有效的数据库连接字符串 </param>     /// <param name="commandType">SqlCommand 命令类型 ( 存储过程, T-SQL 语句, 等等。 )</param>     /// <param name="commandText"> 存储过程的名字或者 T-SQL 语句 </param>     /// <param name="commandParameters"> 以数组形式提供 SqlCommand 命令中用到的参数列表 </param> /// <returns> 返回一个数值表示此 SqlCommand 命令执行后影响的行数 </returns> 2 、 /// 执行一条返回结果集的 SqlCommand 命令,通过专用的连接字符串。     /// 使用参数数组提供参数     /// </summary>     /// <remarks>     /// 使用示例:     /// SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "

关于sqlhelper

必备: 在 sqlhelper.cs 文件中,添加: public static readonly string ConnectionStringLocalTransaction = ConfigurationManager .ConnectionStrings[ "pubsConnectionString" ].ConnectionString; 1 、执行 SQL 语句       string sql = TextBox1.Text;         SqlCommand cmd = new SqlCommand ();         // 定义对象资源保存的范围,一旦 using 范围结束,将释放对方所占的资源         using ( SqlConnection conn = new SqlConnection ( SqlHelper .ConnectionStringLocalTransaction))         {             // 打开连接             conn.Open();             // 调用执行方法,因为没有参数,所以最后一项直接设置为 null             SqlHelper .ExecuteNonQuery(conn, CommandType .Text, sql, null );                         Response.Write( "<font color=red> 操作完成!请检查数据库! </font>" );         } } 2 、 存储过程      SqlParameter myparm = new SqlParameter ();         // 获取参数的名字         myparm.ParameterName = txtparm.Text;         // 设置变量的类型和长度         myparm.SqlDbType = SqlDbType .NVarChar;         myparm.Size = 20;         // 获取参数的值         m

第四名,5道题,一等奖

图片
比赛终于结束了,我也要准备自己的考研了。 成绩不算好,也不算太坏。算是给自己的人生履历上又添了一笔吧。 加油!以后还有更重要的事情要做! 过两天,把这个东西总结一下 。 这张照片是比赛结束后的合影: 第二排 ,右边的第一个就是我.挨着的是张杰,然后是曹英存老师,孟亚飞,王伟杰,王亚

线段树题目 zju1610

[知识点 ] 线段树 1 。创建线段树 2 。对线段树着色 3 。作相关统计 1 。创建线段树     1 )取最小和最大的两个数作为端点,建立线段树     2 )当前节点的两个端点值之差等于一时,此时该节点即位叶子节点,不用再 向下分     3 )否则,分裂该节点为 [a , (a + b) / 2], [(a + b) / 2, b];       4 )创建线段树时,注意初始化操作 2 。线段树着色 (根据不同的题目此操作各不相同,对 zju_1610 做分析)     1 )当前节点的颜色与将要涂的颜色 color 相同,直接 return     2 )当前线段树节点的两个端点和要涂的两个端点正好都相同,则将该节点着为 color ,然后 return     3 )要涂的两个端点在当前节点的两个端点之间时:先将当前节点的颜色向其子节点扩展,然后:        1. 要涂的右端点小于或等于当前节点 middle = (a + b) / 2 时,向左子节点移动        2. 要涂的左端点大于或等于当前节点 middle = (a + b) / 2 时,向右子节点移动        3.else ( 1 , 2 ) 向左右子节点移动 3 。相关统计    1 )当前节点未着色或其颜色与要统计的颜色不相同,直接 return    2 )当前节点的颜色与要统计的颜色相同时: 看标记 p 是否和当前节点的左端点相同,若相同说明 此 区间在上次已经统计过,则可直接执p为当前节点的右端点,然后 return ( p 为标记已记录的有端点)/ *PS:这一条总结的不是很好!有点冗余,不妨这样: 从0——8000依次扫描,如果还是原来的数,即还是一条颜色,那么continue,不计,是其他颜色,many[t]++; 即:一次扫描全部统计!非常漂亮! */ 第一个线段树的代码:zju1610 #include<iostream> using namespace std; #define NOCOLOR -1 #define MUTILCOLOR -2 typedef struct seg { int color;//颜色 int ln; int rn;//线段范围 struct seg * left; struct

STL-MAP用法全讲

摘自: http://hi.baidu.com/listenprogram/blog/item/4ec67707b62b0bce7a8947a7.html 一.Map概述        Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。这里说下map内部数据的组织,map内部自建一颗红黑树(一种非严格意义上的平衡二叉树),这颗树具有对数据自动排序的功能,所以在map内部所有的数据都是有序的,后边我们会见识到有序的好处。        下面举例说明什么是一对一的数据映射。比如一个班级中,每个学生的学号跟他的姓名就存在着一一映射的关系,这个模型用map可能轻易描述,很明显学号用int描述,姓名用字符串描述(本篇文章中不用char *来描述字符串,而是采用STL中string来描述),下面给出map描述代码: Map<int, string> mapStudent; ----------------------------------------------------------------------------------------------------------------------------------- map的构造函数        map共提供了6个构造函数,这块涉及到内存分配器这些东西,略过不表,在下面我们将接触到一些map的构造方法,这里要说下的就是,我们通常用如下方法构造一个map: Map<int, string> mapStudent; ---------------------------------------------------------------------------------------------------------------------------------- 数据的插入        在构造map容器后,我们就可以往里面插入数据了。这里讲三种插入数据的方法:        第一种:用insert函数插入pair数据,下面举例说明(以下代码虽然是随手写的,应该可以在VC和GCC下编译通过,大家可以运

AC了30题,纪念一下--【附注】POJ 2351解题报告

这道题目,不用什么道具的话,一定WA,不过我在网上看了,一个程序,用二分法,也可以AC,并且时间也不多。赞~ 不过,我没有那个耐心,我感觉用Qsort已经足够快了。 因此,我用了MAP,因为对于MAP很盲,因此,就边学边用,效果不错,还实惠~呵呵。 对于MAP, 定义 : map<key_type,value> 名称; 插入 : map[]=value; 修改 : map[]=newvalue: map[]+=newvalue;//如果是数值的话 删除:我还没有用过,呵呵,暂且不表! 遍历 : 可以声明一个: map<key_type,value>::iterator iter; for(iter=名称,begin();iter!=名称.end();iter++) {依次访问iter:iter->first,iter->second;} 当然,还有许多高级的用法。暂且不谈 Source Code Problem: 2153 User: omycle Memory: 1908K Time: 3641MS Language: C++ Result: Accepted Source Code #pragma warning ( disable : 4786 ) #include <iostream> #include <string> #include <map> using namespace std ; int Count = 0 ; map < string , int > Score ; string p [ 10000 ]; void getstring ( char * st ) { int i = 0 ; while ( 1 ) { char ch ; ch = getchar (); if ( ch == ' \n ' ) break ; st [ i ]= ch ; i ++; } } void Read () { int n ; cin >> n ; int i = 0 ; Count = n ; getchar (); for ( i = 0 ; i < n ; i ++

VC中使用STL出现的警告.

当在使用STL时,VC有时会提出类似以下的警告: Compiling... test.cpp C:\Windows\Desktop\test\test.cpp(13) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std ::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/C4786.asp 给了很好的解释. 都是因为VC对STL的不完全支持造成的. 解决方法: #ifdef WIN32 #pragma warning (disable: 4514 4786) #endif

虽然AC,我依然困惑--【附注】POJ 2032解题报告

以后做题的时候,一定不要存在侥幸心理!根据题目情况,不要妄加猜测!!!一定一定,否则,耗时、耗力,还生气! 如果WA,好好读题,先检查容易出错的地方,换种思维去考虑,不要固执!!一定,一定!! 对于这个题目: 因为在DFS的时候,如果是'C',需要遍历两种情况: 那么对于这道题目,有两种方法 1、可以用for(int i=1;i<=2;i++) { if(i==1) {遍历一种情况} else if(i==2) {遍历另一种情况} } //这种方法被无数次的WA证明,是错误的 2、设置一个MARK数组,布尔型的,用于说明哪一页已经访问过了 if(!mark[]) {} if(!mark[]) {} //这种方法,不管是谁都认为正确。 我的困惑是第一种情况:为什么就WA呢?如果输入结果正确,而且,肯定有解的情况下。 Source Code Problem: 2023 User: omycle Memory: 288K Time: 0MS Language: C++ Result: Accepted Source Code #include <iostream> using namespace std ; bool mark [ 101 ]; int Totalpage ; int Total = 0 ; bool flag = false ; typedef struct { char type ; //C or E char juzi [ 260 ]; char end [ 10 ]; int page_1 ; int page_2 ; } Node ; Node node [ 101 ]; int Index [ 101 ]; void getstring ( char * st ) { bool flag = false ; getchar (); //把第一个空格过滤掉 for ( int i = 0 ;; i ++) { char ch = 0 ; ch = getchar (); if (! flag && ch == ' \" ' ) { i --; flag = true ; continue ; } if

这样,怎能不愤怒!--【附注】1129解题报告

换了一下,就AC了,其实还是WA! 原来WA的程序,是直接从原来具有的数值开始++,但毫无疑问,答案一定是正确的。 现在,是从1开始往上加,如果遇到相同的,继续加。 bool check ( int value , int i ) { int j = 2 ; while ( mg [ i ][ j ]!= 0 ) { if ( node [ mg [ i ][ j ]]. index == value ) return false ; j ++; } return true ; } 对于这道题目,我感觉有点愤愤的,就是偷懒了一下,就这样的后果么? Source Code Problem: 1129 User: omycle Memory: 256K Time: 0MS Language: C++ Result: Accepted Source Code #include <iostream> using namespace std ; int mg [ 30 ][ 30 ]; typedef struct { // int bz;//代表的含义 int index ; //代表分的channel } Channel ; int TotalCount = 0 ; Channel node [ 27 ]; void Init () { for ( int i = 1 ; i <= TotalCount ; i ++) { node [ i ]. index = 0 ; } } bool check ( int value , int i ) { int j = 2 ; while ( mg [ i ][ j ]!= 0 ) { if ( node [ mg [ i ][ j ]]. index == value ) return false ; j ++; } return true ; } void Bianli () { //初始情况i=0; for ( int i = 1 ; i <= TotalCount ; i ++) { if ( node [ i ]. index == 0 ) node [ i ]. index = 1 ; int j = 1 ; in