我住包子山

this->blog.MoveTo("blog.baozishan.in")

#

pku3297解题报告

这道题我用的方法很麻烦,使用一个结构体vector保存结果,使用一个map判断是不是一个人报了两个工程.使用set判断一个工程是不是有人重复报名
于是就有了下面的笨拙代码

 1#include <string>
 2#include <set>
 3#include <vector>
 4#include <memory.h>
 5#include <map>
 6#include <algorithm>
 7using namespace std;
 8
 9struct Project
10{
11    string name;
12    int studentcount;
13    Project()
14    {
15        studentcount=0;
16        name.assign("");
17    }

18}
;
19
20map<string,int> studentmap;
21set<string> studentset;
22vector<Project> prov;
23int countarray[101]={0};
24char strtemp[100]="";
25Project project;
26
27inline bool comp(const Project &p1,const Project &p2)
28{
29    return p1.studentcount>p2.studentcount;
30}

31inline bool comp2(const Project &p1,const Project &p2)
32{
33    return p1.name.compare(p2.name)<0;
34}

35
36int main()
37{
38    
39    while(true)
40    {
41        int projcount=0;
42        prov.push_back(project);
43        while(true)
44        {
45            gets(strtemp);
46            project.name.assign(strtemp);
47            if(project.name[0]=='1')break;
48            if(project.name[0]=='0')exit(0);
49            if(project.name[0]>='A'&&project.name[0]<='Z')
50            {
51                prov.push_back(project);
52                studentset.clear();
53                projcount++;
54            }

55            if(project.name[0]>='a'&&project.name[0]<='z')
56            {
57                if(studentmap[strtemp]==0)
58                {
59                    studentmap[strtemp]=projcount;
60                }

61                else if(studentmap[strtemp]==-1)
62                {
63                    continue;
64                }

65                else if(studentmap[strtemp]!=projcount)
66                {
67                    prov[studentmap[strtemp]].studentcount--;
68                    studentmap[strtemp]=-1;
69                    continue;
70                }

71                if(studentset.count(strtemp))
72                    continue;
73                else
74                {
75                    studentset.insert(strtemp);
76                    prov[projcount].studentcount++;
77                }

78            }
                        
79        }

80        prov.erase(prov.begin());
81        stable_sort(prov.begin(),prov.end(),comp2);
82        stable_sort(prov.begin(),prov.end(),comp);
83        for(int i=0;i<prov.size();i++)
84        {
85            printf("%s %d\n",prov[i].name.c_str(),prov[i].studentcount);
86        }

87        memset(countarray,0,sizeof(countarray));
88        studentmap.clear();
89        prov.clear();
90        
91    }

92}

93
94

posted @ 2007-07-28 16:37 Gohan 阅读(357) | 评论 (0)编辑 收藏

pku 3286解题报告

我的做法可能很弱智
给定一个数x>0算通过每一位零出现次数的统计,算出所有的0的次数(从1到X)

举一个例子
2508这个数
首先考虑个位数
250X  X=0;一共有250-1+1个
25X8  X=0;一共有258-10+1个
2X08 X=0;注意并不只有208-100+1中可能,我之前就错在这里了,因为最大2508,所以2099-2009这百位的零我就没有考虑到,所以这里的0有299-100+1个

于是题目就做出来了

输入一个a b
a<b
a==0时
b统计出零的个数然后加1(0)的个数
否则从a 到 b的0的个数则是从1到b的0个数减去从1到a-1的零的个数
a<10的情况我害怕出错就分开写了,所以整个程序有些长

下面就是我笨拙的代码

 1#include <iostream>
 2#include <string>
 3#include <cstdio>
 4#include <cstdlib>
 5#include <cmath>
 6using namespace std;
 7long long aarray[10]={0};
 8long long barray[10]={0};
 9long long diff[10]={0};
