| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
让你们见识一下傻瓜菜鸟怎么用STL昏头昏脑一次A的吧#include <iostream>
#include <deque>
#include <set>
#include <string>
using namespace std;
int main()
{
int a,b,c,i,j,x,y,g;
string aa;
cin>>a>>b>>c;
set<pair<int,int>> foll;
deque<pair<string,pair<int,pair<int,int> > > > coll;
coll.push_back(make_pair("01",make_pair(1,make_pair(a,0))));
coll.push_back(make_pair("02",make_pair(1,make_pair(0,b))));
foll.insert(make_pair(a,0));
foll.insert(make_pair(0,b));
while(!coll.empty())
{
aa=coll.front().first;
x=coll.front().second.second.first;
y=coll.front().second.second.second;
g=coll.front().second.first;
coll.pop_front();
if (x==c || y==c)
break;
if (x<a && foll.find(make_pair(a,y))==foll.end())//装满1
{
coll.push_back(make_pair(aa+"01",make_pair(g+1,make_pair(a,y))));
foll.insert(make_pair(a,y));
}
if (x)
{
if (foll.find(make_pair(0,y))==foll.end())//倒掉1
{
coll.push_back(make_pair(aa+"11",make_pair(g+1,make_pair(0,y))));
foll.insert(make_pair(0,y));
}
//1倒入2
i=x-b+y;
if (i<0)
i=0;
j=y+x;
if (j>b)
j=b;
if (foll.find(make_pair(i,j))==foll.end())
{
coll.push_back(make_pair(aa+"21",make_pair(g+1,make_pair(i,j))));
foll.insert(make_pair(i,j));
}
}
if (y)
{
if (foll.find(make_pair(x,0))==foll.end())
{
coll.push_back(make_pair(aa+"12",make_pair(g+1,make_pair(x,0))));
foll.insert(make_pair(x,0));
}
j=y-a+x;
if (j<0)
j=0;
i=x+y;
if (i>a)
i=a;
if (foll.find(make_pair(i,j))==foll.end())
{
coll.push_back(make_pair(aa+"22",make_pair(g+1,make_pair(i,j))));
foll.insert(make_pair(i,j));
}
}
if (y<b && foll.find(make_pair(x,b))==foll.end())
{
coll.push_back(make_pair(aa+"02",make_pair(g+1,make_pair(x,b))));
foll.insert(make_pair(x,b));
}
g=-1;
}
if (g==-1)
cout<<"impossible"<<endl;
else
{
cout<<g<<endl;
c=aa.length();
for (i=0;i<c;i+=2)
{
if (aa[i]=='0')
cout<<"FILL("<<aa[i+1]<<')'<<endl;
else
if (aa[i]=='1')
cout<<"DROP("<<aa[i+1]<<')'<<endl;
else
cout<<"POUR("<<aa[i+1]<<','<<char(99-aa[i+1])<<')'<<endl;
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator