2008年10月30日 星期四

ACM102 - Ecological Bin Packing


#include
#include
#include
#include
using namespace std;
class Q102
{
private:
map > bin;
map movecount;
unsigned int MoveCount(string bin1,string bin2,string bin3)
{
unsigned int movecount=0;
movecount+=bin[1][bin1]+bin[2][bin1];
movecount+=bin[0][bin2]+bin[2][bin2];
movecount+=bin[0][bin3]+bin[1][bin3];
return movecount;
}
void GetAllMoveCount()
{
movecount["BCG"]=MoveCount("B","C","G");
movecount["BGC"]=MoveCount("B","G","C");
movecount["CBG"]=MoveCount("C","B","G");
movecount["CGB"]=MoveCount("C","G","B");
movecount["GBC"]=MoveCount("G","B","C");
movecount["GCB"]=MoveCount("G","C","B");
}
public:
Q102()
{
for(int i=0;i<3;++i)
{
bin[i]["G"]=0;
bin[i]["B"]=0;
bin[i]["C"]=0;
}
}
void SetGlass(unsigned int b1,unsigned int g1,unsigned int c1,unsigned int b2,unsigned int g2,unsigned int c2,unsigned int b3,unsigned int g3,unsigned int c3)
{
bin[0]["B"]=b1;
bin[0]["G"]=g1;
bin[0]["C"]=c1;
bin[1]["B"]=b2;
bin[1]["G"]=g2;
bin[1]["C"]=c2;
bin[2]["B"]=b3;
bin[2]["G"]=g3;
bin[2]["C"]=c3;
}
void ShowMin()
{
GetAllMoveCount();
unsigned int min=movecount["BCG"];
string minlable="BCG";
for(map::iterator iter=movecount.begin();iter!=movecount.end();++iter)
{
if(iter->second < min)
{
min=iter->second;
minlable=iter->first;
}
}
cout << minlable << " " << min << endl;
}

};
int main(int argc, char *argv[])
{
Q102 q102;
unsigned int b1, g1,c1, b2,g2, c2, b3, g3, c3;
while(true)
{
cin >> b1 >> g1 >> c1 >> b2 >> g2 >> c2 >> b3 >> g3 >> c3;
if(cin.eof())
{
break;
}
q102.SetGlass(b1,g1,c1,b2,g2,c2,b3,g3,c3);
q102.ShowMin();
}
}

ACM101 The Blocks Problem


#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Q101
{
public:
map > thelist;
int _size;
void SetSize(int size)
{
_size=size;
for(int i=0;i<_size;++i)
{
thelist[i].clear();
thelist[i].push_back(i);
}
}

void Show()
{
for(int i=0;i<_size;++i)
{
cout << i << ":";

for(list::iterator iter=thelist[i].begin();iter!=thelist[i].end();++iter)
{
cout << " " << *iter;
}
cout << endl;
}
}

int Search(int n)
{
for(map>::iterator iter=thelist.begin();iter!=thelist.end();++iter)
{
for(list::iterator iter2=iter->second.begin();iter2!=iter->second.end();++iter2)
{
if(*iter2==n)
{
return iter->first;
}
}
}
return -1;

}

void ResetAfter(int n)
{
int index=Search(n);
while(thelist[index].back()!=n)
{
int temp=thelist[index].back();
thelist[index].pop_back();
thelist[temp].push_back(temp);
}
}

stack GetStack(int n)
{
stack s;
int index =Search(n);
while(thelist[index].back()!=n)
{
s.push(thelist[index].back());
thelist[index].pop_back();
}
s.push(thelist[index].back());
thelist[index].pop_back();
return s;
}
void moveonto(int a,int b)
{
if(a==b)
{
return;
}
int aat= Search(a);
int bat=Search(b);
if(aat==bat)
{
return;
}
ResetAfter(a);
ResetAfter(b);

thelist[aat].pop_back();
thelist[bat].push_back(a);
}
void moveover(int a,int b)
{
if(a==b)
{
return;
}
int aat= Search(a);
int bat=Search(b);
if(aat==bat)
{
return;
}
ResetAfter(a);
thelist[aat].remove(a);
thelist[bat].push_back(a);
}
void pileonto(int a,int b)
{
if(a==b)
{
return;
}
int aat= Search(a);
int bat=Search(b);
if(aat==bat)
{
return;
}
ResetAfter(b);
stack s=GetStack(a);
while(!s.empty())
{
thelist[bat].push_back(s.top());
s.pop();
}
}
void pileover(int a,int b)
{
if(a==b)
{
return;
}
int aat= Search(a);
int bat=Search(b);
if(aat==bat)
{
return;
}

stack s=GetStack(a);
while(!s.empty())
{
thelist[bat].push_back(s.top());
s.pop();
}
}
};
int main(int argc, char *argv[])
{
Q101 q101;
while(true)
{
int size;
cin >> size;
if(cin.eof())
{
break;
}
q101.SetSize(size);

while(true)
{
string cmd1,cmd2;
int a,b;
string input;
getline(cin,input);
istringstream ss;
ss.str(input);
ss >> cmd1;

if(cmd1=="quit")
{
q101.Show();
break;
}
ss >> a;
ss >> cmd2;
ss >> b;
if(cmd1=="move")
{
if(cmd2=="onto")
{
q101.moveonto(a,b);
}
else if(cmd2=="over")
{
q101.moveover(a,b);
}
}
else if(cmd1=="pile")
{
if(cmd2=="onto")
{
q101.pileonto(a,b);
}
else if(cmd2=="over")
{
q101.pileover(a,b);
}
}
}
}
}