10char tempstr[10= "";
11
12
13int calc(std::string str,int i)
14{
15    //str.erase()
16    if(i==(str.size()-1)) return 0;
17    long long sum=0,len=str.size();
18    int needminus = int(pow(10.0,i));
19    //if(i!=0)str[len-i-2]+=(str[len-i-1]-'0');//new add
20    if(str[len-i-1]=='0')
21    {
22    str.erase(len-i-1,1);
23    }

24    else
25    {
26        str.erase(len-i-1,i+1);
27        str.append(i,'9');
28    }

29    for(int i=0;i<str.size();i++)
30    {
31        sum=sum*10+(str[i]-'0');
32    }

33    sum-=needminus;
34    sum+=1;
35    return sum;
36}

37
38int main()
39{
40    unsigned int a,b;
41    std::string tempstring;
42    int add;
43    while(scanf("%u %u",&a,&b))
44    {
45        add=0;
46
47        if(a==0)
48            add=1;
49        else {
50            add=0;
51            a--;
52        }

53        if(a==-2)
54            break;
55        int alen,blen;
56        if(a<10)
57        {
58            aarray[0]=0;
59        }

60        else
61        {
62            _i64toa(a,tempstr,10);
63            alen = strlen(tempstr);
64            tempstring.assign(tempstr);
65            for(int i=0;i<alen;i++)
66            {
67                aarray[i]=calc(tempstring,i);
68            }

69        }

70        _i64toa(b,tempstr,10);
71        blen = strlen(tempstr);
72        tempstring.assign(tempstr);
73        for(int i=0;i<blen;i++)
74        {
75            barray[i]=calc(tempstring,i);
76        }

77        for(int i=0;i<blen;i++)
78        {
79            diff[i]=barray[i]-aarray[i];
80        }

81        long long sum=0;
82        for(int i=0;i<blen;i++)
83        {
84            sum+=diff[i];
85        }

86        
87        cout<<sum+add<<endl;
88        memset(aarray,0,sizeof(long long)*10);
89        memset(barray,0,sizeof(long long)*10);
90        memset(diff,0,sizeof(long long)*10);
91    }

92}


 

posted @ 2007-07-25 08:20 Gohan 阅读(571) | 评论 (0)编辑 收藏

在家的一周

基本没做什么
喝光了一箱健力宝,吃掉了许多娃娃脸,吃了几次羊,对travian这个网页游戏做了提供辅助的可行性测试,借此了解更多了些webbrowswer控件及其周边,同学什么都没怎么见,唉,估计只能等到寒假了...
回到学校,争取这周给辅助做的差不多,别的也不能落下...

posted @ 2007-07-18 07:45 Gohan 阅读(214) | 评论 (0)编辑 收藏

又买了本书

...
99块


太懒了.看书有如在堆栈,都快满栈了...

posted @ 2007-07-09 23:08 Gohan 阅读(162) | 评论 (0)编辑 收藏

今天发现vs2005fstream不能用中文路径

具体解决如下

vs2005 fstream 不能打开中文路径名文件的问题!

http://www.cppblog.com/danoyang/archive/2006/05/23/7523.html

fstream 和 中文路径
http://www.cppblog.com/mythma/archive/2006/06/09/8349.html


Trackback: http://www.cppblog.com/danoyang/services/trackbacks/7523.aspx
Trackback: http://www.cppblog.com/mythma/services/trackbacks/8349.aspx

posted @ 2007-06-19 00:19 Gohan 阅读(232) | 评论 (0)编辑 收藏

I'm Gohan

假期打算根据那本Mud Programming模仿着写个mud..

posted @ 2007-06-07 10:41 Gohan 阅读(195) | 评论 (0)编辑 收藏

SubclassWindow 一个函数,其实是个宏

#define     SubclassWindow(hwnd, lpfn)       \
              ((WNDPROC)SetWindowLongPtr((hwnd), GWLP_WNDPROC, (LPARAM)(WNDPROC)(lpfn)))

这个宏是我看第七章winshellprograming看到的,很强大的功能,例子是用FindWindowEx找到windows开始按钮的窗口句柄,之后用该宏加入开始按钮的消息处理函数.总之还不错,winshell还真不是一般..
MSDN上查SubclassWindow都不是我要的这个,虽然功能大体相同吧.
下面这个就是SetWindowLongPtr函数:
SetWindowLongPtr Function

The SetWindowLongPtr function changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory.

这个函数改变一个指定窗口的一个属性.它也可设定窗口储存区指定偏移位置的值。

This function supersedes the SetWindowLong function. To write code that is compatible with both 32-bit and 64-bit versions of Microsoft Windows, use SetWindowLongPtr.
这个函数取代了SetWindowLong函数,为了兼容32位64位windows os,就用这个函数吧 .

Syntax

LONG_PTR SetWindowLongPtr(      
    HWND hWnd,
    int nIndex,
    LONG_PTR dwNewLong
);

Parameters

hWnd
[in] Handle to the window and, indirectly, the class to which the window belongs. The SetWindowLongPtr function fails if the process that owns the window specified by the hWnd parameter is at a higher process privilege in the User Interface Privilege Isolation (UIPI) hierarchy than the process the calling thread resides in.
返回fail当拥有指定窗口的京城比用户UI权限隔绝(??)高的时候..不知道翻译对不

Microsoft Windows XP and earlier: The SetWindowLongPtr function fails if the window specified by the hWnd parameter does not belong to the same process as the calling thread.

这个意思大概是函数失败如果调用进程传入的hWnd句柄不属于调用包含这个函数的线程的进程(应用程序).

nIndex
[in] Specifies the zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus the size of an integer. To set any other value, specify one of the following values.
这个不用翻译了,很明了哈哈
GWL_EXSTYLE
Sets a new extended window style. For more information, see CreateWindowEx.
GWL_STYLE
Sets a new window style.
GWLP_WNDPROC
Sets a new address for the window procedure.
GWLP_HINSTANCE
Sets a new application instance handle.
GWLP_ID
Sets a new identifier of the window.
GWLP_USERDATA
Sets the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero.
The following values are also available when the hWnd parameter identifies a dialog box.
DWLP_DLGPROC
Sets the new pointer to the dialog box procedure.
DWLP_MSGRESULT
Sets the return value of a message processed in the dialog box procedure.
DWLP_USER
Sets new extra information that is private to the application, such as handles or pointers.
dwNewLong
[in] Specifies the replacement value.

Return Value

If the function succeeds, the return value is the previous value of the specified offset.
成功返回的是设置前的值LONG_PTR这个类型

If the function fails, the return value is zero. To get extended error information, call GetLastError.

If the previous value is zero and the function succeeds, the return value is zero, but the function does not clear the last error information. To determine success or failure, clear the last error information by calling SetLastError(0), then call SetWindowLongPtr. Function failure will be indicated by a return value of zero and a GetLastError result that is nonzero.


Remarks

Certain window data is cached, so changes you make using SetWindowLongPtr will not take effect until you call the SetWindowPos function.

If you use SetWindowLongPtr with the GWLP_WNDPROC index to replace the window procedure, the window procedure must conform to the guidelines specified in the description of the WindowProc callback function.

If you use SetWindowLongPtr with the DWLP_MSGRESULT index to set the return value for a message processed by a dialog box procedure, the dialog box procedure should return TRUE directly afterward. Otherwise, if you call any function that results in your dialog box procedure receiving a window message, the nested window message could overwrite the return value you set by using DWLP_MSGRESULT.

Calling SetWindowLongPtr with the GWLP_WNDPROC index creates a subclass of the window class used to create the window. An application can subclass a system class, but should not subclass a window class created by another process. The SetWindowLongPtr function creates the window subclass by changing the window procedure associated with a particular window class, causing the system to call the new window procedure instead of the previous one. An application must pass any messages not processed by the new window procedure to the previous window procedure by calling CallWindowProc. This allows the application to create a chain of window procedures.

Reserve extra window memory by specifying a nonzero value in the cbWndExtra member of the WNDCLASSEX structure used with the RegisterClassEx function.

Do not call SetWindowLongPtr with the GWLP_HWNDPARENT index to change the parent of a child window. Instead, use the SetParent function.

If the window has a class style of CS_CLASSDC or CS_PARENTDC, do not set the extended window styles WS_EX_COMPOSITED or WS_EX_LAYERED.

Windows XP/Vista: Calling SetWindowLongPtr to set the style on a progressbar will reset its position.

Function Information



先到这里,以后会写更多Win32的基础知识,当我学到的时候..

btw,有本叫the old new thing 似乎很强,不知道什么时候能有一本...

posted @ 2007-06-03 00:26 Gohan 阅读(4085) | 评论 (2)编辑 收藏

一个小练习,帮人做 (a^n)%k

输入a,n,k(1<=a,n<=1e9   1<=k<=10000 ,注意:有多组测试数据,请用EOF标志判断结束输入):
2 32 5
2 30 5

输出(a^n)%k的结果(a的n次方被k除的余数):
输入a,n,k(1<=a,n<=1e9   1<=k<=10000 ,注意:有多组测试数据,请用EOF标志判断结束输入):
2 32 5
2 30 5

输出(a^n)%k的结果(a的n次方被k除的余数):
要求复杂度为O(logn)

解决思路,吃屎兄的推导的
(a*b)Mod c=((a Mod c)*b)Mod c
a^b Mod c  把B写成二进制(At ,At-1,At-2...A1,A0)
a^b Mod c =(a^(At*2^t....A0*2^0)mod c)=

((a^A0*2^0 mod c)*a^A1*2^1mod c).....
t=log2B;

下面是小弟的程序

#include <iostream>
using namespace std;
int convertToBin(int n,int (&arr)[14])
{
    
int i=0;
    
while(n)
    
{
        arr[i]
=n%2;
        n
=n/2;
        i
++;
    }

    
return i;
}

int findAnswer(int k,int a,int arr[14],int bsize)
{
    
int ret = 1;
    
for(int i=0;i<bsize;i++)
    
{
        
if(arr[i])
            ret
=(ret*a*(1<<i))%k;
        
else
            ret
=(ret*(1<<i))%k;
    }

    
return ret;
}

int main()
{
    
int a,n,k=1;
    
while(!cin.eof())
    
{
        cin
>>a;
            
if(a==-1break;
        cin
>>n>>k;
        
int arr[14]={0};
        
int bsize = convertToBin(n,arr);
        cout
<<findAnswer(k,a,arr,bsize)<<endl;
    }

}

posted @ 2007-06-01 22:49 Gohan 阅读(255) | 评论 (0)编辑 收藏

一些关于Win32 Programming的体会--读毕第6章WindowsShellProgramming

这章用到比较多的两个接口
IShellLink IPersistFile
两个COM接口,一个ShellLink提供对于快捷方式信息存取的方法,但是如果要载入或保存快捷方式,需要通过ShellLink Query一个IPersistFile接口,使用IPersistFile的载入保存方法.
贴载入与读取的这段

 1WCHAR wszLnkFile[MAX_PATH] = {0};
 2IShellLink* pShellLink = NULL;
 3   IPersistFile* pPF = NULL;
 4
 5   // Create the appropriate COM server
 6   HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL,
 7                                 CLSCTX_INPROC_SERVER, IID_IShellLink,
 8                                 reinterpret_cast<LPVOID*>(&pShellLink));
 9   if(FAILED(hr))
10      return hr;
11
12   // Get the IPersistFile interface to load the LNK file
13   hr = pShellLink->QueryInterface(IID_IPersistFile, reinterpret_cast<LPVOID*>(&pPF));
14   if(FAILED(hr))
15   {
16      pShellLink->Release();
17      return hr;
18   }

19 MultiByteToWideChar(CP_ACP, 0, szLnkFile, -1, wszLnkFile, MAX_PATH);
20   hr = pPF->Load(wszLnkFile, STGM_READ);
21   if(FAILED(hr))
22   {
23      pPF->Release();
24      pShellLink->Release();
25      return hr;
26   }

27
28   //现在可以用pShellLink了
29  hr = pPF->Save(wszLnkFile, TRUE);
30
31   // Clean up
32   pPF->Release();
33   pShellLink->Release();
34

下面这段是一个Drag的例子
 WindowFromPoint(pt)感觉很强,可以获取pt点(屏幕坐标系)的窗体对象
DragQueryFile来分析hDrop
hDrop是WM_DROPFILES事件的(wParam)参数,类型为HDROP
一般都用reinterpret_cast转换

      POINT pt;
   DragQueryPoint(hDrop, 
&pt);
   ClientToScreen(hDlg, 
&pt);
   HWND hwndDrop 
= WindowFromPoint(pt);
   
if(hwndDrop != GetDlgItem(hDlg, IDC_VIEW))
   
{
      Msg(__TEXT(
"Sorry, you have to drop over the list view control!"));
      
return;
   }


   
// Now check the files
   int iNumOfFiles = DragQueryFile(hDrop, -1, NULL, 0);
   
for(int i = 0 ; i < iNumOfFiles; i++)
   
{
      TCHAR szFileName[MAX_PATH] 
= {0};
      DragQueryFile(hDrop, i, szFileName, MAX_PATH);
      
//获得了文件名,index为i的
   }


   DragFinish(hDrop);


posted @ 2007-05-27 00:50 Gohan 阅读(458) | 评论 (0)编辑 收藏

这两天看书体会

看 VC++Win Shell Programming

对win32 编程有点体会
了解了一些HIMAGELIST 这个win32结构
很多ImageList_XXX函数
还有就是IShellFolder这个接口
LPSHELLFOLDER
有很多SHXX函数用

今天来再更新一点

IShellFolder Interface 接口的成员


The IShellFolder interface is used to manage folders. It is exposed by all Shell namespace folder objects.

IShellFolder Members

BindToObject Retrieves an IShellFolder object for a subfolder.书上有讲
BindToStorage Requests a pointer to an object's storage interface.
CompareIDs Determines the relative order of two file objects or folders, given their item identifier lists.
CreateViewObject Requests an object that can be used to obtain information from or interact with a folder object.
EnumObjects Allows a client to determine the contents of a folder by creating an item identifier enumeration object and returning its IEnumIDList interface. The methods supported by that interface can then be used to enumerate the folder's contents.下面有IEnumIDList的成员
GetAttributesOf Retrieves the attributes of one or more file or folder objects contained in the object represented by IShellFolder.
GetDisplayNameOf Retrieves the display name for the specified file object or subfolder.
书上有讲
GetUIObjectOf Retrieves an OLE interface that can be used to carry out actions on the specified file objects or folders.书上有讲
ParseDisplayName Translates a file object's or folder's display name into an item identifier list.书上有讲
SetNameOf Sets the display name of a file object or subfolder, changing the item identifier in the process.

 

IEnumIDList Interface


The IEnumIDList interface provides a standard set of methods that can be used to enumerate the pointers to item identifier lists (PIDLs) of the items in a Shell folder. When a folder's IShellFolder::EnumObjects method is called, it creates an enumeration object and passes a pointer to the object's IEnumIDList interface back to the caller.

IEnumIDList Members

Clone Creates a new item enumeration object with the same contents and state as the current one.
Next Retrieves the specified number of item identifiers in the enumeration sequence and advances the current position by the number of items retrieved.
Reset Returns to the beginning of the enumeration sequence.
Skip Skips over the specified number of elements in the enumeration sequence.

posted @ 2007-05-20 01:14 Gohan 阅读(422) | 评论 (0)编辑 收藏

仅列出标题
共16页: First 8 9 10 11 12 13 14 15 16