弄了一天,奄奄一息了,鬼火大哥,help!
鬼火狼烟吧
全部回复
仅看楼主
level 6
jacobzh 楼主
这是题目:Problem Statement    You want to send a group of salespeople from location 0 to location 1, but no two of them can travel through the same location (other than 0 and 1). This removes the possibility of trying to sell a customer the same product twice. Character j of element i (both 0-based) of adj denotes whether locations i and j are connected by a symmetric link ('1' for connected, '0' otherwise). Return the greatest number of salespeople that can be sent. The constraints will guarantee that locations 0 and 1 do not share a link.Definition    Class:SalesRoutingMethod:howManyParameters:vector
Returns:intMethod signature:int howMany(vector
adj)(be sure your method is public)    Constraints-adj will contain between 3 and 12 elements, inclusive.-Each element of adj will contain exactly N characters, where N is the number of elements in adj.-Each character in adj will be '0' (zero) or '1' (one).-Character i of element j of adj will be the same as character j of element i.-Character i of element i of adj will be '0'.-Character 1 of element 0 of adj will be '0'.Examples0)    {"001","001","110"}Returns: 1We can send a single salesperson from location 0 to location 2, and finally to location 1.1)    {"0010","0010","1100","0000"}Returns: 1Same as before, but now there is an isolated location 3.2)    {"001100","000001","100010","100010","001101","010010"}Returns: 1The only location that is directly connected to location 1 is 5, so only 1 salesperson can be sent.3)    {"001111","001111","110000","110000","110000","110000"}Returns: 44)    {"00000","00000","00000","00000","00000"}Returns: 0俺写了一段代码,下面是我的测试程序:#include
#include
#include
using namespace std;class SalesRouting{public:int howMany(vector
);private:int maxRout(int,vector
,vector
);//当前行,走过的行,源数据 };///int SalesRouting::howMany(vector
adj){string tem=adj[1];adj[1]=*adj.end();*adj.end()=tem;vector
routed;return maxRout(adj.size()-1,routed,adj);}///int SalesRouting::maxRout(int j,vector
routed,vector
adj){ int result=0;///存放结果 vector
::iterator it=routed.begin(),it_end=routed.end(); if(adj[j][0]=='1')result++;//如果能能通向0,则结果加1 for(int i=1;i
shiyan; shiyan.push_back("001111"); shiyan.push_back("001111"); shiyan.push_back("110000"); shiyan.push_back("110000"); shiyan.push_back("110000"); shiyan.push_back("110000"); cout<
2006年08月24日 09点08分 1
level 9
偶先瞅瞅呵呵
2006年08月24日 09点08分 2
level 9
这个不是欺负俺鸟语不行么。。。~
2006年08月24日 09点08分 3
level 9
IPSC的题目◎◎。。
2006年08月24日 10点08分 4
level 9
牛人啊,做这个题目
2006年08月24日 10点08分 5
level 9
给个解呵呵:#include
#include
#include
using namespace std;bool p[1<12][12];int m[1<<12];class SalesRouting { public : int howMany(vector
t) { int n = t.size, res = 0; for (int i = 1; i<(1<
2006年08月24日 10点08分 6
level 6
jacobzh 楼主
大哥真是厉害,就这么短,还用了这么多位操作,效率一定高,不过俺这好象没得出正确答案啊,看不懂偶去改了改我的程序,终于对了,效率和代码长度就没法看了#include
#include
#include
using namespace std;class SalesRouting{public:int howMany(vector
);private:int maxRout(int,vector
,vector
);//当前行,走过的行,源数据bool checki(vector
,int); };///int SalesRouting::howMany(vector
adj){vector
routed;return maxRout(1,routed,adj);}///bool SalesRouting::checki(vector
routed,int i){ if(routed.empty())return 1; else{ vector
::iterator it=routed.begin(),it_end=routed.end(); for(;it!=it_end;it++) if(*it==i)return 0; } return 1; }//// int SalesRouting::maxRout(int j,vector
routed,vector
adj){ int result=0;///存放结果 if(adj[j][0]=='1')result++;//如果能能通向0,则结果加1 for(int i=1;i
shiyan; shiyan.push_back("001"); shiyan.push_back("001"); shiyan.push_back("110"); shiyan.push_back("110000"); shiyan.push_back("110000"); shiyan.push_back("110000"); cout<
2006年08月24日 15点08分 7
level 9
很清晰啊,支持一下,代码就应该这么写的呵呵,把注释再添加上就更好了,代码长不是坏事,养成好的风格比什么都重要, 以前就是不注重风格,C写长了就养成了坏习惯。。。>_< 上面的代码是根据别人的时间矩阵算法更改来的,昨天时间短没有验证,又一时没找到C++的编译器。。。还是你的长的代码流畅呵呵。
2006年08月25日 01点08分 8
level 9
还有位操作只应该在优化的时候考虑,在不影响功能的前提下还是建议使用其他办法来代替的(现在效率越来越不值钱了,看看什么双核,多流水线,CPU价格大跳水,XXXXXXXX),毕竟不易读懂,踏实才是我们的好信条:)。
2006年08月25日 01点08分 9
level 6
jacobzh 楼主
多谢大哥鼓励哈,呵呵.不过刚检验了下,程序还是不对,又改了n个版本,没一个对的,哎……@_@
2006年08月25日 07点08分 10
level 9
@@ 周一去公司仔细研究一下这个东西
2006年08月25日 13点08分 11
level 6
jacobzh 楼主
总算是通过了,哎,作了一星期……
2006年08月28日 09点08分 12
level 9
@@,通过了?是程序通过了,还是作业??:)
2006年08月28日 09点08分 13
level 6
jacobzh 楼主
是说程序,我还没回学校呢,后后~
2006年08月28日 09点08分 14
1