ACM100: The 3n + 1 problem


#include
using namespace std;
class n3plus1
{

public:
int GetMaxCycle(int i,int j)
{
int max=0;
int temp;
for(;i<=j;++i)
{
temp=GetCycle(i,0);
max=temp>max?temp:max;
}
return max;
}
int GetCycle(int n,int temp)
{
++temp;
if(n==1)
{
return temp;
}
else if(n%2==0)
{
return GetCycle(n/2,temp);
}
else
{
return GetCycle(n*3+1,temp);
}
}
};
int main(int argc, char *argv[])
{

int m,n,max,min;
n3plus1 obj;
while(true)
{
cin >> m >> n;
if(cin.eof())
{
break;
}
max=m>n?m:n;
min=m cout << m << " " << n << " " << obj.GetMaxCycle(min,max) << endl;
}
}

ACM476: Points in Figures: Rectangles


#include
#include
#include
using namespace std;
class Point
{
public:
Point(float xx,float yy):x(xx) , y(yy){};
float x,y;

};
class Rectangle
{
public:
Point point1,point2;
Rectangle(float x1,float y1,float x2,float y2):point1(x1,y1),point2(x2,y2){};
bool IsIn(Point point)
{
return point.x > point1.x && point.x < point2.x && point.y < point1.y && point.y > point2.y;
}
};
class ACM476
{
public:
vector rectangles;
vector points;
};
int main(int argc, char *argv[])
{
ACM476 acm476;
while(true)
{
string input;
getline(cin,input);
istringstream ss;
ss.str(input);
string cmd;
float x1,y1,x2,y2;
ss >> cmd;
if(cmd=="*")
{
break;
}
switch(cmd[0])
{
case 'r':
ss >> x1;ss >> y1;ss >> x2;ss >> y2;
acm476.rectangles.push_back(Rectangle(x1,y1,x2,y2));
break;
}
}
while(true)
{
string input;
getline(cin,input);
istringstream ss;
ss.str(input);
float x,y;
ss >> x;
ss >> y;
if(x==9999.9f && y==9999.9f)
{
break;
}
acm476.points.push_back(Point(x,y));
}
for(vector::size_type ip =0;ip != acm476.points.size();++ip)
{
bool flag=false;
for(vector::size_type ir =0; ir != acm476.rectangles.size();++ir)
{
if(acm476.rectangles[ir].IsIn(acm476.points[ip]))
{
cout << "Point " << ip+1 << " is contained in figure " << ir+1 << endl;
flag=true;
}
}
if(!flag)
{
cout << "Point " << ip+1 <<" is not contained in any figure" << endl;
}

}
}

ACM458 - The Decoder

http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&page=show_problem&problem=399



#include
using namespace std;
int main(int argc, char *argv[])
{
string input;
int cmt;
int i;
while(true)
{
cin >> input;
if(cin.eof())
{
break;
}
cmt=input.size();
for(i=0;i < cmt;++i)
{
input[i]-=7;
}
cout << input << endl;
}
}

2008年10月12日 星期日

簡單的建立會員機制-建立新會員

Oracle Providers for ASP.NET 成員

OracleMembershipProvider

1.在Web.config加入以下內容

<?xml version="1.0"?>

<configuration xmlns=


  "http://schemas.microsoft.com/.NetConfiguration/v2.0">


  <connectionStrings>


    <add name="my_membership_app_con_string" connectionString=


      "User Id=scott;Password=tiger;Data Source=Oracle"/>


  </connectionStrings>


  <system.web>


    <!-- Enable and customize OracleMembershipProvider settings -->


    <membership defaultProvider="MyOracleMembershipProvider">


      <providers>


        <add name="MyOracleMembershipProvider"


             type="Oracle.Web.Security.OracleMembershipProvider,


             Oracle.Web, Version=2.111.6.20, Culture=neutral,


             PublicKeyToken=89b483f429c47342"


             connectionStringName="my_membership_app_con_string"


             applicationName="my_membership_app"


             enablePasswordRetrieval="false"


             enablePasswordReset="true"


             requiresQuestionAndAnswer="true"


             requiresUniqueEmail="true"


             passwordFormat="Hashed"


             maxInvalidPasswordAttempts="4"


             minRequiredPasswordLength="9"


             passwordAttemptWindow="8"/>


      </providers>


    </membership>


  </system.web>


</configuration>



2.從工具箱拖曳元件CreateUserWizard。並設定MembershipProvider屬性。



<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"

    MembershipProvider="MyOracleMembershipProvider">


    <WizardSteps>


        <asp:CreateUserWizardStep runat="server" />


        <asp:CompleteWizardStep runat="server" />


    </WizardSteps>


</asp:CreateUserWizard>



 



 



NewUser NewUser2



NewUserOK

Using OracleSessionStateProvider Web.config

Oracle Providers for ASP.NET 成員之一。

讓asp.net網站在做NLB的架構時將SessionState存放在Oracle裡。

NLB成員,只要有一台Server能提供服務。

網站都能繼續提供服務使用者的操作完全不會中斷 。

<?xml version="1.0"?>
<configuration xmlns=
  "http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <connectionStrings>
    <add name="my_sessionstate_app_con_string" connectionString=
      "User Id=scott;Password=tiger;Data Source=Oracle"/>
  </connectionStrings>
  <system.web>
    <!-- Enable and customize OracleSessionStateProvider -->
    <sessionState mode="Custom" customProvider="MyOracleSessionStateStore">
      <providers>
        <add name="MyOracleSessionStateStore"
             type="Oracle.Web.SessionState.OracleSessionStateStore,
             Oracle.Web, Version=2.111.6.20, Culture=neutral,
             PublicKeyToken=89b483f429c47342"
             connectionStringName="my_sessionstate_app_con_string"/>
      </providers>
    </sessionState>
  </system.web>
</configuration>

2008年10月5日 星期日

珍惜身邊不同的聲音

有機會和同事一起進行工作

當你的伙伴常常對自己的點子提出質疑的時候

是不是會覺得這個人怎麼那麼愛找麻煩呢?

在看到這個故事以後…

真的要好好珍惜這些常常跟自己唱反調的人

 

前些日子

是Google的十年慶

Google為此特別開了一個十年慶的網站

十週年慶

其中的第一個超連結

a11

就讓我呆住了快10秒鐘

我心裡在想當時他們是一個怎麼樣的心情呢?

「哇!真是太好了。跟這樣子的人一起工作。任何事情至少都可以用2種觀點去分析,可以達到互補的作用,真的是太好了。」

是不是這樣子呢?